From 12b0ffced3e927538713f58b34e96705a3a96560 Mon Sep 17 00:00:00 2001 From: David Cameron Date: Mon, 18 May 2026 08:02:08 -0400 Subject: [PATCH] Allow reserved words in member access --- feature/access.js | 18 ++++++++++++++++-- test/jessie.js | 5 +++++ 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/feature/access.js b/feature/access.js index 86675de..2afb7e7 100644 --- a/feature/access.js +++ b/feature/access.js @@ -2,15 +2,29 @@ * Property access: a.b, a[b], a(b), [1,2,3] - parse half * For private fields (#x), see class.js */ -import { access, binary } from '../parse.js'; +import { access, cur, err, expr, idx, next, parse, skip, token } from '../parse.js'; const ACCESS = 170; +const HASH = 35, _0 = 48, _9 = 57; // a[b] access('[]', ACCESS); // a.b -binary('.', ACCESS); +token('.', ACCESS, a => { + if (!a) return; + + parse.space(); + if (cur.charCodeAt(idx) === HASH) { + skip(); + const id = next(parse.id); + return id ? ['.', a, '#' + id] : err('Expected property name'); + } + + const cc = cur.charCodeAt(idx); + const prop = cc >= _0 && cc <= _9 ? expr(ACCESS) : next(parse.id) || expr(ACCESS); + return ['.', a, prop || err('Expected property name')]; +}); // a(b,c,d), a() access('()', ACCESS); diff --git a/test/jessie.js b/test/jessie.js index 4de83a5..4f0725c 100644 --- a/test/jessie.js +++ b/test/jessie.js @@ -24,6 +24,11 @@ test('jessie: inherits justin', () => { is(parse('{a: 1}'), ['{}', [':', 'a', [, 1]]]) }) +test('jessie: reserved words in member access', () => { + is(parse('record.function.kind'), ['.', ['.', 'record', 'function'], 'kind']) + is(parse('record.class.name'), ['.', ['.', 'record', 'class'], 'name']) +}) + // === variables === test('jessie: variables', () => {