patrickhuber / Pliant

MIT License
26 stars 4 forks source link

Add trivia to tokens and parse runner. #84

Closed patrickhuber closed 6 years ago

patrickhuber commented 6 years ago

Text in the input that is not used in the parse but is important for refactoring tools is currently thrown away with ignore rules.

patrickhuber commented 6 years ago

Some Requirements:

Grammar

Given Grammar:

RepeatingWord = 
    word RepeatingWord
    | word ;
word ~ /[\w]+/ ;
whitespace ~ /[\s]+/;
start: RepeatingWord ;
trivia: whitespace ;

Test 1

When Input

[space][space]aa[space]aa[space][space]

Then

first token leading trivia is [space][space]
first token following trivia is Empty
second token leading trivia is [space]
second token folliwing trivia is [space][space]

Test 2

When Input

aa[space]aa

Then

first token leading trivia is null
first token following trivia is null
second token leading trivia is [space]
second token following trivia is null

Test 3

When Input

aa[space][carriage return][line feed]aa[space]

Then

first token leading trivia is null
first token following trivia is [space][carriage return][line feed]
second token leading trivia is [space]
second token following trivia is [space]

Test 4

When Input

aa[space][carriage return][line feed]aa[space][carriage return][line feed][carriage return][line feed]

Then

first token leading trivia is null
first token following trivia is [space][carriage return][line feed]
second token leading trivia is [space]
second token following trivia is [space][carriage return][line feed][carriage return][line feed]
patrickhuber commented 6 years ago

@ArsenShnurkov please review the pull request #90 that implements trivia.