Last active
March 20, 2018 18:22
-
-
Save ronaldxs/748362a36fd851e0e6f5afeca9187c30 to your computer and use it in GitHub Desktop.
White space oddness with grammars
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!perl6 | |
use v6; | |
use Test; | |
plan 4; | |
# based on within clause from Grammar::Modelica | |
grammar TestWithSemi { | |
rule TOP {^<ps>$} | |
rule ps { 'photo' 'shop;' } | |
} | |
grammar TestWithSemi_1 is TestWithSemi { | |
token ws { \s+ || <|w> } | |
} | |
grammar TestWithSemi_2 is TestWithSemi { | |
token ws { \s+ || <|w> || $ } | |
} | |
ok TestWithSemi.parse('photo shop;'), 'test with default ws'; | |
my Bool $test-with-semi_1 = so TestWithSemi_1.parse('photo shop;'); | |
ok $test-with-semi_1, 'test with custom ws'; | |
my Bool $test-with-semi_2 = so TestWithSemi_2.parse('photo shop;'); | |
ok $test-with-semi_1 == $test-with-semi_2, | |
'adding $ on top of <|w> should be same'; | |
ok TestWithSemi_1.parse('photo shop; '), | |
'adding trailing space happens to pass test'; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment