Permalink
Browse files

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.
  • Loading branch information...
1 parent 1682a25 commit 5e64d09a15f782f43f863d79b0f1b09fca53bdfd @dmajda dmajda committed Jul 25, 2010
Showing with 18 additions and 18 deletions.
  1. +1 −1 Rakefile
  2. +11 −11 lib/compiler.js
  3. +2 −2 lib/metagrammar.js
  4. +1 −1 test/compiler-test.js
  5. +3 −3 test/metagrammar-test.js
View
2 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
View
22 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;",
View
4 lib/metagrammar.js
@@ -1,12 +1,12 @@
-PEG.grammarParser = (function(){
+PEG.parser = (function(){
/* Generated by PEG.js (http://pegjs.majda.cz/). */
var result = {
/*
* 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;
View
2 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
);
});
View
6 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 ===== */

0 comments on commit 5e64d09

Please sign in to comment.