ldthomas/apg-js2-exp

Allow leading whitespace

LinusU opened this issue · 3 comments

It would be nice if leading whitespace could be automatically stripped so that you can use it with ES6 template strings in a nice way.

e.g.

new ApgExp(`
  number        = [ "-" ] int [ frac ] [ exp ]
  digit0-9      = %x30-39
  digit1-9      = %x31-39
  exp           = ( "e" / "E" ) [ "-" / "+" ] 1*digit0-9
  frac          = "." 1*digit0-9
  int           = "0" / ( digit1-9 *digit0-9 )
`)

I'd much prefer sticking to the ABNF rules and not trying to second guess what kind of pre-processing of the grammar text any specific user might need. Automatically stripping white space would have to distinguish between a rule definition and a continuation line. Not impossible of course, but accounting for all of the scenarios is just the kind of sticky situation I'd rather avoid in a general tool.

Ah, I did not think of continuation lines, still very new to ABNF. Maybe this doesn't make sense then...

Comment lines would be another problem to deal with. I'm sure the list would get longer if you actually tried to automate this. Thanks for your interest and comments though.