Handle the "/" followed by "]" to ensure it not being treated as regex

Fixes #580
This commit is contained in:
Sheetal Nandi 2018-03-13 11:27:34 -07:00
Родитель a7080b7f47
Коммит b9f410d6cd
5 изменённых файлов: 47 добавлений и 6 удалений

Просмотреть файл

@ -1245,7 +1245,7 @@ repository:
- name: keyword.operator.arithmetic.ts
match: '%|\*|/|-|\+'
# capture the arithmetic sign followed by variable or parenthesized expression so that it is not interpreted as regex
- match: (?<=[_$[:alnum:])])\s*(/)(?![/*])
- match: (?<=[_$[:alnum:])\]])\s*(/)(?![/*])
captures:
'1': { name: keyword.operator.arithmetic.ts }
@ -2033,7 +2033,7 @@ repository:
- include: '#regexp'
# Check if complete regexp syntax
- name: string.regexp.ts
begin: (?<![_$[:alnum:])])\/(?![\/*])(?=(?:[^\/\\\[]|\\.|\[([^\]\\]|\\.)+\])+\/(?![\/*])[gimuy]*(?!\s*[a-zA-Z0-9_$]))
begin: (?<![_$[:alnum:])\]])\/(?![\/*])(?=(?:[^\/\\\[]|\\.|\[([^\]\\]|\\.)+\])+\/(?![\/*])[gimuy]*(?!\s*[a-zA-Z0-9_$]))
beginCaptures:
'0': {name: punctuation.definition.string.begin.ts}
end: (/)([gimuy]*)

Просмотреть файл

@ -3868,7 +3868,7 @@
</dict>
<dict>
<key>match</key>
<string>(?&lt;=[_$[:alnum:])])\s*(/)(?![/*])</string>
<string>(?&lt;=[_$[:alnum:])\]])\s*(/)(?![/*])</string>
<key>captures</key>
<dict>
<key>1</key>
@ -5738,7 +5738,7 @@
<key>name</key>
<string>string.regexp.ts</string>
<key>begin</key>
<string>(?&lt;![_$[:alnum:])])\/(?![\/*])(?=(?:[^\/\\\[]|\\.|\[([^\]\\]|\\.)+\])+\/(?![\/*])[gimuy]*(?!\s*[a-zA-Z0-9_$]))</string>
<string>(?&lt;![_$[:alnum:])\]])\/(?![\/*])(?=(?:[^\/\\\[]|\\.|\[([^\]\\]|\\.)+\])+\/(?![\/*])[gimuy]*(?!\s*[a-zA-Z0-9_$]))</string>
<key>beginCaptures</key>
<dict>
<key>0</key>

Просмотреть файл

@ -3814,7 +3814,7 @@
</dict>
<dict>
<key>match</key>
<string>(?&lt;=[_$[:alnum:])])\s*(/)(?![/*])</string>
<string>(?&lt;=[_$[:alnum:])\]])\s*(/)(?![/*])</string>
<key>captures</key>
<dict>
<key>1</key>
@ -5684,7 +5684,7 @@
<key>name</key>
<string>string.regexp.tsx</string>
<key>begin</key>
<string>(?&lt;![_$[:alnum:])])\/(?![\/*])(?=(?:[^\/\\\[]|\\.|\[([^\]\\]|\\.)+\])+\/(?![\/*])[gimuy]*(?!\s*[a-zA-Z0-9_$]))</string>
<string>(?&lt;![_$[:alnum:])\]])\/(?![\/*])(?=(?:[^\/\\\[]|\\.|\[([^\]\\]|\\.)+\])+\/(?![\/*])[gimuy]*(?!\s*[a-zA-Z0-9_$]))</string>
<key>beginCaptures</key>
<dict>
<key>0</key>

Просмотреть файл

@ -0,0 +1,40 @@
original file
-----------------------------------
(a[0] / 2) / (2)
-----------------------------------
Grammar: TypeScript.tmLanguage
-----------------------------------
>(a[0] / 2) / (2)
^
source.ts meta.brace.round.ts
^
source.ts variable.other.readwrite.ts
^
source.ts meta.array.literal.ts meta.brace.square.ts
^
source.ts meta.array.literal.ts constant.numeric.decimal.ts
^
source.ts meta.array.literal.ts meta.brace.square.ts
^
source.ts
^
source.ts keyword.operator.arithmetic.ts
^
source.ts
^
source.ts constant.numeric.decimal.ts
^
source.ts meta.brace.round.ts
^
source.ts
^
source.ts keyword.operator.arithmetic.ts
^
source.ts
^
source.ts meta.brace.round.ts
^
source.ts constant.numeric.decimal.ts
^
source.ts meta.brace.round.ts

1
tests/cases/Issue580.ts Normal file
Просмотреть файл

@ -0,0 +1 @@
(a[0] / 2) / (2)