diff --git a/extending.html b/extending.html index acfd3a3675..51bf777dcb 100644 --- a/extending.html +++ b/extending.html @@ -63,6 +63,19 @@

Language definitions

alias: 'string' } } + +
greedy
+
This is a boolean attribute. It is intended to solve a common problem with + patterns that match long strings like comments, regex or string literals. For example, + comments are parsed first, but if the string /* foo */ + appears inside a string, you would not want it to be highlighted as a comment. + The greedy-property allows a pattern to ignore previous matches of other patterns, and + overwrite them when necessary. Use this flag with restraint, as it incurs a small performance overhead. + The following example demonstrates its usage: +
'string': {
+	pattern: /(["'])(\\(?:\r\n|[\s\S])|(?!\1)[^\\\r\n])*\1/,
+	greedy: true
+}

Unless explicitly allowed through the inside property, each token cannot contain other tokens, so their order is significant. Although per the ECMAScript specification, objects are not required to have a specific ordering of their properties, in practice they do in every modern browser.