Skip to content

Commit

Permalink
fix #277
Browse files Browse the repository at this point in the history
  • Loading branch information
b3b00 committed Mar 22, 2022
1 parent fcbb548 commit a3f11d9
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 2 deletions.
52 changes: 52 additions & 0 deletions ParserTests/IssuesTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
using ParserTests.Issue260;
using sly.buildresult;
using sly.lexer;
using sly.parser;
using sly.parser.generator;
using sly.parser.parser;
using Xunit;

namespace ParserTests
Expand Down Expand Up @@ -158,6 +160,31 @@ public Set219 set(Token<Issue219Lexer> id, Token<Issue219Lexer> eq, Token<Issue2
throw new Exception219("visitor error");
}
}

public enum Issue277Tokens
{
[Lexeme(GenericToken.Identifier, IdentifierType.AlphaNumericDash)]
IDENTIFIER,

[Lexeme(GenericToken.KeyWord, "or")]
OR,
}

public class Issue277Parser
{
[Production("widget: IDENTIFIER")]
public string Widget(Token<Issue277Tokens> widget)
{
return widget.Value;
}

[Production("expression: widget (OR [d] widget)+")]
public string Expression(string widget, List<Group<Issue277Tokens, string>> ors)
{
return ors.Aggregate($"{widget}", (acc, a) => $"{acc} | {a.Value(0)}");
}
}

public class IssuesTests
{

Expand Down Expand Up @@ -237,5 +264,30 @@ public static void Issue261Test()


}

[Fact]
public static void Issue277Test()
{
var parserInstance = new Issue277Parser();
var builder = new ParserBuilder<Issue277Tokens, string>();

var result = builder
.BuildParser(parserInstance, ParserType.EBNF_LL_RECURSIVE_DESCENT, "expression");

Assert.True(result.IsOk);

Assert.NotNull(result.Result);
Assert.IsType<Parser<Issue277Tokens, string>>(result.Result);
var parser = result.Result as Parser<Issue277Tokens, string>;

var expression = "foo or bar or baz";

var res = parser.Parse(expression);
Assert.True(res.IsOk);
Assert.NotNull(res.Result);
Assert.IsType<string>(res.Result);
var resAsString = res.Result as string;
Assert.Equal("foo | bar | baz", resAsString);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -385,11 +385,14 @@ public SyntaxParseResult<IN> ParseOneOrMore(IList<Token<IN>> tokens, OneOrMoreCl
firstInnerResult = ParseTerminal(tokens, innerClause as TerminalClause<IN>, currentPosition);
hasByPasNodes = hasByPasNodes || firstInnerResult.HasByPassNodes;
}
else if (innerClause is NonTerminalClause<IN>)
else if (innerClause is NonTerminalClause<IN> nonTerm)
{
manyNode.IsManyValues = true;
firstInnerResult = ParseNonTerminal(tokens, innerClause as NonTerminalClause<IN>, currentPosition);
hasByPasNodes = hasByPasNodes || firstInnerResult.HasByPassNodes;
if (nonTerm.IsGroup)
manyNode.IsManyGroups = true;
else
manyNode.IsManyValues = true;
}
else if (innerClause is ChoiceClause<IN> choice)
{
Expand Down

0 comments on commit a3f11d9

Please sign in to comment.