Skip to content

Commit

Permalink
[Erlang] Fix quoted identifier lookahead
Browse files Browse the repository at this point in the history
Fixes sublimehq#1878 (comment)

This commit improves the quoted identifier pattern as the old one
caused the namespace lookahead to be triggered in the wrong place.

The following token was matched by the (?={{ident}}\s*:[^:=]) pattern
in the namespace context by accident:

   '$get_stacktrace') catch exit:'$get_stacktrace':

The new pattern makes sure to stop matching at the first unescaped
single quote. Any number of escaped backslashes is allowed in front of
it.
  • Loading branch information
DeathAxe committed Oct 28, 2019
1 parent f60f80a commit 63a118a
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
5 changes: 4 additions & 1 deletion Erlang/Erlang.sublime-syntax
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,15 @@ variables:
# end of identifier lookahead
# Note: avoid negative lookahead as it is 6-8% slower
ident_break: (?={{ident_break_char}})
# a quoted identifier with possibly escaped single quote
# preceeded by an arbitary number of excaped backslashes
ident_quoted: \'((?:\\\\)*\\\'|[^''])*\'
# an identifier can be an atom or a variable
ident_unquoted: '[_A-Za-z]{{ident_char}}*'
# all characters not being used to indicate a context change
illegal_ident: '[^\s,:.;''(){}\[\]%=|/]+'
# quoted/unquoted/macro identifier
ident: \?{,2}(?:{{ident_unquoted}}|\'.*?(?=[^\\])\')
ident: \?{,2}(?:{{ident_unquoted}}|{{ident_quoted}})

# http://erlang.org/doc/reference_manual/macros.html#predefined-macros
erlang_macros: |-
Expand Down
28 changes: 28 additions & 0 deletions Erlang/syntax_test_erlang.erl
Original file line number Diff line number Diff line change
Expand Up @@ -1630,6 +1630,34 @@ preprocessor_define_tests() -> .
% <- punctuation.section.arguments.end.erlang
%^ punctuation.terminator.clause.erlang

-define(_get_stacktrace_(),
try exit('$get_stacktrace') catch exit:'$get_stacktrace':Stacktrace -> Stacktrace end).
% ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.preprocessor.define.arguments.erlang
% ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.exception.try.erlang
% ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.exception.catch.erlang
% ^^^ meta.exception.try.erlang
% ^^^^ meta.function-call.name.erlang
% ^^^^^^^^^^^^^^^^^^^ meta.function-call.arguments.erlang
% ^^^ keyword.control.exception.try.erlang
% ^^^^ support.function.erlang
% ^ punctuation.section.arguments.begin.erlang
% ^ punctuation.definition.atom.begin.erlang
% ^^^^^^^^^^^^^^^^^ constant.other.symbol.erlang
% ^ punctuation.definition.atom.end.erlang
% ^ punctuation.section.arguments.end.erlang
% ^^^^^ keyword.control.exception.catch.erlang
% ^^^^ constant.language.exception.type.erlang
% ^ punctuation.separator.patterns.erlang
% ^ punctuation.definition.atom.begin.erlang
% ^^^^^^^^^^^^^^^^^ constant.other.symbol.erlang
% ^ punctuation.definition.atom.end.erlang
% ^ punctuation.separator.patterns.erlang
% ^^^^^^^^^^ variable.other.erlang
% ^^ punctuation.separator.clause-head-body.erlang
% ^^^^^^^^^^ variable.other.erlang
% ^^^ keyword.control.exception.end.erlang
%

% directive-export tests

preprocessor_export_tests() -> .
Expand Down

0 comments on commit 63a118a

Please sign in to comment.