|
20 | 20 |
|
21 | 21 | namespace ParserTests
|
22 | 22 | {
|
23 |
| - |
| 23 | + public enum BasicToken |
| 24 | + { |
| 25 | + [AlphaId] |
| 26 | + ID, |
| 27 | + |
| 28 | + [Int] |
| 29 | + INT, |
| 30 | + |
| 31 | + [Sugar(".")] |
| 32 | + PERIOD |
| 33 | + } |
| 34 | + |
| 35 | + public class RepeatParser |
| 36 | + { |
| 37 | + [Production("root : thing{0-6} PERIOD[d]")] |
| 38 | + public string Root(List<string> things) |
| 39 | + { |
| 40 | + return string.Join(",", things); |
| 41 | + } |
| 42 | + |
| 43 | + [Production("thing : ID INT")] |
| 44 | + public string Thing(Token<BasicToken> id, Token<BasicToken> integer) |
| 45 | + { |
| 46 | + return $"{id.Value}({integer.IntValue})"; |
| 47 | + } |
| 48 | + } |
| 49 | + |
| 50 | + |
| 51 | + |
24 | 52 | [Lexer(IgnoreWS = true, IgnoreEOL = true)]
|
25 | 53 | public enum DoNotIgnoreCommentsTokenWithChannels
|
26 | 54 | {
|
@@ -1818,6 +1846,33 @@ public void TestNotClosingIndents()
|
1818 | 1846 | Check.That(error.ErrorType).IsEqualTo(ErrorType.UnexpectedEOS);
|
1819 | 1847 | }
|
1820 | 1848 |
|
1821 |
| - |
| 1849 | + |
| 1850 | + [Fact] |
| 1851 | + public void TestRepeat() |
| 1852 | + { |
| 1853 | + ParserBuilder<BasicToken, string> builder = new ParserBuilder<BasicToken, string>(); |
| 1854 | + var instance = new RepeatParser(); |
| 1855 | + var parserRes = builder.BuildParser(instance, ParserType.EBNF_LL_RECURSIVE_DESCENT, "root"); |
| 1856 | + Check.That(parserRes).IsOk(); |
| 1857 | + |
| 1858 | + var parser = parserRes.Result; |
| 1859 | + Check.That(parser).IsNotNull(); |
| 1860 | + var parseResult = parser.Parse("a1b2c3d4e5."); |
| 1861 | + Check.That(parseResult).IsOkParsing(); |
| 1862 | + Check.That(parseResult.Result).IsEqualTo("a(1),b(2),c(3),d(4),e(5)"); |
| 1863 | + parseResult = parser.Parse("."); |
| 1864 | + Check.That(parseResult).IsOkParsing(); |
| 1865 | + Check.That(parseResult.Result).IsEqualTo(""); |
| 1866 | + parseResult = parser.Parse("a1b2c3d4e5f6g7"); |
| 1867 | + Check.That(parseResult).Not.IsOkParsing(); |
| 1868 | + Check.That(parseResult.Errors).CountIs(1); |
| 1869 | + var error = parseResult.Errors[0] as UnexpectedTokenSyntaxError<BasicToken>; |
| 1870 | + Check.That(error).IsNotNull(); |
| 1871 | + Check.That(error.ErrorType).IsEqualTo(ErrorType.UnexpectedToken); |
| 1872 | + |
| 1873 | + Check.That(error.UnexpectedToken.TokenID).IsEqualTo(BasicToken.ID); |
| 1874 | + Check.That(error.UnexpectedToken.Value).IsEqualTo("g"); |
| 1875 | + |
| 1876 | + } |
1822 | 1877 | }
|
1823 | 1878 | }
|
0 commit comments