You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
fix(ts/js) use identifier to match potential keywords (#2519)
- (parser) Adds `keywords.$pattern` key to grammar definitions
- `lexemes` is now deprecated in favor of `keywords.$pattern` key
- enh(typescript) use identifier to match potential keywords, preventing false positives
- enh(javascript) use identifier to match potential keywords, preventing false positives
Copy file name to clipboardExpand all lines: docs/mode-reference.rst
+11-6Lines changed: 11 additions & 6 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -241,14 +241,19 @@ and ``endSameAsBegin: true``.
241
241
242
242
.. _lexemes:
243
243
244
-
lexemes
245
-
^^^^^^^
244
+
lexemes (now keywords.$pattern)
245
+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
246
246
247
247
**type**: regexp
248
248
249
-
A regular expression that extracts individual lexemes from language text to find :ref:`keywords <keywords>` among them.
250
-
Default value is ``hljs.IDENT_RE`` which works for most languages.
249
+
A regular expression that extracts individual "words" from the code to compare
250
+
against :ref:`keywords <keywords>`. The default value is ``\w+`` which works for
251
+
many languages.
251
252
253
+
Note: It's now recommmended that you use ``keywords.$pattern`` instead of
254
+
``lexemes``, as this makes it easier to keep your keyword pattern associated
255
+
with your keywords themselves, particularly if your keyword configuration is a
256
+
constant that you repeat multiple times within different modes of your grammar.
252
257
253
258
.. _keywords:
254
259
@@ -259,8 +264,8 @@ keywords
259
264
260
265
Keyword definition comes in two forms:
261
266
262
-
* ``'for while if else weird_voodoo|10 ... '`` -- a string of space-separated keywords with an optional relevance over a pipe
263
-
* ``{'keyword': ' ... ', 'literal': ' ... '}`` -- an object whose keys are names of different kinds of keywords and values are keyword definition strings in the first form
267
+
* ``'for while if|0 else weird_voodoo|10 ... '`` -- a string of space-separated keywords with an optional relevance over a pipe
268
+
* ``{keyword: ' ... ', literal: ' ... ', $pattern: /\w+/ }`` -- an object that describes multiple sets of keywords and the pattern used to find them
264
269
265
270
For detailed explanation see :doc:`Language definition guide </language-guide>`.
0 commit comments