@ -161,8 +161,8 @@ describe("PEG.js grammar parser", function() {
} ) ;
} ) ;
/* Canonical g rammar is "a = \"abcd\"; b = \"efgh\"; c = \"ijkl\";". */
it ( "parses g rammar", function ( ) {
/* Canonical G rammar is "a = \"abcd\"; b = \"efgh\"; c = \"ijkl\";". */
it ( "parses G rammar", function ( ) {
var ruleA = { type : "rule" , name : "a" , expression : literalAbcd } ,
ruleB = { type : "rule" , name : "b" , expression : literalEfgh } ,
ruleC = { type : "rule" , name : "c" , expression : literalIjkl } ;
@ -184,8 +184,8 @@ describe("PEG.js grammar parser", function() {
} ) ;
} ) ;
/* Canonical i nitializer is "{ code }". */
it ( "parses i nitializer", function ( ) {
/* Canonical I nitializer is "{ code }". */
it ( "parses I nitializer", function ( ) {
var grammar = oneRuleGrammar ( literalAbcd , {
type : "initializer" ,
code : " code "
@ -195,8 +195,8 @@ describe("PEG.js grammar parser", function() {
expect ( '{ code }; start = "abcd"' ) . toParseAs ( grammar ) ;
} ) ;
/* Canonical r ule is "a: \"abcd\"". */
it ( "parses r ule", function ( ) {
/* Canonical R ule is "a: \"abcd\"". */
it ( "parses R ule", function ( ) {
expect ( 'start = "abcd" / "efgh" / "ijkl"' ) . toParseAs (
oneRuleGrammar ( choiceOfLiterals )
) ;
@ -212,15 +212,15 @@ describe("PEG.js grammar parser", function() {
) ;
} ) ;
/* Canonical e xpression is "\"abcd\" / \"efgh\" / \"ijkl\"". */
it ( "parses e xpression", function ( ) {
/* Canonical E xpression is "\"abcd\" / \"efgh\" / \"ijkl\"". */
it ( "parses E xpression", function ( ) {
expect ( 'start = "abcd" / "efgh" / "ijkl"' ) . toParseAs (
oneRuleGrammar ( choiceOfLiterals )
) ;
} ) ;
/* Canonical c hoice is "\"abcd\" / \"efgh\" / \"ijkl\"". */
it ( "parses c hoice", function ( ) {
/* Canonical C hoice is "\"abcd\" / \"efgh\" / \"ijkl\"". */
it ( "parses C hoice", function ( ) {
expect ( 'start = "abcd" "efgh" "ijkl"' ) . toParseAs (
oneRuleGrammar ( sequenceOfLiterals )
) ;
@ -232,8 +232,8 @@ describe("PEG.js grammar parser", function() {
} ) ) ;
} ) ;
/* Canonical s equence is "\"abcd\" \"efgh\" \"ijkl\"". */
it ( "parses s equence", function ( ) {
/* Canonical S equence is "\"abcd\" \"efgh\" \"ijkl\"". */
it ( "parses S equence", function ( ) {
expect ( 'start = a:"abcd" { code }' ) . toParseAs (
oneRuleGrammar ( { type : "action" , expression : labeledAbcd , code : " code " } )
) ;
@ -253,8 +253,8 @@ describe("PEG.js grammar parser", function() {
) ;
} ) ;
/* Canonical l abeled is "label:\"abcd\"". */
it ( "parses l abeled", function ( ) {
/* Canonical L abeled is "label:\"abcd\"". */
it ( "parses L abeled", function ( ) {
expect ( 'start = label:!"abcd"' ) . toParseAs ( oneRuleGrammar ( {
type : "labeled" ,
label : "label" ,
@ -263,8 +263,8 @@ describe("PEG.js grammar parser", function() {
expect ( 'start = !"abcd"' ) . toParseAs ( oneRuleGrammar ( simpleNotLiteral ) ) ;
} ) ;
/* Canonical p refixed is "!\"abcd\"". */
it ( "parses p refixed", function ( ) {
/* Canonical P refixed is "!\"abcd\"". */
it ( "parses P refixed", function ( ) {
expect ( 'start = $"abcd"?' ) . toParseAs ( oneRuleGrammar ( {
type : "text" ,
expression : optionalLiteral
@ -288,8 +288,8 @@ describe("PEG.js grammar parser", function() {
expect ( 'start = "abcd"?' ) . toParseAs ( oneRuleGrammar ( optionalLiteral ) ) ;
} ) ;
/* Canonical s uffixed is "\"abcd\"?". */
it ( "parses s uffixed", function ( ) {
/* Canonical S uffixed is "\"abcd\"?". */
it ( "parses S uffixed", function ( ) {
expect ( 'start = "abcd"?' ) . toParseAs ( oneRuleGrammar ( optionalLiteral ) ) ;
expect ( 'start = "abcd"*' ) . toParseAs ( oneRuleGrammar ( {
type : "zero_or_more" ,
@ -302,8 +302,8 @@ describe("PEG.js grammar parser", function() {
expect ( 'start = "abcd"' ) . toParseAs ( literalGrammar ( "abcd" ) ) ;
} ) ;
/* Canonical p rimary is "\"abcd\"". */
it ( "parses p rimary", function ( ) {
/* Canonical P rimary is "\"abcd\"". */
it ( "parses P rimary", function ( ) {
expect ( 'start = a' ) . toParseAs ( ruleRefGrammar ( "a" ) ) ;
expect ( 'start = "abcd"' ) . toParseAs ( literalGrammar ( "abcd" ) ) ;
expect ( 'start = [a-d]' ) . toParseAs ( classGrammar ( [ [ "a" , "d" ] ] , "[a-d]" ) ) ;
@ -311,29 +311,29 @@ describe("PEG.js grammar parser", function() {
expect ( 'start = ("abcd")' ) . toParseAs ( literalGrammar ( "abcd" ) ) ;
} ) ;
/* Canonical a ction is "{ code }". */
it ( "parses a ction", function ( ) {
/* Canonical A ction is "{ code }". */
it ( "parses A ction", function ( ) {
expect ( 'start = "abcd" { code }' ) . toParseAs ( actionGrammar ( " code " ) ) ;
expect ( 'start = "abcd" { code }\n' ) . toParseAs ( actionGrammar ( " code " ) ) ;
} ) ;
/* Canonical b raced is "{ code }". */
it ( "parses b raced", function ( ) {
/* Canonical B raced is "{ code }". */
it ( "parses B raced", function ( ) {
expect ( 'start = "abcd" {}' ) . toParseAs ( actionGrammar ( "" ) ) ;
expect ( 'start = "abcd" {{a}}' ) . toParseAs ( actionGrammar ( "{a}" ) ) ;
expect ( 'start = "abcd" {abcd}' ) . toParseAs ( actionGrammar ( "abcd" ) ) ;
expect ( 'start = "abcd" {{a}{b}{c}}' ) . toParseAs ( actionGrammar ( "{a}{b}{c}" ) ) ;
} ) ;
/* Canonical n onBraceCharacters is "abcd". */
it ( "parses n onBraceCharacters", function ( ) {
/* Canonical N onBraceCharacters is "abcd". */
it ( "parses N onBraceCharacters", function ( ) {
expect ( 'start = "abcd" {a}' ) . toParseAs ( actionGrammar ( "a" ) ) ;
expect ( 'start = "abcd" {abc}' ) . toParseAs ( actionGrammar ( "abc" ) ) ;
} ) ;
/* Canonical n onBraceCharacter is "a". */
it ( "parses n onBraceCharacter", function ( ) {
/* Canonical N onBraceCharacter is "a". */
it ( "parses N onBraceCharacter", function ( ) {
expect ( 'start = "abcd" {a}' ) . toParseAs ( actionGrammar ( "a" ) ) ;
expect ( 'start = "abcd" {{}' ) . toFailToParse ( ) ;
@ -342,8 +342,8 @@ describe("PEG.js grammar parser", function() {
/* Trivial character rules are not tested. */
/* Canonical i dentifier is "a". */
it ( "parses i dentifier", function ( ) {
/* Canonical I dentifier is "a". */
it ( "parses I dentifier", function ( ) {
expect ( 'start = a' ) . toParseAs ( ruleRefGrammar ( "a" ) ) ;
expect ( 'start = _' ) . toParseAs ( ruleRefGrammar ( "_" ) ) ;
expect ( 'start = aa' ) . toParseAs ( ruleRefGrammar ( "aa" ) ) ;
@ -354,8 +354,8 @@ describe("PEG.js grammar parser", function() {
expect ( 'start = a\n' ) . toParseAs ( ruleRefGrammar ( "a" ) ) ;
} ) ;
/* Canonical l iteral is "\"abcd\"". */
it ( "parses l iteral", function ( ) {
/* Canonical L iteral is "\"abcd\"". */
it ( "parses L iteral", function ( ) {
expect ( 'start = "abcd"' ) . toParseAs ( literalGrammar ( "abcd" ) ) ;
expect ( "start = 'abcd'" ) . toParseAs ( literalGrammar ( "abcd" ) ) ;
@ -364,8 +364,8 @@ describe("PEG.js grammar parser", function() {
expect ( 'start = "abcd"\n' ) . toParseAs ( literalGrammar ( "abcd" ) ) ;
} ) ;
/* Canonical s tring is "\"abcd\"". */
it ( "parses s tring", function ( ) {
/* Canonical S tring is "\"abcd\"". */
it ( "parses S tring", function ( ) {
var grammar = oneRuleGrammar ( {
type : "named" ,
name : "abcd" ,
@ -378,15 +378,15 @@ describe("PEG.js grammar parser", function() {
expect ( 'start "abcd"\n= "abcd"' ) . toParseAs ( grammar ) ;
} ) ;
/* Canonical d oubleQuotedString is "\"abcd\"". */
it ( "parses d oubleQuotedString", function ( ) {
/* Canonical D oubleQuotedString is "\"abcd\"". */
it ( "parses D oubleQuotedString", function ( ) {
expect ( 'start = ""' ) . toParseAs ( literalGrammar ( "" ) ) ;
expect ( 'start = "a"' ) . toParseAs ( literalGrammar ( "a" ) ) ;
expect ( 'start = "abc"' ) . toParseAs ( literalGrammar ( "abc" ) ) ;
} ) ;
/* Canonical d oubleQuotedCharacter is "a". */
it ( "parses d oubleQuotedCharacter", function ( ) {
/* Canonical D oubleQuotedCharacter is "a". */
it ( "parses D oubleQuotedCharacter", function ( ) {
expect ( 'start = "a"' ) . toParseAs ( literalGrammar ( "a" ) ) ;
expect ( 'start = "\\n"' ) . toParseAs ( literalGrammar ( "\n" ) ) ;
expect ( 'start = "\\0"' ) . toParseAs ( literalGrammar ( "\x00" ) ) ;
@ -395,8 +395,8 @@ describe("PEG.js grammar parser", function() {
expect ( 'start = "\\\n"' ) . toParseAs ( literalGrammar ( "" ) ) ;
} ) ;
/* Canonical s impleDoubleQuotedCharacter is "a". */
it ( "parses s impleDoubleQuotedCharacter", function ( ) {
/* Canonical S impleDoubleQuotedCharacter is "a". */
it ( "parses S impleDoubleQuotedCharacter", function ( ) {
expect ( 'start = "a"' ) . toParseAs ( literalGrammar ( "a" ) ) ;
expect ( 'start = """' ) . toFailToParse ( ) ;
@ -404,15 +404,15 @@ describe("PEG.js grammar parser", function() {
expect ( 'start = "\n"' ) . toFailToParse ( ) ;
} ) ;
/* Canonical s ingleQuotedString is "'abcd'". */
it ( "parses s ingleQuotedString", function ( ) {
/* Canonical S ingleQuotedString is "'abcd'". */
it ( "parses S ingleQuotedString", function ( ) {
expect ( "start = ''" ) . toParseAs ( literalGrammar ( "" ) ) ;
expect ( "start = 'a'" ) . toParseAs ( literalGrammar ( "a" ) ) ;
expect ( "start = 'abc'" ) . toParseAs ( literalGrammar ( "abc" ) ) ;
} ) ;
/* Canonical s ingleQuotedCharacter is "a". */
it ( "parses s ingleQuotedCharacter", function ( ) {
/* Canonical S ingleQuotedCharacter is "a". */
it ( "parses S ingleQuotedCharacter", function ( ) {
expect ( "start = 'a'" ) . toParseAs ( literalGrammar ( "a" ) ) ;
expect ( "start = '\\n'" ) . toParseAs ( literalGrammar ( "\n" ) ) ;
expect ( "start = '\\0'" ) . toParseAs ( literalGrammar ( "\x00" ) ) ;
@ -421,8 +421,8 @@ describe("PEG.js grammar parser", function() {
expect ( "start = '\\\n'" ) . toParseAs ( literalGrammar ( "" ) ) ;
} ) ;
/* Canonical s impleSingleQuotedCharacter is "a". */
it ( "parses s impleSingleQuotedCharacter", function ( ) {
/* Canonical S impleSingleQuotedCharacter is "a". */
it ( "parses S impleSingleQuotedCharacter", function ( ) {
expect ( "start = 'a'" ) . toParseAs ( literalGrammar ( "a" ) ) ;
expect ( "start = '''" ) . toFailToParse ( ) ;
@ -430,8 +430,8 @@ describe("PEG.js grammar parser", function() {
expect ( "start = '\n'" ) . toFailToParse ( ) ;
} ) ;
/* Canonical c lass is "[a-d]". */
it ( "parses c lass", function ( ) {
/* Canonical C lass is "[a-d]". */
it ( "parses C lass", function ( ) {
expect ( 'start = []' ) . toParseAs ( classGrammar ( [ ] , "[]" ) ) ;
expect ( 'start = [a-d]' ) . toParseAs ( classGrammar ( [ [ "a" , "d" ] ] , "[a-d]" ) ) ;
expect ( 'start = [a]' ) . toParseAs ( classGrammar ( [ "a" ] , "[a]" ) ) ;
@ -449,8 +449,8 @@ describe("PEG.js grammar parser", function() {
expect ( 'start = [a-d]\n' ) . toParseAs ( classGrammar ( [ [ "a" , "d" ] ] , "[a-d]" ) ) ;
} ) ;
/* Canonical c lassCharacterRange is "a-d". */
it ( "parses c lassCharacterRange", function ( ) {
/* Canonical C lassCharacterRange is "a-d". */
it ( "parses C lassCharacterRange", function ( ) {
expect ( 'start = [a-d]' ) . toParseAs ( classGrammar ( [ [ "a" , "d" ] ] , "[a-d]" ) ) ;
expect ( 'start = [a-a]' ) . toParseAs ( classGrammar ( [ [ "a" , "a" ] ] , "[a-a]" ) ) ;
@ -459,13 +459,13 @@ describe("PEG.js grammar parser", function() {
} ) ;
} ) ;
/* Canonical c lassCharacter is "a". */
it ( "parses c lassCharacter", function ( ) {
/* Canonical C lassCharacter is "a". */
it ( "parses C lassCharacter", function ( ) {
expect ( 'start = [a]' ) . toParseAs ( classGrammar ( [ "a" ] , "[a]" ) ) ;
} ) ;
/* Canonical b racketDelimitedCharacter is "a". */
it ( "parses b racketDelimitedCharacter", function ( ) {
/* Canonical B racketDelimitedCharacter is "a". */
it ( "parses B racketDelimitedCharacter", function ( ) {
expect ( 'start = [a]' ) . toParseAs ( classGrammar ( [ "a" ] , "[a]" ) ) ;
expect ( 'start = [\\n]' ) . toParseAs ( classGrammar ( [ "\n" ] , "[\\n]" ) ) ;
expect ( 'start = [\\0]' ) . toParseAs ( classGrammar ( [ "\x00" ] , "[\\0]" ) ) ;
@ -474,8 +474,8 @@ describe("PEG.js grammar parser", function() {
expect ( 'start = [\\\n]' ) . toParseAs ( classGrammar ( [ "" ] , "[\\\n]" ) ) ;
} ) ;
/* Canonical s impleBracketDelimiedCharacter is "a". */
it ( "parses s impleBracketDelimitedCharacter", function ( ) {
/* Canonical S impleBracketDelimiedCharacter is "a". */
it ( "parses S impleBracketDelimitedCharacter", function ( ) {
expect ( 'start = [a]' ) . toParseAs ( classGrammar ( [ "a" ] , "[a]" ) ) ;
expect ( 'start = []]' ) . toFailToParse ( ) ;
@ -483,8 +483,8 @@ describe("PEG.js grammar parser", function() {
expect ( 'start = [\n]' ) . toFailToParse ( ) ;
} ) ;
/* Canonical s impleEscapeSequence is "\\n". */
it ( "parses s impleEscapeSequence", function ( ) {
/* Canonical S impleEscapeSequence is "\\n". */
it ( "parses S impleEscapeSequence", function ( ) {
expect ( 'start = "\\b"' ) . toParseAs ( literalGrammar ( "\b" ) ) ;
expect ( 'start = "\\f"' ) . toParseAs ( literalGrammar ( "\f" ) ) ;
expect ( 'start = "\\n"' ) . toParseAs ( literalGrammar ( "\n" ) ) ;
@ -498,26 +498,26 @@ describe("PEG.js grammar parser", function() {
expect ( 'start = "\\u"' ) . toFailToParse ( ) ;
} ) ;
/* Canonical z eroEscapeSequence is "\\0". */
it ( "parses z eroEscapeSequence", function ( ) {
/* Canonical Z eroEscapeSequence is "\\0". */
it ( "parses Z eroEscapeSequence", function ( ) {
expect ( 'start = "\\0"' ) . toParseAs ( literalGrammar ( "\x00" ) ) ;
expect ( 'start = "\\00"' ) . toFailToParse ( ) ;
expect ( 'start = "\\09"' ) . toFailToParse ( ) ;
} ) ;
/* Canonical h exEscapeSequence is "\\xFF". */
it ( "parses h exEscapeSequence", function ( ) {
/* Canonical H exEscapeSequence is "\\xFF". */
it ( "parses H exEscapeSequence", function ( ) {
expect ( 'start = "\\xFF"' ) . toParseAs ( literalGrammar ( "\xFF" ) ) ;
} ) ;
/* Canonical u nicodeEscapeSequence is "\\uFFFF". */
it ( "parses u nicodeEscapeSequence", function ( ) {
/* Canonical U nicodeEscapeSequence is "\\uFFFF". */
it ( "parses U nicodeEscapeSequence", function ( ) {
expect ( 'start = "\\uFFFF"' ) . toParseAs ( literalGrammar ( "\uFFFF" ) ) ;
} ) ;
/* Canonical eol EscapeSequence is "\\\n". */
it ( "parses eol EscapeSequence", function ( ) {
/* Canonical EOL EscapeSequence is "\\\n". */
it ( "parses EOL EscapeSequence", function ( ) {
expect ( 'start = "\\\n"' ) . toParseAs ( literalGrammar ( "" ) ) ;
} ) ;
@ -532,21 +532,21 @@ describe("PEG.js grammar parser", function() {
expect ( 'start = "abcd"' ) . toParseAs ( trivialGrammar ) ;
} ) ;
// Canonical c omment is "/* comment */".
it ( "parses c omment", function ( ) {
// Canonical C omment is "/* comment */".
it ( "parses C omment", function ( ) {
expect ( 'start =// comment\n"abcd"' ) . toParseAs ( trivialGrammar ) ;
expect ( 'start =/* comment */"abcd"' ) . toParseAs ( trivialGrammar ) ;
} ) ;
/* Canonical s ingleLineComment is "// comment". */
it ( "parses s ingleLineComment", function ( ) {
/* Canonical S ingleLineComment is "// comment". */
it ( "parses S ingleLineComment", function ( ) {
expect ( 'start =//\n"abcd"' ) . toParseAs ( trivialGrammar ) ;
expect ( 'start =//a\n"abcd"' ) . toParseAs ( trivialGrammar ) ;
expect ( 'start =//aaa\n"abcd"' ) . toParseAs ( trivialGrammar ) ;
} ) ;
// Canonical m ultiLineComment is "/* comment */".
it ( "parses m ultiLineComment", function ( ) {
// Canonical M ultiLineComment is "/* comment */".
it ( "parses M ultiLineComment", function ( ) {
expect ( 'start =/**/"abcd"' ) . toParseAs ( trivialGrammar ) ;
expect ( 'start =/*a*/"abcd"' ) . toParseAs ( trivialGrammar ) ;
expect ( 'start =/*aaa*/"abcd"' ) . toParseAs ( trivialGrammar ) ;
@ -555,8 +555,8 @@ describe("PEG.js grammar parser", function() {
expect ( 'start =/**/*/"abcd"' ) . toFailToParse ( ) ;
} ) ;
/* Canonical eol is "\n". */
it ( "parses eol ", function ( ) {
/* Canonical EOL is "\n". */
it ( "parses EOL ", function ( ) {
expect ( 'start =\n"abcd"' ) . toParseAs ( trivialGrammar ) ;
expect ( 'start =\r\n"abcd"' ) . toParseAs ( trivialGrammar ) ;
expect ( 'start =\r"abcd"' ) . toParseAs ( trivialGrammar ) ;
@ -564,16 +564,16 @@ describe("PEG.js grammar parser", function() {
expect ( 'start =\u2029"abcd"' ) . toParseAs ( trivialGrammar ) ;
} ) ;
/* Canonical eol Char is "\n". */
it ( "parses eol Char", function ( ) {
/* Canonical EOL Char is "\n". */
it ( "parses EOL Char", function ( ) {
expect ( 'start =\n"abcd"' ) . toParseAs ( trivialGrammar ) ;
expect ( 'start =\r"abcd"' ) . toParseAs ( trivialGrammar ) ;
expect ( 'start =\u2028"abcd"' ) . toParseAs ( trivialGrammar ) ;
expect ( 'start =\u2029"abcd"' ) . toParseAs ( trivialGrammar ) ;
} ) ;
/* Canonical w hitespace is " ". */
it ( "parses w hitespace", function ( ) {
/* Canonical W hitespace is " ". */
it ( "parses W hitespace", function ( ) {
expect ( 'start =\t"abcd"' ) . toParseAs ( trivialGrammar ) ;
expect ( 'start =\x0B"abcd"' ) . toParseAs ( trivialGrammar ) ; // no "\v" in IE
expect ( 'start =\f"abcd"' ) . toParseAs ( trivialGrammar ) ;