Skip to content

Regular Expression fixes in class set and comment rules #8

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 13, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 16 additions & 12 deletions Regular Expressions (Elixir).sublime-syntax
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ contexts:
- include: subroutine_call
- include: back_reference
- include: assertion
- include: comment
- include: escape_sequence
- include: class_set
- include: inline_option
Expand All @@ -33,7 +34,6 @@ contexts:
- include: operator
- include: quantifier
- include: dot_meta_char
- include: comment
- include: literal

quoted_sequence:
Expand Down Expand Up @@ -367,16 +367,11 @@ contexts:
- match: \[:.*?:\]
scope: invalid.illegal.posix-class.regexp.elixir
set: unexpected_quantifier_pop
- match: (\[)(\])
scope: meta.set.regexp.elixir keyword.control.set.regexp.elixir invalid.illegal.set.regexp.elixir
captures:
1: punctuation.definition.set.begin.regexp.elixir
2: punctuation.definition.set.end.regexp.elixir
set: unexpected_quantifier_pop
- match: (\[)(\^?)
- match: (\[)(\^?)(]?)
captures:
1: keyword.control.set.regexp.elixir punctuation.definition.set.begin.regexp.elixir
2: keyword.operator.negation.regexp.elixir
3: meta.literal.regexp.elixir
push:
- meta_scope: meta.set.regexp.elixir
- include: character_range
Expand All @@ -388,9 +383,9 @@ contexts:
- include: literal

character_range:
- match: (?=(\\[dsw]|\\x\h\h|\\\d+|\\c\p{ascii}|\\.|.)-\g<1>)
- match: (?=(\\x\h\h?|\\x{\h+}|\\[0-7]{1,3}|\o{[0-7]+}|\\c\p{ascii}|\\.|[^\\])-(?!])\g<1>)
push:
- match: (?>(\\[dsw])|(\\x\h\h|\\\d+|\\c\p{ascii}|\\.|.))
- match: (\\[dsw])|(\\x\h\h?|\\x{\h+}|\\[0-7]{1,3}|\o{[0-7]+}|\\c\p{ascii}|\\.|[^\\])
scope: meta.character-range.regexp.elixir
captures:
1: invalid.illegal.range.regexp.elixir
Expand All @@ -400,7 +395,7 @@ contexts:
scope: keyword.operator.range.regexp.elixir
set:
- meta_scope: meta.character-range.regexp.elixir
- match: (?>(\\[dsw])|(\\x\h\h|\\\d+|\\c\p{ascii}|\\.|.))
- match: (\\[dsw])|(\\x\h\h?|\\x{\h+}|\\[0-7]{1,3}|\o{[0-7]+}|\\c\p{ascii}|\\.|[^\\])
captures:
1: invalid.illegal.range.regexp.elixir
2: constant.other.range.regexp.elixir
Expand All @@ -412,6 +407,9 @@ contexts:
scope: invalid.illegal.escape-sequence.regexp.elixir
- match: \\b
scope: constant.character.escape.backspace.regexp.elixir
# Inside a class set \x, \xh and \xhh are valid sequences.
- match: \\x\h?\h?
scope: constant.character.escape.hex.regexp.elixir
- include: common_escape_sequence

# E.g: [:alpha:] or [:^alpha:]
Expand Down Expand Up @@ -465,7 +463,13 @@ contexts:
scope: keyword.other.any.regexp.elixir

comment:
- match: (?<!\\\s)(?<=\s)#
- match: '(?=(\\{2})*\\ #)'
push:
- include: escape_sequence
- match: '#'
scope: meta.literal.regexp.elixir
pop: true
- match: (?<=\s)#
push:
- meta_scope: comment.line.number-sign.regexp.elixir
- match: \n
Expand Down
87 changes: 71 additions & 16 deletions syntax_test_regexp.ex
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@
#// ^^ invalid.illegal.general-category.regexp.elixir
#// ^^ invalid.illegal.general-category.regexp.elixir
#// ^^^ invalid.illegal.general-category.regexp.elixir
#//^^^^^^^^^ constant.other.escape-sequence.general-category.regexp.elixir
#//^^^^^^^^^^^^^ constant.other.escape-sequence.general-category.regexp.elixir
~r"\K\R\X\?\*\+\.\x00\00\07\o\o{}\o{84}\o{0}\cX\cä\a\e\f\n\r\t"
#//^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ constant.character.escape

Expand All @@ -73,19 +73,61 @@
#//^^^^^^^^^^^^^^ keyword.control.anchor

# Class sets:
# TODO:
~r"[.+*?{1}()|^$][\N\b]"
#// ^^ constant.character.escape.backspace.regexp.elixir
#// ^^ invalid.illegal.escape-sequence.regexp.elixir
#// ^^^^^^^^^^^^ meta.literal.regexp.elixir
#//^^^^^^^^^^^^^^ meta.set.regexp.elixir
~r"[[:>:]][]"
#// ^^ invalid.illegal.set.regexp.elixir
~r"[.+*?{1}()[|^$][\N\b\x\xf\xff\A\B\g\G\k\K\R\X\z\Z]"
#// ^^^^^^^^^^^^^^^^^^^^ constant.character.escape.regexp.elixir
#// ^^^^^^^^^ constant.character.escape.hex.regexp.elixir
#// ^^ constant.character.escape.backspace.regexp.elixir
#// ^^ invalid.illegal.escape-sequence.regexp.elixir
#// ^^^^^^^^^^^^^ meta.literal.regexp.elixir
#//^^^^^^^^^^^^^^^ meta.set.regexp.elixir
~r"[[:>:]]"
#// ^^^^^ invalid.deprecated.word-boundary.regexp.elixir
~r"[a]][]][^]][^a]"
#// ^ meta.literal.regexp.elixir
#// ^ punctuation.definition.set.end.regexp.elixir
#// ^ meta.literal.regexp.elixir
#// ^ keyword.operator.negation.regexp.elixir
#// ^ punctuation.definition.set.end.regexp.elixir
#// ^ meta.literal.regexp.elixir
#// ^ meta.literal.regexp.elixir
#// ^ meta.literal.regexp.elixir
~r"[
#// ^ meta.set.regexp.elixir
#// ^ meta.set.regexp.elixir meta.literal.regexp.elixir
]"

~r"[a-b-c] [-a-z-] [\d-\s \w-\\] [\x0-\x1] [\x00-\xff] [\000-\007] [\0-\18]"
#// ^ meta.literal.regexp.elixir
#// ^^^^ constant.other.range.regexp.elixir
#// ^ keyword.operator.range.regexp.elixir
#// ^^^^ constant.other.range.regexp.elixir
#// ^^^^ constant.other.range.regexp.elixir
#// ^^^^ constant.other.range.regexp.elixir
#// ^^^ constant.other.range.regexp.elixir
#// ^^^ constant.other.range.regexp.elixir
#// ^^ constant.other.range.regexp.elixir
#// ^^ invalid.illegal.range.regexp.elixir
#// ^^ invalid.illegal.range.regexp.elixir
#// ^^ invalid.illegal.range.regexp.elixir
#// ^ meta.literal.regexp.elixir
#// ^ keyword.operator.range.regexp.elixir
#// ^ meta.literal.regexp.elixir
#// ^^ meta.literal.regexp.elixir
~r"[-] [--] [---] [\--\-] [[--] [--[] [[-[] [[-] [[-\]] [\[-\]]"
#// ^^ constant.other.range.regexp.elixir
#// ^^ constant.other.range.regexp.elixir
#// ^^ meta.literal.regexp.elixir
#// ^ constant.other.range.regexp.elixir
#// ^ constant.other.range.regexp.elixir
#// ^ constant.other.range.regexp.elixir
#// ^ constant.other.range.regexp.elixir
#// ^ constant.other.range.regexp.elixir
#// ^^ constant.other.range.regexp.elixir
#// ^^ constant.other.range.regexp.elixir
#// ^ keyword.operator.range.regexp.elixir
#// ^ punctuation.definition.set.end.regexp.elixir
#// ^^ meta.literal.regexp.elixir
#// ^ meta.literal.regexp.elixir

# Inline options:
~r"(*NO_START_OPT)(*UTF)(*UTF8)(*UCP)(*CRLF)(*CR)(*LF)(*ANYCRLF)(*ANY)(*BSR_ANYCRLF)(*BSR_UNICODE)(*LIMIT_MATCH=)(*LIMIT_RECURSION=)(*ANY)"
#//^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ keyword.control.flag.regexp.elixir
Expand Down Expand Up @@ -206,18 +248,31 @@

# Comments:
~r"(?#comment block)"
#//^^^^^^^^^^ comment.block.group.regexp.elixir
#//^^^^^^^^^^^^^^^^^ comment.block.group.regexp.elixir
~r"# # comment line"
#// ^ comment.line.number-sign.regexp.elixir
#//^^ meta.literal.regexp.elixir
~r"[ # not a comment inside a set]"
#// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.literal.regexp.elixir
~r" # a comment"
#// ^^^^^^^^^^^ comment.line.number-sign.regexp.elixir
#//^ meta.literal.regexp.elixir
~r"\ # escape preceding space to prevent matching as a comment"
#// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.literal.regexp.elixir
~r"\ # \\\ # # a comment"
#// ^^^^^^^^^^^ comment.line.number-sign.regexp.elixir
#// ^^ meta.literal.regexp.elixir
#// ^^^^ constant.character.escape.regexp.elixir
#// ^^ meta.literal.regexp.elixir
#//^^ constant.character.escape.regexp.elixir
~r"\ # escape preceding space to prevent matching as a comment
#// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.literal.regexp.elixir
#//^^ constant.character.escape.regexp.elixir
(back to regex...)
#// ^^^ keyword.other.any.regexp.elixir
"
~r"\\ # match as comment with an even number of preceding backslashes
#// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ comment.line.number-sign.regexp.elixir
#//^^ constant.character.escape.regexp.elixir
(back to regex...)
#// ^^^ keyword.other.any.regexp.elixir
"

~r"no preceding space#not a comment"
#//^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.literal.regexp.elixir
~R[ #{123}] ~r[ #{123}]
Expand Down