Skip to content

How can dsl::list and expression_production be combined and still handle trailing newlines? #123

Answered by foonathan
sarcasticnature asked this question in Q&A
Discussion options

You must be logged in to vote

dsl::list(dsl::p<Expr>, dsl::sep(dsl::ascii::newline)) + dsl::eol + dsl::eof

The issue here is that dsl::list with dsl::sep uses the existence of the separator to determine whether it should parse another Expr. So you can't have a newline after the expression.

dsl::list(dsl::p<Expr>, dsl::trailing_sep(dsl::newline));

dsl::list with dsl::trailing_sep can't use the existence of the separator to check whether it can parse another Expr (since it could be the trailing separator), so Expr needs a branch condition to determine whether or not one matches, as the error message told you. Depending on what Expr parses, something like dsl::peek(foo) >> dsl::p<Expr> as list item might do the tricker.

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@sarcasticnature
Comment options

Answer selected by sarcasticnature
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants