Skip to content

Instantly share code, notes, and snippets.

@samuraisam
Last active December 18, 2015 12:49
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 samuraisam/5785740 to your computer and use it in GitHub Desktop.
Save samuraisam/5785740 to your computer and use it in GitHub Desktop.
grammar NewStrLiteralTest {
token TOP { <string> }
proto token string { * }
token string:sym<single-quoted> { \' ~ \' ( <-[\\\x00\n']>+ | <str_escape> )* }
token string:sym<double-quoted> { \" ~ \" ( <-[\\\x00\n"]>+ | <str_escape> )* }
token str_escape {
[ <hex-escape> | <oct-escape> | <char-escape> ]
}
token hex-escape { '\\' <[xX]> <.xdigit> ** 1..2 }
token oct-escape { '\\' <[0..7]> ** 1..3 }
token char-escape { '\\' <[abfnrtv\\?'"]> }
}
say NewStrLiteralTest.parse('"hello \nworl\x00d"');
say NewStrLiteralTest.parse('\'hello w"h\nirld\'');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment