Skip to content

Use white space as separator in certain rules #1798

Answered by NaridaL
yaindrop asked this question in Q&A
Discussion options

You must be logged in to vote

With whitespace skipped, you will get the following tokens: IDENT LBRACE IDENT IDENT IDENT IDENT LBRACE.

One thing that would probably work is a gate which checks if the token is on the same line.
You will probably need to ignore ambiguities somewhere.

// parse identifiers as args while they are on the same line as the previous token:
 this.MANY({
    GATE: () => this.LA(0).lineStart === this.LA(1).lineStart,
    DEF: () => {
           this.CONSUME(IDENTIFIER)
         }
  });

Another approach, if most of the newlines are relevant, but spaces and tabs are not, would be to have your WHITESPACE token NOT match "\n" and be skipped. "\n" would be a separate token which you don't skip. You m…

Replies: 2 comments 2 replies

Comment options

You must be logged in to vote
2 replies
@yaindrop
Comment options

@bd82
Comment options

Answer selected by yaindrop
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants