Skip to content

Commit

Permalink
fix #427
Browse files Browse the repository at this point in the history
  • Loading branch information
b3b00 committed Apr 8, 2024
1 parent 9aeb523 commit 15acd04
Showing 1 changed file with 40 additions and 0 deletions.
40 changes: 40 additions & 0 deletions tests/ParserTests/issue427/Issue427Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,27 @@ public class Issue427Parser
public static int Expression (int expression) => expression;
}

public class Issue427BisParser
{
[Production("main : expression")]
public static int RootTag(int expression) => expression;

[Operand]
[Production("operand : INTEGER")]
public static int IntegerTag(Token<Issue427Lexer> expressionToken) => int.Parse(expressionToken.Value.ToString());

[Operation((int) Issue427Lexer.PLUS, Affix.InFix, Associativity.Left, 10)]
public static int Addition(int left, Token<Issue427Lexer> operatorToken, int right) => left + right;

[Production("group : LPAREN [d] Issue427BisParser_expressions RPAREN [d]")]
[Operand]
public static int Group(int value) => value;


[Production("expression : Issue427BisParser_expressions")]
public static int Expression (int expression) => expression;
}

public class Issue427MinimalParser
{

Expand Down Expand Up @@ -67,6 +88,25 @@ public void TestIssue427()
Check.That(result).IsOkParsing();
Check.That(result.Result).IsEqualTo(5);





}

[Fact]
public void TestIssue427Bis()
{
ParserBuilder<Issue427Lexer, int> Parser = new ParserBuilder<Issue427Lexer, int>("en");
var oparser = new Issue427BisParser();

var r = Parser.BuildParser(oparser,ParserType.LL_RECURSIVE_DESCENT,"main");
Check.That(r).IsOk();
var parser = r.Result;
var result = parser.Parse("2 + 3");
Check.That(result).IsOkParsing();
Check.That(result.Result).IsEqualTo(5);

result = parser.Parse("(2 + 3)");
Check.That(result).IsOkParsing();
Check.That(result.Result).IsEqualTo(5);
Expand Down

0 comments on commit 15acd04

Please sign in to comment.