[gtksourceview] javascript.lang: Add/update ES2015 number contexts
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtksourceview] javascript.lang: Add/update ES2015 number contexts
- Date: Mon, 26 Nov 2018 23:17:34 +0000 (UTC)
commit 3059e445fbe3391368c9c33af983d8e054ac86de
Author: Jeffery To <jeffery to gmail com>
Date: Sun Jul 1 04:46:45 2018 +0800
javascript.lang: Add/update ES2015 number contexts
* Add decimal context that matches the JS spec more closely than
def:decimal
* Add contexts for ES2015 binary and octal integer literals
* Copy octal and hex contexts from def.lang, adding atomic grouping
Legacy octal numbers (prefixed with "0", e.g. "0755") are still valid
but throw a SyntaxError in strict mode.
References:
https://www.ecma-international.org/ecma-262/6.0/index.html#sec-literals-numeric-literals
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Lexical_grammar#Octal
data/language-specs/javascript.lang | 47 +++++++++++++++++++++++++++++++++----
tests/syntax-highlighting/file.js | 6 +++++
2 files changed, 49 insertions(+), 4 deletions(-)
---
diff --git a/data/language-specs/javascript.lang b/data/language-specs/javascript.lang
index 684cbc71..69ab2c2a 100644
--- a/data/language-specs/javascript.lang
+++ b/data/language-specs/javascript.lang
@@ -35,6 +35,8 @@
<styles>
<style id="escape" name="Escaped Character" map-to="def:special-char"/>
+ <style id="decimal" name="Decimal Number" map-to="def:decimal"/>
+ <style id="base-n-number" name="Base-N Number" map-to="def:base-n-integer"/>
<style id="null-value" name="Null Value" map-to="def:special-constant"/>
<style id="undefined-value" name="Undefined Value" map-to="def:special-constant"/>
<style id="boolean" name="Boolean Value" map-to="def:boolean"/>
@@ -120,6 +122,42 @@
</include>
</context>
+ <context id="decimal" style-ref="decimal">
+ <match extended="true">
+ (?<! [\w\.] )
+ (?>
+ ( [1-9][0-9]* | 0 ) ( \. [0-9]* )? |
+ \. [0-9]+
+ )
+ (?> [eE] [+-]? [0-9]+ )?
+ (?! [\w\.] )
+ </match>
+ </context>
+
+ <context id="binary-integer" style-ref="base-n-number">
+ <match extended="true">
+ (?<![\w\.]) (?>0 [bB] [01]+) (?![\w\.])
+ </match>
+ </context>
+
+ <context id="octal-integer" style-ref="base-n-number">
+ <match extended="true">
+ (?<![\w\.]) (?>0 [oO] [0-7]+) (?![\w\.])
+ </match>
+ </context>
+
+ <context id="hex-integer" style-ref="base-n-number">
+ <match extended="true">
+ (?<![\w\.]) (?>0 [xX] [0-9a-fA-F]+) (?![\w\.])
+ </match>
+ </context>
+
+ <context id="legacy-octal-integer" style-ref="base-n-number">
+ <match extended="true">
+ (?<![\w\.]) (?>0 [0-7]+) (?![\w\.])
+ </match>
+ </context>
+
<!--
There was a long discussion on ##javascript on freenode between
'katspaugh', 'joo' and 'prog_' on whether 'undefined' should be
@@ -368,10 +406,11 @@
<context ref="string" />
<context ref="single-quoted-string" />
<context ref="template-string"/>
- <context ref="def:float"/>
- <context ref="def:decimal"/>
- <context ref="def:octal"/>
- <context ref="def:hexadecimal"/>
+ <context ref="decimal"/>
+ <context ref="binary-integer"/>
+ <context ref="octal-integer"/>
+ <context ref="hex-integer"/>
+ <context ref="legacy-octal-integer"/>
<context ref="undefined-value"/>
<context ref="null-value"/>
<context ref="boolean"/>
diff --git a/tests/syntax-highlighting/file.js b/tests/syntax-highlighting/file.js
index ca30228f..7897808a 100644
--- a/tests/syntax-highlighting/file.js
+++ b/tests/syntax-highlighting/file.js
@@ -27,6 +27,12 @@ x = a /b/ c / d;
'\u{1D306}' // Unicode code point escape
/\cJ/ // Control escape
+// ES2015 binary and octal numbers:
+let binary1 = 0b1010;
+let binary2 = 0B00001111;
+let octal1 = 0o0123;
+let octal2 = 0O4567;
+
// Template strings
// ----------------
// Template strings are delimited by back-ticks (grave accent) and
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]