From e2c5a7ef684f576bea9a097037ae1e6ecc2be40b Mon Sep 17 00:00:00 2001 From: Chandler Carruth Date: Sat, 9 Jul 2022 19:40:09 -0700 Subject: [PATCH] [highlightjs] Add support for `var` and `let`. (#1366) This required reworking how `=` and `;` were handled as well as more general surgery on patterns. This looks for initializers at the top level of parameters and at the end of `var` or `let` declarations. It supports fancy nested `var` patterns within `let` declarations, etc. Co-authored-by: josh11b --- highlighting/highlightjs_carbon_lang.js | 87 ++++++++++++++++++------- highlighting/highlightjs_example.html | 3 +- 2 files changed, 64 insertions(+), 26 deletions(-) diff --git a/highlighting/highlightjs_carbon_lang.js b/highlighting/highlightjs_carbon_lang.js index 9f829373bed5..2651bbc546df 100644 --- a/highlighting/highlightjs_carbon_lang.js +++ b/highlighting/highlightjs_carbon_lang.js @@ -9,7 +9,6 @@ * Category: common, system * Website: https://github.com/carbon-language/carbon-lang/ * - * TODO: local `var` and `let` declarations. * TODO: struct literals. * TODO: abstract, virtual, impl on methods. * TODO: private, protected. @@ -88,7 +87,7 @@ export default function (hljs) { // But it is harmless to give them nicer syntax highlighting. Eventually, as // the language settles, we can explore specifically highlighting operators // that aren't valid as errors. - const PUNCTUATION = [/->/, /\./, /:!?/, /;/]; + const PUNCTUATION = [/->/, /\./]; const OPERATORS = [ />>=/, /<=>/, @@ -117,7 +116,6 @@ export default function (hljs) { /&/, /\\/, /\^/, - /=/, /!/, />/, / i64 { var i: i64 = -1; + let (x: i64, var y: i64) = (1, 2); for (e: T in s) { if (e <= s.Last()) { @@ -49,7 +50,7 @@ constraint WidgetC { } base class Widget { - fn Print[addr me: Self*](var i: i64, x: f32, _: bool); + fn Print[addr me: Self*](var i: i64, x: f32 = 4.2, _: bool); } fn Widget.Print[addr me: Self*](var i: i64, x: f32, _: bool, 47) {