mirror of
https://github.com/microsoft/monaco-editor.git
synced 2025-12-22 20:52:56 +01:00
Merge pull request #46 from spahnke/regex-flags
Improve tokenization of regular expressions
This commit is contained in:
commit
66b5497f3c
3 changed files with 69 additions and 3 deletions
|
|
@ -430,7 +430,7 @@ testTokenization('javascript', [
|
||||||
]
|
]
|
||||||
}],
|
}],
|
||||||
|
|
||||||
[{
|
[{
|
||||||
line: 'x = /foo/.test(\'\')',
|
line: 'x = /foo/.test(\'\')',
|
||||||
tokens: [
|
tokens: [
|
||||||
{ startIndex: 0, type: 'identifier.js' },
|
{ startIndex: 0, type: 'identifier.js' },
|
||||||
|
|
@ -446,6 +446,39 @@ testTokenization('javascript', [
|
||||||
]
|
]
|
||||||
}],
|
}],
|
||||||
|
|
||||||
|
[{
|
||||||
|
line: '/foo/',
|
||||||
|
tokens: [
|
||||||
|
{ startIndex: 0, type: 'regexp.js' }
|
||||||
|
]
|
||||||
|
}],
|
||||||
|
|
||||||
|
[{
|
||||||
|
line: '/foo/g',
|
||||||
|
tokens: [
|
||||||
|
{ startIndex: 0, type: 'regexp.js' },
|
||||||
|
{ startIndex: 5, type: 'keyword.other.js' }
|
||||||
|
]
|
||||||
|
}],
|
||||||
|
|
||||||
|
[{
|
||||||
|
line: '/foo/gimsuy',
|
||||||
|
tokens: [
|
||||||
|
{ startIndex: 0, type: 'regexp.js' },
|
||||||
|
{ startIndex: 5, type: 'keyword.other.js' }
|
||||||
|
]
|
||||||
|
}],
|
||||||
|
|
||||||
|
[{
|
||||||
|
line: '/foo/q', // invalid flag
|
||||||
|
tokens: [
|
||||||
|
{ startIndex: 0, type: 'delimiter.js' },
|
||||||
|
{ startIndex: 1, type: 'identifier.js' },
|
||||||
|
{ startIndex: 4, type: 'delimiter.js' },
|
||||||
|
{ startIndex: 5, type: 'identifier.js' }
|
||||||
|
]
|
||||||
|
}],
|
||||||
|
|
||||||
[{
|
[{
|
||||||
line: 'x = 1 + f(2 / 3, /foo/)',
|
line: 'x = 1 + f(2 / 3, /foo/)',
|
||||||
tokens: [
|
tokens: [
|
||||||
|
|
|
||||||
|
|
@ -446,6 +446,39 @@ testTokenization('typescript', [
|
||||||
]
|
]
|
||||||
}],
|
}],
|
||||||
|
|
||||||
|
[{
|
||||||
|
line: '/foo/',
|
||||||
|
tokens: [
|
||||||
|
{ startIndex: 0, type: 'regexp.ts' }
|
||||||
|
]
|
||||||
|
}],
|
||||||
|
|
||||||
|
[{
|
||||||
|
line: '/foo/g',
|
||||||
|
tokens: [
|
||||||
|
{ startIndex: 0, type: 'regexp.ts' },
|
||||||
|
{ startIndex: 5, type: 'keyword.other.ts' }
|
||||||
|
]
|
||||||
|
}],
|
||||||
|
|
||||||
|
[{
|
||||||
|
line: '/foo/gimsuy',
|
||||||
|
tokens: [
|
||||||
|
{ startIndex: 0, type: 'regexp.ts' },
|
||||||
|
{ startIndex: 5, type: 'keyword.other.ts' }
|
||||||
|
]
|
||||||
|
}],
|
||||||
|
|
||||||
|
[{
|
||||||
|
line: '/foo/q', // invalid flag
|
||||||
|
tokens: [
|
||||||
|
{ startIndex: 0, type: 'delimiter.ts' },
|
||||||
|
{ startIndex: 1, type: 'identifier.ts' },
|
||||||
|
{ startIndex: 4, type: 'delimiter.ts' },
|
||||||
|
{ startIndex: 5, type: 'identifier.ts' }
|
||||||
|
]
|
||||||
|
}],
|
||||||
|
|
||||||
[{
|
[{
|
||||||
line: 'x = 1 + f(2 / 3, /foo/)',
|
line: 'x = 1 + f(2 / 3, /foo/)',
|
||||||
tokens: [
|
tokens: [
|
||||||
|
|
|
||||||
|
|
@ -130,7 +130,7 @@ export const language = {
|
||||||
{ include: '@whitespace' },
|
{ include: '@whitespace' },
|
||||||
|
|
||||||
// regular expression: ensure it is terminated before beginning (otherwise it is an opeator)
|
// regular expression: ensure it is terminated before beginning (otherwise it is an opeator)
|
||||||
[/\/(?=([^\\\/]|\\.)+\/([gimuy]*)(\s*)(\.|;|\/|,|\)|\]|\}|$))/, { token: 'regexp', bracket: '@open', next: '@regexp' }],
|
[/\/(?=([^\\\/]|\\.)+\/([gimsuy]*)(\s*)(\.|;|\/|,|\)|\]|\}|$))/, { token: 'regexp', bracket: '@open', next: '@regexp' }],
|
||||||
|
|
||||||
// delimiters and operators
|
// delimiters and operators
|
||||||
[/[()\[\]]/, '@brackets'],
|
[/[()\[\]]/, '@brackets'],
|
||||||
|
|
@ -190,7 +190,7 @@ export const language = {
|
||||||
[/[^\\\/]/, 'regexp'],
|
[/[^\\\/]/, 'regexp'],
|
||||||
[/@regexpesc/, 'regexp.escape'],
|
[/@regexpesc/, 'regexp.escape'],
|
||||||
[/\\\./, 'regexp.invalid'],
|
[/\\\./, 'regexp.invalid'],
|
||||||
['/', { token: 'regexp', bracket: '@close' }, '@pop'],
|
[/(\/)([gimsuy]*)/, [{ token: 'regexp', bracket: '@close', next: '@pop' }, 'keyword.other']],
|
||||||
],
|
],
|
||||||
|
|
||||||
regexrange: [
|
regexrange: [
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue