Add "position" option to parser, to specify initial pos/line/col

(for parsing embedded scripts)
This commit is contained in:
Mihai Bazon
2013-07-15 11:27:11 +03:00
parent 9243b0cb9d
commit 4a0bab0fa3

View File

@@ -210,17 +210,17 @@ function is_token(token, type, val) {
var EX_EOF = {}; var EX_EOF = {};
function tokenizer($TEXT, filename) { function tokenizer($TEXT, filename, position) {
var S = { var S = {
text : $TEXT.replace(/\r\n?|[\n\u2028\u2029]/g, "\n").replace(/\uFEFF/g, ''), text : $TEXT.replace(/\r\n?|[\n\u2028\u2029]/g, "\n").replace(/\uFEFF/g, ''),
filename : filename, filename : filename,
pos : 0, pos : position && position.pos || 0,
tokpos : 0, tokpos : position && position.pos || 0,
line : 1, line : position && position.line || 1,
tokline : 0, tokline : position && position.line || 1,
col : 0, col : position && position.col || 0,
tokcol : 0, tokcol : position && position.col || 0,
newline_before : false, newline_before : false,
regex_allowed : false, regex_allowed : false,
comments_before : [] comments_before : []
@@ -591,7 +591,8 @@ function parse($TEXT, options) {
strict : false, strict : false,
filename : null, filename : null,
toplevel : null, toplevel : null,
expression : false expression : false,
position : { pos: 0, line: 1, col: 0 },
}); });
var S = { var S = {