From 5e64d09a15f782f43f863d79b0f1b09fca53bdfd Mon Sep 17 00:00:00 2001 From: David Majda Date: Sun, 25 Jul 2010 15:33:28 +0200 Subject: [PATCH] Renamed some properties of the |PEG| object 1. |PEG.Compiler| -> |PEG.compiler| 2. |PEG.grammarParser| -> |PEG.parser| This brings us closer to the desired structure of the PEG object, which is: +-PEG |- parser +- compiler |- checks |- passes +- emitter These are the only things (together with the |PEG.buildParser| function and exceptions) that I want to be publicly accessible -- as extension points and also for easy testing of PEG.js's components. --- Rakefile | 2 +- lib/compiler.js | 22 +++++++++++----------- lib/metagrammar.js | 4 ++-- test/compiler-test.js | 2 +- test/metagrammar-test.js | 6 +++--- 5 files changed, 18 insertions(+), 18 deletions(-) diff --git a/Rakefile b/Rakefile index 0e8705d..5a786fd 100644 --- a/Rakefile +++ b/Rakefile @@ -1,4 +1,4 @@ desc "Generate the grammar parser" task :metaparser do - system "bin/pegjs PEG.grammarParser lib/metagrammar.pegjs" + system "bin/pegjs PEG.parser lib/metagrammar.pegjs" end diff --git a/lib/compiler.js b/lib/compiler.js index a97944e..2e4a595 100644 --- a/lib/compiler.js +++ b/lib/compiler.js @@ -12,13 +12,13 @@ * The grammar must be a string in the format described by the metagramar in the * metagrammar.pegjs file. * - * Throws |PEG.grammarParser.SyntaxError| if the grammar contains a syntax error - * or |PEG.GrammarError| if it contains a semantic error. Note that not all - * errors are detected during the generation and some may protrude to the - * generated parser and cause its malfunction. + * Throws |PEG.parser.SyntaxError| if the grammar contains a syntax error or + * |PEG.GrammarError| if it contains a semantic error. Note that not all errors + * are detected during the generation and some may protrude to the generated + * parser and cause its malfunction. */ PEG.buildParser = function(grammar) { - return PEG.Compiler.compileParser(PEG.grammarParser.parse(grammar)); + return PEG.compiler.compileParser(PEG.parser.parse(grammar)); }; /* ===== PEG.GrammarError ===== */ @@ -127,9 +127,9 @@ PEG.RegExpUtils = { } }; -/* ===== PEG.Compiler ===== */ +/* ===== PEG.compiler ===== */ -PEG.Compiler = { +PEG.compiler = { /* * Generates a parser from a specified grammar AST. Throws |PEG.GrammarError| * if the AST contains a semantic error. Note that not all errors are detected @@ -160,7 +160,7 @@ PEG.Compiler = { * |PEG.GrammarError|. The checks are run in sequence in order of their * definition. */ -PEG.Compiler.checks = [ +PEG.compiler.checks = [ /* Checks that all referenced rules exist. */ function(ast) { function nop() {} @@ -287,7 +287,7 @@ PEG.Compiler.checks = [ * modified in-place by the pass. The passes are run in sequence in order of * their definition. */ -PEG.Compiler.passes = [ +PEG.compiler.passes = [ /* * Removes proxy rules -- that is, rules that only delegate to other rule. */ @@ -366,7 +366,7 @@ PEG.Compiler.passes = [ ]; /* Emits the generated code for the AST. */ -PEG.Compiler.emitter = function(ast) { +PEG.compiler.emitter = function(ast) { /* * Takes parts of code, interpolates variables inside them and joins them with * a newline. @@ -477,7 +477,7 @@ PEG.Compiler.emitter = function(ast) { " * Parses the input with a generated parser. If the parsing is successfull,", " * returns a value explicitly or implicitly specified by the grammar from", " * which the parser was generated (see |PEG.buildParser|). If the parsing is", - " * unsuccessful, throws |PEG.grammarParser.SyntaxError| describing the error.", + " * unsuccessful, throws |PEG.parser.SyntaxError| describing the error.", " */", " parse: function(input) {", " var pos = 0;", diff --git a/lib/metagrammar.js b/lib/metagrammar.js index 1e3c538..b5e7c1c 100644 --- a/lib/metagrammar.js +++ b/lib/metagrammar.js @@ -1,4 +1,4 @@ -PEG.grammarParser = (function(){ +PEG.parser = (function(){ /* Generated by PEG.js (http://pegjs.majda.cz/). */ var result = { @@ -6,7 +6,7 @@ PEG.grammarParser = (function(){ * Parses the input with a generated parser. If the parsing is successfull, * returns a value explicitly or implicitly specified by the grammar from * which the parser was generated (see |PEG.buildParser|). If the parsing is - * unsuccessful, throws |PEG.grammarParser.SyntaxError| describing the error. + * unsuccessful, throws |PEG.parser.SyntaxError| describing the error. */ parse: function(input) { var pos = 0; diff --git a/test/compiler-test.js b/test/compiler-test.js index f3eca93..e63dfe5 100644 --- a/test/compiler-test.js +++ b/test/compiler-test.js @@ -124,7 +124,7 @@ module("PEG"); test("buildParser reports syntax errors in the grammar", function() { throws( function() { PEG.buildParser(''); }, - PEG.grammarParser.SyntaxError + PEG.parser.SyntaxError ); }); diff --git a/test/metagrammar-test.js b/test/metagrammar-test.js index d37d776..b17ad57 100644 --- a/test/metagrammar-test.js +++ b/test/metagrammar-test.js @@ -5,15 +5,15 @@ var global = this; /* ===== Helpers ===== */ global.grammarParserParses = function(input, expected) { - global.parses(PEG.grammarParser, input, expected); + global.parses(PEG.parser, input, expected); }; global.grammarParserDoesNotParse = function(input) { - global.doesNotParse(PEG.grammarParser, input); + global.doesNotParse(PEG.parser, input); } global.grammarParserDoesNotParseWithMessage = function(input, message) { - global.doesNotParseWithMessage(PEG.grammarParser, input, message); + global.doesNotParseWithMessage(PEG.parser, input, message); } /* ===== Grammar Parser ===== */