I have a parser for language that looks like this:
[nodeType OPTIONAL STUFF]
There are a few node typed, such as "ask" and "set", so currently ask and set are defined as keywords. This causes problems in other parts of the parser.
Is there a way to define a token parser that accepts only tokens who contain specific text?
Yes. You can have a look at the Terminals class and this is also explained in the Tutorial.
Actually, jparsec combines the two passes of parsing that have been traditionally separated in lex and yacc: The lexical analysis phase (e.g.
Terminals) parses aStringand returns a stream ofTokens, the syntactic analysis (otherParserinstances) parses stream ofTokens and interpret them, usually building an AST or embedding semantic directly.