mparlak / Flee

Fast Lightweight Expression Evaluator
624 stars 119 forks source link

Umlaut in variable name #76

Open Suplanus opened 4 years ago

Suplanus commented 4 years ago

If there is an umlaut in the variable name a syntax error is thrown:

Flee.Parsing.grammatica_1._5.alpha2.PerCederberg.Grammatica.Runtime.ParseException: 'unexpected character 'ö', on line: 1 column: 4'

Here is the unit test for it:

[Theory]
[InlineData("Motörhead", true)]
public void ParseWithEnablerList(string expression, object expected)
{
  // Arrange
  ExpressionContext parser = new ExpressionContext();
  parser.Variables.Add("Motörhead", true);
  IGenericExpression<bool> e = parser.CompileGeneric<bool>(expression);

  // Act
  bool value = e.Evaluate();

  // Assert
  value.Should().Be((bool)expected);
}
hunkydoryrepair commented 3 years ago

Grammar for variables is defined by: IDENTIFIER = <<[a-z_]\w*>>

so the first character must be a-z or underscore, and subsequent characters must match RegEx "word" characters", which unfortunately does not include a number of accented characters.