superpower

Superpower: match a string with tokenizer only if it begins a line

匆匆过客 提交于 2020-01-04 06:25:10
问题 When tokenizing in superpower, how to match a string only if it is the first thing in a line (note: this is a different question than this one) ? For example, assume I have a language with only the following 4 characters (' ', ':', 'X', 'Y'), each of which is a token. There is also a 'Header' token to capture cases of the following regex pattern /^[XY]+:/ (any number of Xs and Ys followed by a colon, only if they start the line). Here is a quick class for testing (the 4th test-case fails):

Superpower: match a string with parser only if it begins a line

大兔子大兔子 提交于 2019-12-04 06:22:17
问题 When parsing in superpower, how to match a string only if it is the first thing in a line? For example, I need to match the A colon in "A: Hello Goodbye\n" but not in "Goodbye A: Hello\n" 回答1: Using your example here, I would change your ActorParser and NodeParser definitions to this: public readonly static TokenListParser<Tokens, Node> ActorParser = from name in NameParser from colon in Token.EqualTo(Tokens.Colon) from text in TextParser select new Node { Actor = name + colon.ToStringValue()