support multi line strings
This commit is contained in:
parent
fac85b2b27
commit
24dd04d1ba
1 changed files with 49 additions and 5 deletions
|
|
@ -107,6 +107,9 @@ var keywords = {
|
||||||
|
|
||||||
getLineTokens = function(line, startState)
|
getLineTokens = function(line, startState)
|
||||||
{
|
{
|
||||||
|
// regexp must not have capturing parentheses
|
||||||
|
// regexps are ordered -> the first match is used
|
||||||
|
|
||||||
var rules = {
|
var rules = {
|
||||||
start :
|
start :
|
||||||
[
|
[
|
||||||
|
|
@ -119,17 +122,27 @@ getLineTokens = function(line, startState)
|
||||||
regex: "\\/\\*.*?\\*\\/"
|
regex: "\\/\\*.*?\\*\\/"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
token: "comment", // multi line comment in several lines
|
token: "comment", // multi line comment start
|
||||||
regex: "\\/\\*.*$",
|
regex: "\\/\\*.*$",
|
||||||
next: "comment"
|
next: "comment"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
token: "string", // single line
|
token: "string", // single line
|
||||||
regex: '["][^"]*["]'
|
regex: '["](?:(?:\\\\.)|(?:[^"\\\\]))*?["]'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
token: "string", // multi line string start
|
||||||
|
regex: '["].*\\\\$',
|
||||||
|
next: "qqstring"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
token: "string", // single line
|
token: "string", // single line
|
||||||
regex: "['][^']*[']"
|
regex: "['](?:(?:\\\\.)|(?:[^'\\\\]))*?[']"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
token: "string", // multi line string start
|
||||||
|
regex: "['].*\\\\$",
|
||||||
|
next: "qstring"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
token: "number", // hex
|
token: "number", // hex
|
||||||
|
|
@ -173,6 +186,30 @@ getLineTokens = function(line, startState)
|
||||||
token: "comment", // comment spanning whole line
|
token: "comment", // comment spanning whole line
|
||||||
regex: ".+"
|
regex: ".+"
|
||||||
}
|
}
|
||||||
|
],
|
||||||
|
"qqstring":
|
||||||
|
[
|
||||||
|
{
|
||||||
|
token: "string",
|
||||||
|
regex: '(?:(?:\\\\.)|(?:[^"\\\\]))*?"',
|
||||||
|
next: "start"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
token: "string",
|
||||||
|
regex: '.+'
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"qstring":
|
||||||
|
[
|
||||||
|
{
|
||||||
|
token: "string",
|
||||||
|
regex: "(?:(?:\\\\.)|(?:[^'\\\\]))*?'",
|
||||||
|
next: "start"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
token: "string",
|
||||||
|
regex: '.+'
|
||||||
|
}
|
||||||
]
|
]
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -197,6 +234,8 @@ getLineTokens = function(line, startState)
|
||||||
|
|
||||||
var match, tokens = [];
|
var match, tokens = [];
|
||||||
|
|
||||||
|
var lastIndex = 0;
|
||||||
|
|
||||||
while (match = re.exec(line))
|
while (match = re.exec(line))
|
||||||
{
|
{
|
||||||
var token = {
|
var token = {
|
||||||
|
|
@ -204,6 +243,11 @@ getLineTokens = function(line, startState)
|
||||||
value: match[0]
|
value: match[0]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (re.lastIndex == lastIndex) {
|
||||||
|
throw new Error("tokenizer error")
|
||||||
|
}
|
||||||
|
lastIndex = re.lastIndex;
|
||||||
|
|
||||||
//console.log(match);
|
//console.log(match);
|
||||||
|
|
||||||
for (var i=0; i < state.length; i++)
|
for (var i=0; i < state.length; i++)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue