Skip to content

Commit

Permalink
Merge pull request #52 from borela/hotfix/rewrite-fjsx15-regex-literal
Browse files Browse the repository at this point in the history
Remove dependency from sublime's core regex
  • Loading branch information
borela authored Jan 18, 2018
2 parents e2d8ad2 + 70064c0 commit 74597e1
Show file tree
Hide file tree
Showing 12 changed files with 441 additions and 19 deletions.
56 changes: 37 additions & 19 deletions syntaxes/fjsx15/literal/string/regex.sublime-syntax
Original file line number Diff line number Diff line change
Expand Up @@ -19,25 +19,43 @@ scope: ...

contexts:
main:
- match: |
(?x)
\s*/
(?=
.*?
(?<!\\)/
[a-z]{0,5}
)
scope: punctuation.definition.string.begin.js.fjsx15
set: regex
regex:
- meta_scope: string.regexp.js.fjsx15
- include: Packages/JavaScript/Regular Expressions (JavaScript).sublime-syntax
- include: regex-end

regex-end:
- match: (/)([a-z]{0,5})
- match: \s*(/)
captures:
1: >-
string.regexp.js.fjsx15
punctuation.definition.string.begin.js.fjsx15
set: [
regex-meta,
close-regex,
regex-content
]

close-regex:
- match: \s*(/)([a-z]*)
captures:
1: punctuation.definition.string.end.js.fjsx15
2: regex.flag.js.fjsx15
2: keyword.other.flag.js.fjsx15
pop: true
- match: (?=\s*\S)
push: regex-content

pop-now:
- match: ""
pop: true

regex-content:
- include: Packages/Naomi/syntaxes/fjsx15/literal/string/regex/anchor.sublime-syntax
- include: Packages/Naomi/syntaxes/fjsx15/literal/string/regex/backref.sublime-syntax
- include: Packages/Naomi/syntaxes/fjsx15/literal/string/regex/backslash.sublime-syntax
- include: Packages/Naomi/syntaxes/fjsx15/literal/string/regex/capturing-group.sublime-syntax
- include: Packages/Naomi/syntaxes/fjsx15/literal/string/regex/character-class.sublime-syntax
- include: Packages/Naomi/syntaxes/fjsx15/literal/string/regex/lookahead.sublime-syntax
- include: Packages/Naomi/syntaxes/fjsx15/literal/string/regex/negative-lookahead.sublime-syntax
- include: Packages/Naomi/syntaxes/fjsx15/literal/string/regex/non-capturing-group.sublime-syntax
- include: Packages/Naomi/syntaxes/fjsx15/literal/string/regex/operator.sublime-syntax
- include: Packages/Naomi/syntaxes/fjsx15/literal/string/regex/quantifier.sublime-syntax
- include: pop-now

regex-meta:
- meta_content_scope: string.regexp.js.fjsx15
- include: pop-now
26 changes: 26 additions & 0 deletions syntaxes/fjsx15/literal/string/regex/anchor.sublime-syntax
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
%YAML1.2
---

# Licensed under the Apache License, Version 2.0 (the “License”); you may not
# use this file except in compliance with the License. You may obtain a copy of
# the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an “AS IS” BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations under
# the License.

hidden: true

scope: ...

contexts:
main:
# ^ $ \b
- match: \s*((?>\\b|\^|\$))
captures:
1: keyword.control.anchor.regexp.js.fjsx15
pop: true
25 changes: 25 additions & 0 deletions syntaxes/fjsx15/literal/string/regex/backref.sublime-syntax
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
%YAML1.2
---

# Licensed under the Apache License, Version 2.0 (the “License”); you may not
# use this file except in compliance with the License. You may obtain a copy of
# the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an “AS IS” BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations under
# the License.

hidden: true

scope: ...

contexts:
main:
- match: \s*(\\[1-9][0-9]*)
captures:
1: keyword.other.back-reference.regexp.js.fjsx15
pop: true
39 changes: 39 additions & 0 deletions syntaxes/fjsx15/literal/string/regex/backslash.sublime-syntax
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
%YAML1.2
---

# Licensed under the Apache License, Version 2.0 (the “License”); you may not
# use this file except in compliance with the License. You may obtain a copy of
# the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an “AS IS” BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations under
# the License.

hidden: true

scope: ...

contexts:
main:
# Character classes/sets.
- match: (?i)\s*(\\[wsd]|)
captures:
1: constant.other.character-class.escape.backslash.regexp
pop: true
# Other escape sequences.
- match: |
(?x)\s*
(\\
(?> c[A-Z]
| x[\da-fA-F]{2}
| u[\da-fA-F]{4}
| .
)
)
captures:
1: constant.character.escape.backslash.regexp.js.fjsx15
pop: true
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
%YAML1.2
---

# Licensed under the Apache License, Version 2.0 (the “License”); you may not
# use this file except in compliance with the License. You may obtain a copy of
# the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an “AS IS” BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations under
# the License.

hidden: true

scope: ...

contexts:
main:
- match: \s*(\()(?!\?)
captures:
1: punctuation.definition.group.begin.regexp.js.fjsx15
set: [ meta, close, regex-content ]

close:
- match: \s*(\))
captures:
1: punctuation.definition.group.end.regexp.js.fjsx15
pop: true
- match: (?=\s*\S)
push: regex-content

meta:
- meta_scope: meta.group.regexp.js.fjsx15
- match: ""
pop: true

regex-content:
- include: Packages/Naomi/syntaxes/fjsx15/literal/string/regex.sublime-syntax#regex-content
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
%YAML1.2
---

# Licensed under the Apache License, Version 2.0 (the “License”); you may not
# use this file except in compliance with the License. You may obtain a copy of
# the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an “AS IS” BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations under
# the License.

hidden: true

scope: ...

contexts:
main:
- match: \s*((\[)(\^)?)
captures:
1: constant.other.character-class.regexp.js.fjsx15
2: punctuation.definition.character-class.begin.regexp.js.fjsx15
3: keyword.operator.negation.regexp.js.fjsx15
set: [ close, content ]

close:
- match: (\])
captures:
1: >-
constant.other.character-class.regexp.js.fjsx15
punctuation.definition.character-class.end.regexp.js.fjsx15
pop: true
- match: (?=\s*\S)
push: content

content:
- include: Packages/Naomi/syntaxes/fjsx15/literal/string/regex/character-class/range.sublime-syntax
- include: Packages/Naomi/syntaxes/fjsx15/literal/string/regex/backslash.sublime-syntax
- match: .
scope: constant.other.character-class.regexp.js.fjsx15
pop: true
- include: pop-now

pop-now:
- match: ""
pop: true
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
%YAML1.2
---

# Licensed under the Apache License, Version 2.0 (the “License”); you may not
# use this file except in compliance with the License. You may obtain a copy of
# the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an “AS IS” BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations under
# the License.

hidden: true

scope: ...

variables:
possibleRange: |
(?> \w
| \d
| \\
(?> c[A-Z]
| x[\da-fA-F]{2}
| u[\da-fA-F]{4}
)
)
contexts:
main:
- match: |
(?xi)\s*
({{possibleRange}}-{{possibleRange}})
captures:
1: constant.other.character-class.range.regexp.js.fjsx15
pop: true
41 changes: 41 additions & 0 deletions syntaxes/fjsx15/literal/string/regex/lookahead.sublime-syntax
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
%YAML1.2
---

# Licensed under the Apache License, Version 2.0 (the “License”); you may not
# use this file except in compliance with the License. You may obtain a copy of
# the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an “AS IS” BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations under
# the License.

hidden: true

scope: ...

contexts:
main:
- match: \s*(\(\?=)
captures:
1: punctuation.definition.group.assertion.begin.regexp.js.fjsx15
set: [ meta, close, regex-content ]

close:
- match: \s*(\))
captures:
1: punctuation.definition.group.assertion.end.regexp.js.fjsx15
pop: true
- match: (?=\s*\S)
push: regex-content

meta:
- meta_scope: meta.group.assertion.look-ahead.regexp.js.fjsx15
- match: ""
pop: true

regex-content:
- include: Packages/Naomi/syntaxes/fjsx15/literal/string/regex.sublime-syntax#regex-content
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
%YAML1.2
---

# Licensed under the Apache License, Version 2.0 (the “License”); you may not
# use this file except in compliance with the License. You may obtain a copy of
# the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an “AS IS” BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations under
# the License.

hidden: true

scope: ...

contexts:
main:
- match: \s*(\(\?!)
captures:
1: punctuation.definition.group.assertion.begin.regexp.js.fjsx15
set: [ meta, close, regex-content ]

close:
- match: \s*(\))
captures:
1: punctuation.definition.group.assertion.end.regexp.js.fjsx15
pop: true
- match: (?=\s*\S)
push: regex-content

meta:
- meta_scope: meta.group.assertion.look-ahead.negative.regexp.js.fjsx15
- match: ""
pop: true

regex-content:
- include: Packages/Naomi/syntaxes/fjsx15/literal/string/regex.sublime-syntax#regex-content
Loading

0 comments on commit 74597e1

Please sign in to comment.