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.
redux
David Majda 14 years ago
parent 1682a25b0d
commit 5e64d09a15

@ -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

@ -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;",

@ -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;

@ -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
);
});

@ -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 ===== */

Loading…
Cancel
Save