From 36ea1a8253c4ae6b876d1e492b94ddcce9fb6d8f Mon Sep 17 00:00:00 2001 From: Mihai Bazon Date: Thu, 26 Sep 2024 23:50:53 +0300 Subject: [PATCH] highlight funcalls --- src/js/ymacs-baselang.js | 5 +++++ src/js/ymacs-mode-js.js | 25 +++++++++++++------------ 2 files changed, 18 insertions(+), 12 deletions(-) diff --git a/src/js/ymacs-baselang.js b/src/js/ymacs-baselang.js index 0bfa3a4..c2c6d65 100644 --- a/src/js/ymacs-baselang.js +++ b/src/js/ymacs-baselang.js @@ -235,6 +235,7 @@ export class Ymacs_BaseLang { this.t(tokType, n); return p; } + popInParen(start, n, tokType = "close-paren") { let s = this._stream; if (this._inParens !== NIL) { @@ -253,15 +254,19 @@ export class Ymacs_BaseLang { this.t("error", n); } } + inParen() { return this._inParens.car; } + doneParen(p) { this._parens = new Cons(p, this._parens); } + pushCont(cont) { this._cont = new Cons(cont, this._cont); } + popCont() { this._cont = this._cont.cdr; } diff --git a/src/js/ymacs-mode-js.js b/src/js/ymacs-mode-js.js index de65812..21a8dc3 100644 --- a/src/js/ymacs-mode-js.js +++ b/src/js/ymacs-mode-js.js @@ -57,10 +57,12 @@ class Ymacs_Lang_JS extends Ymacs_BaseLang { this._isProp = s.peek() == "."; let tok = this.readName(); if (tok) { + this.skipWS(); if (isProp) { - this.token(tok, null); + this.token(tok, s.lookingAt("(") ? "function-name" : null); } else if (!this.parseALittle(tok)) { - let type = s.lookingAt(/^\s*:/) ? null + let type = s.lookingAt(":") ? null + : s.lookingAt("(") ? "function-name" : tok.id in KEYWORDS ? "keyword" : tok.id in KEYWORDS_TYPE ? "type" : tok.id in KEYWORDS_CONST ? "constant" @@ -76,30 +78,29 @@ class Ymacs_Lang_JS extends Ymacs_BaseLang { parseALittle(tok) { let s = this._stream; let paren = this.inParen(); + let name; switch (tok.id) { case "class": - this.token(tok, "keyword"); - this.skipWS(); - let name = this.maybeName("type"); - this.skipWS(); - if (this.maybeName("keyword")?.id == "extends") { + if (s.lookingAt("{") || (name = this.maybeName("type"))) { + this.token(tok, "keyword"); this.skipWS(); - this.maybeName("type"); + if (this.maybeName("keyword")?.id == "extends") { + this.skipWS(); + this.maybeName("type"); + } + this.setParenMeta({ class: tok, name: name }); } - this.setParenMeta({ class: tok, name: name }); return true; case "function": this.token(tok, "keyword"); - this.skipWS(); this.maybeName("function-name"); return true; case "new": this.token(tok, "keyword"); - if (!s.lookingAt(/^\s*class/)) { - this.skipWS(); + if (!s.lookingAt(/^class/)) { this.maybeName("type"); } return true;