nearley: disclude `undefined` from data array, provide notreegen

Related to post processing and eliminating nodes, is there a value I can return from a matched token that will eliminate it from output automatically?

For example, it would be nice if I could just drop optional whitespace, such that–

selector _ combinator _ element

– would return an array of 3 elements instead of 5. I thought I could write:

_ -> null

– but then that just returned an actual null value. I can see why I might want to post-process based on null, so I’m not sure what to suggest, maybe a special nearley token? Like: %null% or something?

About this issue

  • Original URL
  • State: open
  • Created 9 years ago
  • Comments: 20 (10 by maintainers)

Most upvoted comments

As a global flag, it would look like this:

_ -> whitespacechar:*
__ -> whitespacechar:+
comment -> "/*" commentchar:+ "*/" | "//" commentchar:+ "\n"
@no-tree _
@no-tree __
@no-tree comment

I prefer this because (1) you can enumerate no-tree nonterminals in one place, (2) you can’t accidentally create a conflict where only some, but not all, rules for a non-terminal are no-tree’d, (3) you can quickly toggle no-tree-ness for a nonterminal without having to change it in multiple places.