-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
289 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,131 @@ | ||
using System.Collections.Generic; | ||
using sly.lexer; | ||
using sly.parser.generator; | ||
using sly.parser.parser; | ||
|
||
namespace ParserTests.Issue332; | ||
|
||
|
||
[ParserRoot("root")] | ||
public class Issue332Parser | ||
{ | ||
[Production("root: statement*")] | ||
public object Root(List<object> statement) => "foo"; | ||
|
||
[Production("statement: LPAREN statement RPAREN")] | ||
public object BOLCK1(Token<Issue332Token> l, object statement, Token<Issue332Token> r) => | ||
null; | ||
|
||
|
||
|
||
#region expr | ||
|
||
[Operation((int) Issue332Token.LESSER, Affix.InFix, Associativity.Right, 50)] | ||
[Operation((int) Issue332Token.GREATER, Affix.InFix, Associativity.Right, 50)] | ||
[Operation((int) Issue332Token.EQUALS, Affix.InFix, Associativity.Right, 50)] | ||
[Operation((int) Issue332Token.DIFFERENT, Affix.InFix, Associativity.Right, 50)] | ||
public object binaryComparisonExpression(object left, Token<Issue332Token> operatorToken, | ||
object right) => null; | ||
|
||
[Operation((int)Issue332Token.CONCAT, Affix.InFix, Associativity.Right, 100)] | ||
public object DotExpr(object left, Token<Issue332Token> oper, object right) => null | ||
; | ||
|
||
[Operation((int)Issue332Token.PLUS, Affix.InFix, Associativity.Right, 20)] | ||
[Operation((int)Issue332Token.MINUS, Affix.InFix, Associativity.Right, 20)] | ||
public object BE1(object left, Token<Issue332Token> oper, object right) => null | ||
; | ||
|
||
[Operation((int)Issue332Token.TIMES, Affix.InFix, Associativity.Right, 70)] | ||
[Operation((int)Issue332Token.DIVIDE, Affix.InFix, Associativity.Right, 70)] | ||
public object BE2(object left, Token<Issue332Token> oper, object right) => null; | ||
|
||
[Operation((int)Issue332Token.AND, Affix.InFix, Associativity.Right, 50)] | ||
[Operation((int)Issue332Token.OR, Affix.InFix, Associativity.Right, 50)] | ||
[Operation((int)Issue332Token.XOR, Affix.InFix, Associativity.Right, 50)] | ||
public object Bool1(object left, Token<Issue332Token> oper, object right) => null; | ||
|
||
|
||
[Operation((int)Issue332Token.NOT, Affix.PreFix, Associativity.Right, 100)] | ||
public object Bool2(Token<Issue332Token> oper, object expr) => null; | ||
|
||
[Operation((int)Issue332Token.MINUS, Affix.PreFix, Associativity.Right, 100)] | ||
public object MINUS(Token<Issue332Token> oper, object expr) => null; | ||
|
||
|
||
#endregion | ||
|
||
#region primany | ||
|
||
[Operand] | ||
[Production("operand: primary")] | ||
public object Operand(object prim) => prim; | ||
|
||
[Production("primary: LPAREN primary RPAREN")] | ||
public object LR(Token<Issue332Token> l, object prim, Token<Issue332Token> r) => | ||
prim as object; | ||
|
||
[Production("primary: STRING")] | ||
public object STRING(Token<Issue332Token> token) => null; | ||
|
||
[Production("primary: INT")] | ||
public object INT(Token<Issue332Token> token) => null; | ||
|
||
[Production("primary: CHAR")] | ||
public object CHAR(Token<Issue332Token> token) => null; | ||
|
||
[Production("primary: DOUBLE")] | ||
public object DOUBLE(Token<Issue332Token> token) => null ; | ||
|
||
[Production("primary: Issue332Parser_expressions")] | ||
public object Bool(object expr) => null; | ||
|
||
|
||
[Production("primary: IDENTFIER")] | ||
public object IDENTIFIER(Token<Issue332Token> id) => null; | ||
|
||
[Production("primary: TRUE")] | ||
public object BoolTrue(Token<Issue332Token> token) => null; | ||
|
||
[Production("primary: FALSE")] | ||
public object BoolFalse(Token<Issue332Token> token) => null; | ||
|
||
#endregion | ||
|
||
|
||
|
||
[Production("set: IDENTFIER SET[d] Issue332Parser_expressions")] | ||
public object Set( Token<Issue332Token> id, object value) => null; | ||
|
||
[Production("statement: set")] | ||
public object SET(object a) => null; | ||
|
||
[Production("statement : IF[d] ifblock (ELIF ifblock)* (ELSE block)?")] | ||
public object IF(object ifBlock, List<Group<Issue332Token, object>> elif, | ||
ValueOption<Group<Issue332Token, object>> Else) => null; | ||
|
||
[Production("ifblock: Issue332Parser_expressions block")] | ||
public object IFBLOCK(object a, object block) => null; | ||
|
||
[Production("block: INDENT[d] statement* UINDENT[d]")] | ||
public object Block(List<object> statements) => null; | ||
|
||
[Production("statement: FOR set Issue332Parser_expressions statement block")] | ||
public object FOR(Token<Issue332Token> a, object set, object expr, object statement, object block) =>null; | ||
|
||
[Production("statement: WHILE Issue332Parser_expressions block")] | ||
public object WHILE(Token<Issue332Token> a, object expr, object block) => null; | ||
|
||
[Production("statement: IDENTFIER DIRECT[d] IDENTFIER")] | ||
public object DIRECT(Token<Issue332Token> id1, Token<Issue332Token> id2) => null; | ||
|
||
[Production("statement: FUNC[d] IDENTFIER LPAREN[d] RPAREN[d] block")] | ||
public object STAT_FUNC( Token<Issue332Token> id, object block) => null; | ||
|
||
[Production("statement: CLASS[d] IDENTFIER set*")] | ||
public object CLASS(Token<Issue332Token> id, List<object> sets) => null; | ||
|
||
[Production("statement: IDENTFIER SET[d] IDENTFIER LPAREN RPAREN")] | ||
public object INSTANTIATE(Token<Issue332Token> id, Token<Issue332Token> a, Token<Issue332Token> otherid, Token<Issue332Token> b, | ||
Token<Issue332Token> c) => null; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Linq.Expressions; | ||
using NFluent; | ||
using ParserTests.Issue311; | ||
using sly.buildresult; | ||
using sly.lexer; | ||
using sly.parser; | ||
using sly.parser.generator; | ||
using Xunit; | ||
|
||
namespace ParserTests.Issue332; | ||
|
||
public class Issue332Tests | ||
{ | ||
[Fact] | ||
public void TestIssue328() | ||
{ | ||
ParserBuilder<Issue332Token, object> Parser = new ParserBuilder<Issue332Token, object>(); | ||
Issue332Parser oparser = new Issue332Parser(); | ||
var r = Parser.BuildParser(oparser,ParserType.EBNF_LL_RECURSIVE_DESCENT); | ||
Check.That(r).Not.IsOk(); | ||
Check.That(r.Errors).Not.IsEmpty(); | ||
var error = r.Errors.First(); | ||
Check.That(error.Code).IsEqualTo(ErrorCodes.PARSER_LEFT_RECURSIVE); | ||
|
||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
using sly.lexer; | ||
|
||
namespace ParserTests.Issue332; | ||
|
||
[Lexer(IndentationAWare = true)] | ||
public enum Issue332Token | ||
{ | ||
[Lexeme(GenericToken.KeyWord, "IF")] [Lexeme(GenericToken.KeyWord, "if")] | ||
IF = 1, | ||
|
||
[Lexeme(GenericToken.KeyWord, "ELIF")] [Lexeme(GenericToken.KeyWord, "elif")] | ||
ELIF = 2, | ||
|
||
[Lexeme(GenericToken.KeyWord, "ELSE")] [Lexeme(GenericToken.KeyWord, "else")] | ||
ELSE = 3, | ||
|
||
[Lexeme(GenericToken.KeyWord, "WHILE")] [Lexeme(GenericToken.KeyWord, "while")] | ||
WHILE = 4, | ||
|
||
[Lexeme(GenericToken.KeyWord, "FOR")] [Lexeme(GenericToken.KeyWord, "for")] | ||
FOR = 5, | ||
|
||
[Lexeme(GenericToken.KeyWord, "TRUE")] [Lexeme(GenericToken.KeyWord, "true")] | ||
TRUE = 6, | ||
|
||
[Lexeme(GenericToken.KeyWord, "FALSE")] [Lexeme(GenericToken.KeyWord, "false")] | ||
FALSE = 7, | ||
|
||
[Lexeme(GenericToken.KeyWord, "NOT")] [Lexeme(GenericToken.KeyWord, "not")] | ||
NOT = 8, | ||
|
||
[Lexeme(GenericToken.KeyWord, "AND")] [Lexeme(GenericToken.KeyWord, "and")] | ||
AND = 9, | ||
|
||
[Lexeme(GenericToken.KeyWord, "OR")] [Lexeme(GenericToken.KeyWord, "or")] | ||
OR = 10, | ||
|
||
[Lexeme(GenericToken.KeyWord,"XOR")][Lexeme(GenericToken.KeyWord,"xor")] | ||
XOR = 11, | ||
|
||
[Sugar("//")] | ||
ANNOTATION = 12, | ||
//[Lexeme(GenericToken.KeyWord, "CLASS")] [Lexeme(GenericToken.KeyWord, "print")] | ||
//PRINT = 12, | ||
|
||
[Sugar("\n")] | ||
HUANHANG = 13, | ||
|
||
[Lexeme(GenericToken.KeyWord,"CLASS")][Lexeme(GenericToken.KeyWord,"class")] | ||
CLASS = 14, | ||
|
||
[Lexeme(GenericToken.KeyWord,"FUNC")][Lexeme(GenericToken.KeyWord,"func")] | ||
FUNC = 15, | ||
|
||
#region literals 20 -> 29 | ||
[Lexeme(GenericToken.Identifier)] IDENTFIER = 20, | ||
[Lexeme(GenericToken.String)] STRING = 21, | ||
[Lexeme(GenericToken.Int)] INT = 22, | ||
[Lexeme(GenericToken.Double)] DOUBLE = 23, | ||
[Lexeme(GenericToken.Char)] CHAR = 24, | ||
#endregion | ||
|
||
#region operators 30 -> 49 | ||
|
||
[Sugar("<-")] SET = 40, | ||
|
||
[Sugar("->")] DIS_SET = 41, | ||
|
||
[Sugar( ">")] GREATER = 30, | ||
|
||
[Sugar( "<")] LESSER = 31, | ||
|
||
[Sugar( "==")] EQUALS = 32, | ||
|
||
[Sugar( "!=")] DIFFERENT = 33, | ||
|
||
[Sugar( ".")] CONCAT = 34, | ||
|
||
[Sugar( "-*")] DIRECT = 35, | ||
|
||
[Sugar("*-")] DIS_DIRECT = 43, | ||
|
||
[Sugar( "+")] PLUS = 36, | ||
|
||
[Sugar( "-")] MINUS = 37, | ||
|
||
[Sugar( "*")] TIMES = 38, | ||
|
||
[Sugar( "/")] DIVIDE = 39, | ||
|
||
#endregion | ||
|
||
#region sugar 50 -> | ||
|
||
[Sugar( "(")] LPAREN = 50, | ||
|
||
[Sugar( ")")] RPAREN = 51, | ||
|
||
EOF = 0 | ||
|
||
#endregion | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters