-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #240 from b3b00/bugfix/239
bugfix #239
- Loading branch information
Showing
10 changed files
with
259 additions
and
31 deletions.
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,20 @@ | ||
using sly.lexer; | ||
|
||
namespace ParserTests.Issue239 | ||
{ | ||
public enum Issue239Lexer | ||
{ | ||
[AlphaNumDashId] | ||
ID, | ||
[Keyword("int")] | ||
INT, | ||
[Int] | ||
INT_LITERAL, | ||
[Sugar("=")] | ||
ASSIGN, | ||
[Sugar(";")] | ||
SEMI | ||
|
||
|
||
} | ||
} |
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,30 @@ | ||
using System.Collections.Generic; | ||
using sly.lexer; | ||
using sly.parser.generator; | ||
|
||
namespace ParserTests.Issue239 | ||
{ | ||
public class Issue239Parser | ||
{ | ||
[Production("statements : statement*")] | ||
public object Statements(List<object> statements) | ||
{ | ||
return statements; | ||
} | ||
|
||
[Production("statement: INT[d] ID SEMI[d]")] | ||
public object IntDeclaration(Token<Issue239Lexer> id) | ||
{ | ||
return $"{id.Value} is an int;\n"; | ||
} | ||
|
||
[Production("statement : ID ASSIGN[d] INT_LITERAL SEMI[d]")] | ||
public object Assignement(Token<Issue239Lexer> id, Token<Issue239Lexer> value) | ||
{ | ||
return $"{id.Value} is equal to {value.IntValue}\n"; | ||
} | ||
|
||
|
||
|
||
} | ||
} |
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,36 @@ | ||
using System.Collections.Generic; | ||
using expressionparser; | ||
using simpleExpressionParser; | ||
using sly.parser; | ||
using sly.parser.generator; | ||
using Xunit; | ||
|
||
namespace ParserTests.Issue239 | ||
{ | ||
public class Issue239Tests | ||
{ | ||
private static Parser<Issue239Lexer, object> BuildParser() | ||
{ | ||
var StartingRule = $"statements"; | ||
var parserInstance = new Issue239Parser(); | ||
var builder = new ParserBuilder<Issue239Lexer, object>(); | ||
var pBuild = builder.BuildParser(parserInstance, ParserType.EBNF_LL_RECURSIVE_DESCENT, StartingRule); | ||
Assert.True(pBuild.IsOk); | ||
Assert.NotNull(pBuild.Result); | ||
return pBuild.Result; | ||
} | ||
|
||
|
||
|
||
[Fact] | ||
public static void TestOk() | ||
{ | ||
var parser = BuildParser(); | ||
var parseResult = parser.Parse("int x; int y; a = 12;"); | ||
Assert.True(parseResult.IsOk); | ||
Assert.IsAssignableFrom<List<object>>(parseResult.Result); | ||
var lst = parseResult.Result as List<object>; | ||
Assert.Equal(3, lst.Count); | ||
} | ||
} | ||
} |
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
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
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
Oops, something went wrong.