http://www.perlmonks.org?node_id=691893


in reply to PRD parser problem: How to deal with mutiple lines

This is about choices. From the examples, there are three possible section contents: single line description, description with a brace block, and blank. That leads to three productions (including blank which is not an <error>).

You could start that like:

section_content: description |
Then define a description
description: 'DESCRIPTION' '=' statement | 'DESCRIPTION' '=' '{' statement(s) '}'
Finally a statement
statement: ...

The key is to think: what are the choices for a valid description or statement or whatever? Each choice is an alternative. Each alternative is made of pieces which themselves might have choices.

p.s. Normal conventions of grammars have us use upper case on the left side of a rule only if we are defining a token. Other left sides, which are built from other things, are usually lower case.

Phil

The Gantry Web Framework Book is now available.