Skip to content

Commit

Permalink
highlight funcalls
Browse files Browse the repository at this point in the history
  • Loading branch information
mishoo committed Sep 26, 2024
1 parent 00529d2 commit 36ea1a8
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 12 deletions.
5 changes: 5 additions & 0 deletions src/js/ymacs-baselang.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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;
}
Expand Down
25 changes: 13 additions & 12 deletions src/js/ymacs-mode-js.js
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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;
Expand Down

0 comments on commit 36ea1a8

Please sign in to comment.