我开始使用Sprache解析数学表达式的领域特定语言。我知道我可以用这样的解析的标识符: static readonly Parser<string> Identifier =
from leading in Parse.WhiteSpace.Many()
from first in Parse.Letter.Once()
from rest in Parse.
我还没有找到一个例子 - 如何处理字符转义。我发现了一个代码示例: static void Main(string[] args)
{
string text = "'test \\\' text'";
var result = Grammar.QuotedText.End().Parse(text);
}
public static class Grammar
{
使用monadic解析器Sprache,寻找匹配数字字符(0..9),不包括非数字字符,但前导或尾随空格是可以的。 我想这应该工作: public static readonly Parser<string>
Number = Parse.Numeric.Except(Parse.Letter).AtLeastOnce().Text().Token();
或本: public sta