Skip to content

Instantly share code, notes, and snippets.

@ronaldxs
Last active March 20, 2018 18:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ronaldxs/748362a36fd851e0e6f5afeca9187c30 to your computer and use it in GitHub Desktop.
Save ronaldxs/748362a36fd851e0e6f5afeca9187c30 to your computer and use it in GitHub Desktop.
White space oddness with grammars
#!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