Skip to content

Commit

Permalink
filling unit tests holes : fix regex lexer i18n !
Browse files Browse the repository at this point in the history
  • Loading branch information
b3b00 committed Oct 16, 2024
1 parent 7a9b1a9 commit 8f0fe3d
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
11 changes: 8 additions & 3 deletions src/sly/lexer/LexerBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ private static BuildResult<ILexer<IN>> Build<IN>(Dictionary<IN, (List<LexemeAttr
}
else
{
result = BuildRegexLexer<IN>(attributes, result);
result = BuildRegexLexer<IN>(attributes, lang, result);
}
}
else if (hasGenericLexemes)
Expand Down Expand Up @@ -240,10 +240,15 @@ private static bool IsGenericLexer<IN>(Dictionary<IN, (List<LexemeAttribute> lex
}


private static BuildResult<ILexer<IN>> BuildRegexLexer<IN>(Dictionary<IN, (List<LexemeAttribute> lexemes,List<LexemeLabelAttribute> labels)> attributes,
private static BuildResult<ILexer<IN>> BuildRegexLexer<IN>(
Dictionary<IN, (List<LexemeAttribute> lexemes, List<LexemeLabelAttribute> labels)> attributes,
string lang,
BuildResult<ILexer<IN>> result) where IN : struct
{
var lexer = new Lexer<IN>();
var lexer = new Lexer<IN>()
{
I18n = lang
};
foreach (var pair in attributes)
{
var tokenID = pair.Key;
Expand Down
3 changes: 2 additions & 1 deletion tests/ParserTests/ErrorTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ public void TestLexicalError()
{
var exprParser = new ExpressionParser();

var builder = new ParserBuilder<ExpressionToken, int>();
var builder = new ParserBuilder<ExpressionToken, int>("en");
var Parser = builder.BuildParser(exprParser, ParserType.LL_RECURSIVE_DESCENT, "root").Result;
var r = Parser.Parse("2 @ 2");
Check.That(r.IsError).IsTrue();
Expand All @@ -120,6 +120,7 @@ public void TestLexicalError()
Check.That(error.Line).IsEqualTo(1);
Check.That(error.Column).IsEqualTo(3);
Check.That(error.UnexpectedChar).IsEqualTo('@');
Check.That(error.ErrorMessage).IsEqualTo("Lexical Error, line 1, column 3 : Unrecognized symbol '@' (64)");
}
}
}

0 comments on commit 8f0fe3d

Please sign in to comment.