From 1f89c7746fd8d04241524980f42a69ccdcc5d8fd Mon Sep 17 00:00:00 2001 From: David Majda Date: Sun, 10 Apr 2011 20:27:10 +0200 Subject: [PATCH] Quote keys in |parseFunctions| table in generated parsers IE and Nitro choked when rule names that are JavaScript reserved words (e.g. "class") were used. --- src/emitter.js | 2 +- src/parser.js | 110 ++++++++++++++++++++++++------------------------- 2 files changed, 56 insertions(+), 56 deletions(-) diff --git a/src/emitter.js b/src/emitter.js index 64a5711..f0f9aed 100644 --- a/src/emitter.js +++ b/src/emitter.js @@ -98,7 +98,7 @@ PEG.compiler.emitter = function(ast) { var parseFunctionTableItems = []; for (var name in node.rules) { - parseFunctionTableItems.push(name + ": parse_" + name); + parseFunctionTableItems.push(quote(name) + ": parse_" + name); } parseFunctionTableItems.sort(); diff --git a/src/parser.js b/src/parser.js index 1152176..a2dc4a9 100644 --- a/src/parser.js +++ b/src/parser.js @@ -10,61 +10,61 @@ PEG.parser = (function(){ */ parse: function(input, startRule) { var parseFunctions = { - __: parse___, - action: parse_action, - and: parse_and, - braced: parse_braced, - bracketDelimitedCharacter: parse_bracketDelimitedCharacter, - choice: parse_choice, - class: parse_class, - classCharacter: parse_classCharacter, - classCharacterRange: parse_classCharacterRange, - colon: parse_colon, - comment: parse_comment, - digit: parse_digit, - dot: parse_dot, - doubleQuotedCharacter: parse_doubleQuotedCharacter, - doubleQuotedLiteral: parse_doubleQuotedLiteral, - eol: parse_eol, - eolChar: parse_eolChar, - eolEscapeSequence: parse_eolEscapeSequence, - equals: parse_equals, - grammar: parse_grammar, - hexDigit: parse_hexDigit, - hexEscapeSequence: parse_hexEscapeSequence, - identifier: parse_identifier, - initializer: parse_initializer, - labeled: parse_labeled, - letter: parse_letter, - literal: parse_literal, - lowerCaseLetter: parse_lowerCaseLetter, - lparen: parse_lparen, - multiLineComment: parse_multiLineComment, - nonBraceCharacter: parse_nonBraceCharacter, - nonBraceCharacters: parse_nonBraceCharacters, - not: parse_not, - plus: parse_plus, - prefixed: parse_prefixed, - primary: parse_primary, - question: parse_question, - rparen: parse_rparen, - rule: parse_rule, - semicolon: parse_semicolon, - sequence: parse_sequence, - simpleBracketDelimitedCharacter: parse_simpleBracketDelimitedCharacter, - simpleDoubleQuotedCharacter: parse_simpleDoubleQuotedCharacter, - simpleEscapeSequence: parse_simpleEscapeSequence, - simpleSingleQuotedCharacter: parse_simpleSingleQuotedCharacter, - singleLineComment: parse_singleLineComment, - singleQuotedCharacter: parse_singleQuotedCharacter, - singleQuotedLiteral: parse_singleQuotedLiteral, - slash: parse_slash, - star: parse_star, - suffixed: parse_suffixed, - unicodeEscapeSequence: parse_unicodeEscapeSequence, - upperCaseLetter: parse_upperCaseLetter, - whitespace: parse_whitespace, - zeroEscapeSequence: parse_zeroEscapeSequence + "__": parse___, + "action": parse_action, + "and": parse_and, + "braced": parse_braced, + "bracketDelimitedCharacter": parse_bracketDelimitedCharacter, + "choice": parse_choice, + "class": parse_class, + "classCharacter": parse_classCharacter, + "classCharacterRange": parse_classCharacterRange, + "colon": parse_colon, + "comment": parse_comment, + "digit": parse_digit, + "dot": parse_dot, + "doubleQuotedCharacter": parse_doubleQuotedCharacter, + "doubleQuotedLiteral": parse_doubleQuotedLiteral, + "eol": parse_eol, + "eolChar": parse_eolChar, + "eolEscapeSequence": parse_eolEscapeSequence, + "equals": parse_equals, + "grammar": parse_grammar, + "hexDigit": parse_hexDigit, + "hexEscapeSequence": parse_hexEscapeSequence, + "identifier": parse_identifier, + "initializer": parse_initializer, + "labeled": parse_labeled, + "letter": parse_letter, + "literal": parse_literal, + "lowerCaseLetter": parse_lowerCaseLetter, + "lparen": parse_lparen, + "multiLineComment": parse_multiLineComment, + "nonBraceCharacter": parse_nonBraceCharacter, + "nonBraceCharacters": parse_nonBraceCharacters, + "not": parse_not, + "plus": parse_plus, + "prefixed": parse_prefixed, + "primary": parse_primary, + "question": parse_question, + "rparen": parse_rparen, + "rule": parse_rule, + "semicolon": parse_semicolon, + "sequence": parse_sequence, + "simpleBracketDelimitedCharacter": parse_simpleBracketDelimitedCharacter, + "simpleDoubleQuotedCharacter": parse_simpleDoubleQuotedCharacter, + "simpleEscapeSequence": parse_simpleEscapeSequence, + "simpleSingleQuotedCharacter": parse_simpleSingleQuotedCharacter, + "singleLineComment": parse_singleLineComment, + "singleQuotedCharacter": parse_singleQuotedCharacter, + "singleQuotedLiteral": parse_singleQuotedLiteral, + "slash": parse_slash, + "star": parse_star, + "suffixed": parse_suffixed, + "unicodeEscapeSequence": parse_unicodeEscapeSequence, + "upperCaseLetter": parse_upperCaseLetter, + "whitespace": parse_whitespace, + "zeroEscapeSequence": parse_zeroEscapeSequence }; if (startRule !== undefined) {