Skip to content

Commit

Permalink
unit test #495
Browse files Browse the repository at this point in the history
  • Loading branch information
b3b00 committed Nov 1, 2024
1 parent 1e7818e commit 9b0b3e4
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 9 deletions.
13 changes: 7 additions & 6 deletions tests/ParserTests/Issue495/Issue495Parser.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Collections.Generic;
using System.Linq;
using sly.lexer;
using sly.parser.generator;

Expand All @@ -13,21 +14,21 @@ public Issue495Parser()
}

[Production("STRING: StartQuote StringValue* EndQuote")]
public object stringValue(Token<Issue495Token> open, List<Token<Issue495Token>> values, Token<Issue495Token> close)
public string stringValue(Token<Issue495Token> open, List<Token<Issue495Token>> values, Token<Issue495Token> close)
{
return null;
return string.Join(", ", values.Select(x => x.Value.ToString()));
}

[Production("statement : Identifier Assign STRING End")]
public object Statement(Token<Issue495Token> id, Token<Issue495Token> assign, object value,
public string Statement(Token<Issue495Token> id, Token<Issue495Token> assign, string value,
Token<Issue495Token> end)
{
return null;
return $"{id.Value}{assign.Value}{value}";
}

[Production("program: statement*")]
public object Program(List<object> statements)
public string Program(List<string> statements)
{
return null;
return string.Join("\n", statements);
}
}
7 changes: 4 additions & 3 deletions tests/ParserTests/Issue495/Issue495Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@ namespace ParserTests.Issue495;

public class Issue495Tests
{
public Parser<Issue495Token,object> _parser { get; set; }
public Parser<Issue495Token,string> _parser { get; set; }

public Parser<Issue495Token, object> GetParser()
public Parser<Issue495Token, string> GetParser()
{
if (_parser == null)
{
ParserBuilder<Issue495Token, object> builder = new ParserBuilder<Issue495Token, object>("en");
ParserBuilder<Issue495Token, string> builder = new ParserBuilder<Issue495Token, string>("en");
var build = builder.BuildParser(new Issue495Parser(), ParserType.EBNF_LL_RECURSIVE_DESCENT, "program");
Check.That(build).IsOk();
_parser = build.Result;
Expand All @@ -29,6 +29,7 @@ public void TestIssue495()
Check.That(parser).IsNotNull();
var parsed = parser.Parse("test = \"3 3\";");
Check.That(parsed).IsOkParsing();
Check.That(parsed.Result).IsEqualTo("test=3 3");
}

}

0 comments on commit 9b0b3e4

Please sign in to comment.