Relay parser opts from peg.generate (#553)

master
Futago-za Ryuu 6 years ago
parent 8d711627c1
commit fe6f09238a

@ -8,6 +8,7 @@ function hex( ch ) {
// JavaScript code generation helpers.
const js = {
stringEscape( s ) {
// ECMA-262, 5th ed., 7.8.4: All characters may appear literally in a string
@ -56,7 +57,64 @@ const js = {
.replace( /[\u0100-\u0FFF]/g, ch => "\\u0" + hex( ch ) )
.replace( /[\u1000-\uFFFF]/g, ch => "\\u" + hex( ch ) );
}
},
// This is a list of reserved words for ESMA-262, 5th ed., 7.6.1 (strict mode)
reservedWords: [
// Keyword
"break",
"case",
"catch",
"continue",
"debugger",
"default",
"delete",
"do",
"else",
"finally",
"for",
"function",
"if",
"in",
"instanceof",
"new",
"return",
"switch",
"this",
"throw",
"try",
"typeof",
"var",
"void",
"while",
"with",
// FutureReservedWord
"class",
"const",
"enum",
"export",
"extends",
"implements",
"import",
"interface",
"let",
"package",
"private",
"protected",
"public",
"static",
"super",
"yield",
// Literal
"false",
"null",
"true",
],
};
module.exports = js;

@ -5,6 +5,7 @@
"use strict";
var ast = require("./ast");
var js = require("./compiler/js");
var util = require("./util");
function peg$subclass(child, parent) {
@ -3320,44 +3321,8 @@ function peg$parse(input, options) {
"!": "semantic_not"
};
const RESERVED_WORDS = [
"break",
"case",
"catch",
"class",
"const",
"continue",
"debugger",
"default",
"delete",
"do",
"else",
"enum",
"export",
"extends",
"false",
"finally",
"for",
"function",
"if",
"import",
"instanceof",
"in",
"new",
"null",
"return",
"super",
"switch",
"this",
"throw",
"true",
"try",
"typeof",
"var",
"void",
"while",
"with"
];
let RESERVED_WORDS = options.reservedWords || js.reservedWords;
if ( !Array.isArray(RESERVED_WORDS) ) RESERVED_WORDS = [];
function extractOptional(optional, index) {
return optional ? optional[index] : null;

@ -42,7 +42,7 @@ const peg = {
} );
return compiler.compile(
config.parser.parse( grammar ),
config.parser.parse( grammar, options.parser || {} ),
config.passes,
options
);

@ -319,8 +319,15 @@ declare namespace peg {
*/
namespace parser {
interface IOptions extends gp.IOptions {
extractComments?: boolean;
reservedWords?: string[];
}
const SyntaxError: SyntaxError;
function parse( input: string, options?: gp.IOptions ): Grammar;
function parse( input: string, options?: IOptions ): Grammar;
}
@ -464,6 +471,7 @@ declare namespace peg {
interface IBuildOptions<T = compiler.OutputOptions> extends compiler.ICompilerOptions<T> {
plugins?: IPlugin<T>[];
parser?: parser.IOptions;
}

@ -39,44 +39,8 @@
"!": "semantic_not"
};
const RESERVED_WORDS = [
"break",
"case",
"catch",
"class",
"const",
"continue",
"debugger",
"default",
"delete",
"do",
"else",
"enum",
"export",
"extends",
"false",
"finally",
"for",
"function",
"if",
"import",
"instanceof",
"in",
"new",
"null",
"return",
"super",
"switch",
"this",
"throw",
"true",
"try",
"typeof",
"var",
"void",
"while",
"with"
];
let RESERVED_WORDS = options.reservedWords || js.reservedWords;
if ( !Array.isArray(RESERVED_WORDS) ) RESERVED_WORDS = [];
function extractOptional(optional, index) {
return optional ? optional[index] : null;

@ -7,6 +7,7 @@ module.exports = {
dependencies: {
ast: "./ast",
js: "./compiler/js",
util: "./util"
},

Loading…
Cancel
Save