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.
This commit is contained in:
parent
1682a25b0d
commit
5e64d09a15
2
Rakefile
2
Rakefile
|
@ -1,4 +1,4 @@
|
||||||
desc "Generate the grammar parser"
|
desc "Generate the grammar parser"
|
||||||
task :metaparser do
|
task :metaparser do
|
||||||
system "bin/pegjs PEG.grammarParser lib/metagrammar.pegjs"
|
system "bin/pegjs PEG.parser lib/metagrammar.pegjs"
|
||||||
end
|
end
|
||||||
|
|
|
@ -12,13 +12,13 @@
|
||||||
* The grammar must be a string in the format described by the metagramar in the
|
* The grammar must be a string in the format described by the metagramar in the
|
||||||
* metagrammar.pegjs file.
|
* metagrammar.pegjs file.
|
||||||
*
|
*
|
||||||
* Throws |PEG.grammarParser.SyntaxError| if the grammar contains a syntax error
|
* Throws |PEG.parser.SyntaxError| if the grammar contains a syntax error or
|
||||||
* or |PEG.GrammarError| if it contains a semantic error. Note that not all
|
* |PEG.GrammarError| if it contains a semantic error. Note that not all errors
|
||||||
* errors are detected during the generation and some may protrude to the
|
* are detected during the generation and some may protrude to the generated
|
||||||
* generated parser and cause its malfunction.
|
* parser and cause its malfunction.
|
||||||
*/
|
*/
|
||||||
PEG.buildParser = function(grammar) {
|
PEG.buildParser = function(grammar) {
|
||||||
return PEG.Compiler.compileParser(PEG.grammarParser.parse(grammar));
|
return PEG.compiler.compileParser(PEG.parser.parse(grammar));
|
||||||
};
|
};
|
||||||
|
|
||||||
/* ===== PEG.GrammarError ===== */
|
/* ===== 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|
|
* 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
|
* 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
|
* |PEG.GrammarError|. The checks are run in sequence in order of their
|
||||||
* definition.
|
* definition.
|
||||||
*/
|
*/
|
||||||
PEG.Compiler.checks = [
|
PEG.compiler.checks = [
|
||||||
/* Checks that all referenced rules exist. */
|
/* Checks that all referenced rules exist. */
|
||||||
function(ast) {
|
function(ast) {
|
||||||
function nop() {}
|
function nop() {}
|
||||||
|
@ -287,7 +287,7 @@ PEG.Compiler.checks = [
|
||||||
* modified in-place by the pass. The passes are run in sequence in order of
|
* modified in-place by the pass. The passes are run in sequence in order of
|
||||||
* their definition.
|
* their definition.
|
||||||
*/
|
*/
|
||||||
PEG.Compiler.passes = [
|
PEG.compiler.passes = [
|
||||||
/*
|
/*
|
||||||
* Removes proxy rules -- that is, rules that only delegate to other rule.
|
* 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. */
|
/* 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
|
* Takes parts of code, interpolates variables inside them and joins them with
|
||||||
* a newline.
|
* a newline.
|
||||||
|
@ -477,7 +477,7 @@ PEG.Compiler.emitter = function(ast) {
|
||||||
" * Parses the input with a generated parser. If the parsing is successfull,",
|
" * Parses the input with a generated parser. If the parsing is successfull,",
|
||||||
" * returns a value explicitly or implicitly specified by the grammar from",
|
" * returns a value explicitly or implicitly specified by the grammar from",
|
||||||
" * which the parser was generated (see |PEG.buildParser|). If the parsing is",
|
" * 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) {",
|
" parse: function(input) {",
|
||||||
" var pos = 0;",
|
" var pos = 0;",
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
PEG.grammarParser = (function(){
|
PEG.parser = (function(){
|
||||||
/* Generated by PEG.js (http://pegjs.majda.cz/). */
|
/* Generated by PEG.js (http://pegjs.majda.cz/). */
|
||||||
|
|
||||||
var result = {
|
var result = {
|
||||||
|
@ -6,7 +6,7 @@ PEG.grammarParser = (function(){
|
||||||
* Parses the input with a generated parser. If the parsing is successfull,
|
* Parses the input with a generated parser. If the parsing is successfull,
|
||||||
* returns a value explicitly or implicitly specified by the grammar from
|
* returns a value explicitly or implicitly specified by the grammar from
|
||||||
* which the parser was generated (see |PEG.buildParser|). If the parsing is
|
* 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) {
|
parse: function(input) {
|
||||||
var pos = 0;
|
var pos = 0;
|
||||||
|
|
|
@ -124,7 +124,7 @@ module("PEG");
|
||||||
test("buildParser reports syntax errors in the grammar", function() {
|
test("buildParser reports syntax errors in the grammar", function() {
|
||||||
throws(
|
throws(
|
||||||
function() { PEG.buildParser(''); },
|
function() { PEG.buildParser(''); },
|
||||||
PEG.grammarParser.SyntaxError
|
PEG.parser.SyntaxError
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -5,15 +5,15 @@ var global = this;
|
||||||
/* ===== Helpers ===== */
|
/* ===== Helpers ===== */
|
||||||
|
|
||||||
global.grammarParserParses = function(input, expected) {
|
global.grammarParserParses = function(input, expected) {
|
||||||
global.parses(PEG.grammarParser, input, expected);
|
global.parses(PEG.parser, input, expected);
|
||||||
};
|
};
|
||||||
|
|
||||||
global.grammarParserDoesNotParse = function(input) {
|
global.grammarParserDoesNotParse = function(input) {
|
||||||
global.doesNotParse(PEG.grammarParser, input);
|
global.doesNotParse(PEG.parser, input);
|
||||||
}
|
}
|
||||||
|
|
||||||
global.grammarParserDoesNotParseWithMessage = function(input, message) {
|
global.grammarParserDoesNotParseWithMessage = function(input, message) {
|
||||||
global.doesNotParseWithMessage(PEG.grammarParser, input, message);
|
global.doesNotParseWithMessage(PEG.parser, input, message);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ===== Grammar Parser ===== */
|
/* ===== Grammar Parser ===== */
|
||||||
|
|
Loading…
Reference in a new issue