BjoernLoetters / macrowave

MIT License
4 stars 0 forks source link

Multiple start-rules #9

Open keddelzz opened 7 years ago

BjoernLoetters commented 7 years ago

This would be a great opportunity to allow, that all rules can be used as start rules. That would bring us to a more PEG-like parser. It would be even better, to allow to parse an input with the rule itself instead of the class:

@grammar
class MyParser {
  def ruleS = ruleA ~ ruleS | ruleB
  def ruleA = "Hello "
  def ruleB = "World!"
}
...
val parser = new MyParser
parser.ruleS.parse("Hello Hello Hello World!") // success

parser.ruleA.parse("Hello Hello Hello World!") // failure
parser.ruleA.parse("Hello ") // success

parser.ruleB.parse("Hello Hello Hello World!") // failure
parser.ruleB.parse("World!") // success

The latter would also help to implement flatMap (issue #5).

keddelzz commented 7 years ago

Currently I don't see, if we can implement multiple start rules with a single parse-table.

BjoernLoetters commented 7 years ago

We need to research that in detail, but I think it is sufficient to initialize the state stack with the appropriate state.