mirror of
https://github.com/microsoft/monaco-editor.git
synced 2025-12-22 11:35:40 +01:00
Tokenizer fixes for quoted identifiers, comments, strings, numbers
This commit is contained in:
parent
79b5433bb4
commit
8380da7fff
1 changed files with 44 additions and 31 deletions
|
|
@ -15,10 +15,10 @@ export const conf: IRichLanguageConfiguration = {
|
||||||
},
|
},
|
||||||
brackets: [['[', ']'], ['(', ')'], ['{', '}']],
|
brackets: [['[', ']'], ['(', ')'], ['{', '}']],
|
||||||
autoClosingPairs: [
|
autoClosingPairs: [
|
||||||
{ open: '"', close: '"', notIn: ['string', 'comment'] }, // quoted identifier?
|
{ open: '"', close: '"', notIn: ['string', 'comment', 'identifier'] },
|
||||||
{ open: '[', close: ']', notIn: ['string', 'comment'] },
|
{ open: '[', close: ']', notIn: ['string', 'comment', 'identifier'] },
|
||||||
{ open: '(', close: ')', notIn: ['string', 'comment'] },
|
{ open: '(', close: ')', notIn: ['string', 'comment', 'identifier'] },
|
||||||
{ open: '{', close: '}', notIn: ['string', 'comment'] },
|
{ open: '{', close: '}', notIn: ['string', 'comment', 'identifier'] },
|
||||||
]
|
]
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -47,6 +47,10 @@ export const language = <ILanguage>{
|
||||||
],
|
],
|
||||||
|
|
||||||
typeKeywords: [
|
typeKeywords: [
|
||||||
|
"action",
|
||||||
|
"any",
|
||||||
|
"anynonnull",
|
||||||
|
"none",
|
||||||
"null",
|
"null",
|
||||||
"logical",
|
"logical",
|
||||||
"number",
|
"number",
|
||||||
|
|
@ -63,54 +67,63 @@ export const language = <ILanguage>{
|
||||||
"function"
|
"function"
|
||||||
],
|
],
|
||||||
|
|
||||||
wordDefinition: /([a-zA-Z_\.][a-zA-Z\._0-9]*)|([0-9][_\.a-zA-Z0-9]*[_\.a-zA-Z])/,
|
// (identifier|keyword or type|quoted identifier)
|
||||||
|
wordDefinition: /([a-zA-Z_][\w\.]*)|(#?[a-z]+)|(#"[\w \.]+")/,
|
||||||
|
|
||||||
tokenizer: {
|
tokenizer: {
|
||||||
root: [
|
root: [
|
||||||
{ include: "@comments" },
|
// escaped identifier
|
||||||
|
[/#"[\w \.]+"/, "identifier"],
|
||||||
|
|
||||||
[/\d+(\.\d+)?/, "number"],
|
// numbers
|
||||||
[/(([a-zA-Z_\.][a-zA-Z\._0-9]*)|([0-9][_\.a-zA-Z0-9]*[_\.a-zA-Z]))|(#["]([ \[\]_\.a-zA-Z0-9]+)["])/,
|
[/\d*\.\d+([eE][\-+]?\d+)?/, "number.float"],
|
||||||
|
[/0[xX][0-9a-fA-F]+/, "number.hex"],
|
||||||
|
[/\d+([eE][\-+]?\d+)?/, "number"],
|
||||||
|
|
||||||
|
// keywords
|
||||||
|
[/(#?[a-z]+)/,
|
||||||
{
|
{
|
||||||
cases: {
|
cases: {
|
||||||
|
"@typeKeywords": "keyword.type",
|
||||||
"@keywords": "keyword",
|
"@keywords": "keyword",
|
||||||
"@default": "identifier"
|
"@default": "identifier"
|
||||||
}
|
}
|
||||||
}],
|
}
|
||||||
{ include: "@strings" },
|
],
|
||||||
[/[{}()\[\]]/, "@brackets"],
|
|
||||||
// Removed forward slash for now to allow comments
|
|
||||||
[/[,;=+<>\-*&@?]|([<>]=)|(<>)|([\.\.][\.]?)|(=>)/, "punctuator"],
|
|
||||||
|
|
||||||
|
// other identifiers
|
||||||
|
[/([a-zA-Z_][\w\.]*)/, "identifier"],
|
||||||
|
|
||||||
|
{ include: "@whitespace" },
|
||||||
|
{ include: "@comments" },
|
||||||
|
{ include: "@strings" },
|
||||||
|
|
||||||
|
[/[{}()\[\]]/, "@brackets"],
|
||||||
|
[/([,;=\+<>\-\*&@\?\/!])|([<>]=)|(<>)|(=>)|(\.\.\.)|(\.\.)/, "punctuator"],
|
||||||
],
|
],
|
||||||
|
|
||||||
|
whitespace: [
|
||||||
|
[/\s+/, "white"]
|
||||||
|
],
|
||||||
|
|
||||||
comments: [
|
comments: [
|
||||||
["\\/\\*", "comment", "@comment"],
|
["\\/\\*", "comment", "@comment"],
|
||||||
["\\/\\/+.*", "comment"]
|
["\\/\\/+.*", "comment"]
|
||||||
],
|
],
|
||||||
|
|
||||||
comment: [
|
comment: [
|
||||||
["\\*\\/", "comment", "@pop"],
|
["\\*\\/", "comment", "@pop"],
|
||||||
[".", "comment"]
|
[".", "comment"]
|
||||||
],
|
],
|
||||||
// Recognize strings, including those broken across lines with \ (but not without)
|
|
||||||
strings: [
|
strings: [
|
||||||
[/"$/, "string.escape", "@root"],
|
["\"", "string", "@string"]
|
||||||
[/"/, "string.escape", "@stringBody"],
|
|
||||||
[/"$/, "string.escape", "@root"],
|
|
||||||
[/"/, "string.escape", "@dblStringBody"]
|
|
||||||
],
|
],
|
||||||
stringBody: [
|
|
||||||
[/\\./, "string"],
|
string: [
|
||||||
[/"/, "string.escape", "@root"],
|
["\"\"", "string.escape"],
|
||||||
[/.(?=.*")/, "string"],
|
["\"", "string", "@pop"],
|
||||||
[/.*\\$/, "string"],
|
[".", "string"]
|
||||||
[/.*$/, "string", "@root"]
|
|
||||||
],
|
|
||||||
dblStringBody: [
|
|
||||||
[/\\./, "string"],
|
|
||||||
[/"/, "string.escape", "@root"],
|
|
||||||
[/.(?=.*")/, "string"],
|
|
||||||
[/.*\\$/, "string"],
|
|
||||||
[/.*$/, "string", "@root"]
|
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue