@ -331,55 +331,71 @@ test("indempotence", function() {
strictEqual ( parser1 . toSource ( ) , parser2 . toSource ( ) ) ;
strictEqual ( parser1 . toSource ( ) , parser2 . toSource ( ) ) ;
} ) ;
} ) ;
test ( "error message s", function ( ) {
test ( "error detail s", function ( ) {
var literalParser = PEG . buildParser ( 'start = "abcd"' ) ;
var literalParser = PEG . buildParser ( 'start = "abcd"' ) ;
doesNotParseWith Message (
doesNotParseWith Details (
literalParser ,
literalParser ,
"" ,
"" ,
[ "\"abcd\"" ] ,
null ,
'Expected "abcd" but end of input found.'
'Expected "abcd" but end of input found.'
) ;
) ;
doesNotParseWith Message (
doesNotParseWith Details (
literalParser ,
literalParser ,
"efgh" ,
"efgh" ,
[ "\"abcd\"" ] ,
"e" ,
'Expected "abcd" but "e" found.'
'Expected "abcd" but "e" found.'
) ;
) ;
doesNotParseWith Message (
doesNotParseWith Details (
literalParser ,
literalParser ,
"abcde" ,
"abcde" ,
[ ] ,
"e" ,
'Expected end of input but "e" found.'
'Expected end of input but "e" found.'
) ;
) ;
var classParser = PEG . buildParser ( 'start = [a-d]' ) ;
var classParser = PEG . buildParser ( 'start = [a-d]' ) ;
doesNotParseWith Message (
doesNotParseWith Details (
classParser ,
classParser ,
"" ,
"" ,
[ "[a-d]" ] ,
null ,
'Expected [a-d] but end of input found.'
'Expected [a-d] but end of input found.'
) ;
) ;
var negativeClassParser = PEG . buildParser ( 'start = [^a-d]' ) ;
var negativeClassParser = PEG . buildParser ( 'start = [^a-d]' ) ;
doesNotParseWith Message (
doesNotParseWith Details (
negativeClassParser ,
negativeClassParser ,
"" ,
"" ,
[ "[^a-d]" ] ,
null ,
'Expected [^a-d] but end of input found.'
'Expected [^a-d] but end of input found.'
) ;
) ;
var anyParser = PEG . buildParser ( 'start = .' ) ;
var anyParser = PEG . buildParser ( 'start = .' ) ;
doesNotParseWith Message (
doesNotParseWith Details (
anyParser ,
anyParser ,
"" ,
"" ,
[ "any character" ] ,
null ,
'Expected any character but end of input found.'
'Expected any character but end of input found.'
) ;
) ;
var namedRuleWithLiteralParser = PEG . buildParser ( 'start "digit" = [0-9]' ) ;
var namedRuleWithLiteralParser = PEG . buildParser ( 'start "digit" = [0-9]' ) ;
doesNotParseWith Message (
doesNotParseWith Details (
namedRuleWithLiteralParser ,
namedRuleWithLiteralParser ,
"a" ,
"a" ,
[ "digit" ] ,
"a" ,
'Expected digit but "a" found.'
'Expected digit but "a" found.'
) ;
) ;
var namedRuleWithAnyParser = PEG . buildParser ( 'start "whatever" = .' ) ;
var namedRuleWithAnyParser = PEG . buildParser ( 'start "whatever" = .' ) ;
doesNotParseWith Message (
doesNotParseWith Details (
namedRuleWithAnyParser ,
namedRuleWithAnyParser ,
"" ,
"" ,
[ "whatever" ] ,
null ,
'Expected whatever but end of input found.'
'Expected whatever but end of input found.'
) ;
) ;
@ -387,58 +403,74 @@ test("error messages", function() {
'start "digits" = digit+' ,
'start "digits" = digit+' ,
'digit "digit" = [0-9]'
'digit "digit" = [0-9]'
] . join ( "\n" ) ) ;
] . join ( "\n" ) ) ;
doesNotParseWith Message (
doesNotParseWith Details (
namedRuleWithNamedRuleParser ,
namedRuleWithNamedRuleParser ,
"" ,
"" ,
[ "digits" ] ,
null ,
'Expected digits but end of input found.'
'Expected digits but end of input found.'
) ;
) ;
var choiceParser1 = PEG . buildParser ( 'start = "a" / "b" / "c"' ) ;
var choiceParser1 = PEG . buildParser ( 'start = "a" / "b" / "c"' ) ;
doesNotParseWith Message (
doesNotParseWith Details (
choiceParser1 ,
choiceParser1 ,
"def" ,
"def" ,
[ "\"a\"" , "\"b\"" , "\"c\"" ] ,
"d" ,
'Expected "a", "b" or "c" but "d" found.'
'Expected "a", "b" or "c" but "d" found.'
) ;
) ;
var choiceParser2 = PEG . buildParser ( 'start = "a" "b" "c" / "a"' ) ;
var choiceParser2 = PEG . buildParser ( 'start = "a" "b" "c" / "a"' ) ;
doesNotParseWith Message (
doesNotParseWith Details (
choiceParser2 ,
choiceParser2 ,
"abd" ,
"abd" ,
[ "\"c\"" ] ,
"d" ,
'Expected "c" but "d" found.'
'Expected "c" but "d" found.'
) ;
) ;
var simpleNotParser = PEG . buildParser ( 'start = !"a" "b"' ) ;
var simpleNotParser = PEG . buildParser ( 'start = !"a" "b"' ) ;
doesNotParseWith Message (
doesNotParseWith Details (
simpleNotParser ,
simpleNotParser ,
"c" ,
"c" ,
[ "\"b\"" ] ,
"c" ,
'Expected "b" but "c" found.'
'Expected "b" but "c" found.'
) ;
) ;
var simpleAndParser = PEG . buildParser ( 'start = &"a" [a-b]' ) ;
var simpleAndParser = PEG . buildParser ( 'start = &"a" [a-b]' ) ;
doesNotParseWith Message (
doesNotParseWith Details (
simpleAndParser ,
simpleAndParser ,
"c" ,
"c" ,
[ ] ,
"c" ,
'Expected end of input but "c" found.'
'Expected end of input but "c" found.'
) ;
) ;
var emptyParser = PEG . buildParser ( 'start = ' ) ;
var emptyParser = PEG . buildParser ( 'start = ' ) ;
doesNotParseWith Message (
doesNotParseWith Details (
emptyParser ,
emptyParser ,
"something" ,
"something" ,
[ ] ,
"s" ,
'Expected end of input but "s" found.'
'Expected end of input but "s" found.'
) ;
) ;
var duplicateErrorParser = PEG . buildParser ( 'start = "a" / "a"' ) ;
var duplicateErrorParser = PEG . buildParser ( 'start = "a" / "a"' ) ;
doesNotParseWith Message (
doesNotParseWith Details (
duplicateErrorParser ,
duplicateErrorParser ,
"" ,
"" ,
[ "\"a\"" ] ,
null ,
'Expected "a" but end of input found.'
'Expected "a" but end of input found.'
) ;
) ;
var unsortedErrorsParser = PEG . buildParser ( 'start = "b" / "a"' ) ;
var unsortedErrorsParser = PEG . buildParser ( 'start = "b" / "a"' ) ;
doesNotParseWith Message (
doesNotParseWith Details (
unsortedErrorsParser ,
unsortedErrorsParser ,
"" ,
"" ,
[ "\"a\"" , "\"b\"" ] ,
null ,
'Expected "a" or "b" but end of input found.'
'Expected "a" or "b" but end of input found.'
) ;
) ;
} ) ;
} ) ;