diff --git a/packages/ReefVM b/packages/ReefVM index 0844e99..1a18a71 160000 --- a/packages/ReefVM +++ b/packages/ReefVM @@ -1 +1 @@ -Subproject commit 0844e99d2d04fb9ba0999f25248a17430bdc5ee6 +Subproject commit 1a18a713d7ae86b03a6bef38cc53d12ecfbf9627 diff --git a/src/parser/scopeTracker.ts b/src/parser/scopeTracker.ts index fd44057..08c64dc 100644 --- a/src/parser/scopeTracker.ts +++ b/src/parser/scopeTracker.ts @@ -2,24 +2,15 @@ import { ContextTracker } from '@lezer/lr' import * as terms from './shrimp.terms' export class Scope { - constructor( - public parent: Scope | null, - public vars: Set - ) {} + constructor(public parent: Scope | null, public vars: Set) {} has(name: string): boolean { - return this.vars.has(name) || (this.parent?.has(name) ?? false) + return this.vars.has(name) ?? this.parent?.has(name) } - add(name: string): Scope { + add(...names: string[]): Scope { const newVars = new Set(this.vars) - newVars.add(name) - return new Scope(this.parent, newVars) - } - - addAll(names: string[]): Scope { - const newVars = new Set(this.vars) - names.forEach(name => newVars.add(name)) + names.forEach((name) => newVars.add(name)) return new Scope(this.parent, newVars) } @@ -94,7 +85,7 @@ export const trackScope = new ContextTracker({ if (term === terms.Params) { const newScope = context.push() if (pendingIdentifiers.length > 0) { - const newContext = newScope.addAll(pendingIdentifiers) + const newContext = newScope.add(...pendingIdentifiers) pendingIdentifiers = [] isInParams = false return newContext @@ -109,12 +100,12 @@ export const trackScope = new ContextTracker({ } // Clear stale identifiers after non-assignment statements - if (term === terms.PropertyAccess || term === terms.FunctionCallOrIdentifier) { + if (term === terms.DotGet || term === terms.FunctionCallOrIdentifier) { pendingIdentifiers = [] } return context }, - hash: (context) => context.hash() + hash: (context) => context.hash(), }) diff --git a/src/parser/shrimp.grammar b/src/parser/shrimp.grammar index 7c6d16d..c9c4a9c 100644 --- a/src/parser/shrimp.grammar +++ b/src/parser/shrimp.grammar @@ -62,7 +62,7 @@ item { consumeToTerminator { PipeExpr | ambiguousFunctionCall | - PropertyAccess | + DotGet | IfExpr | FunctionDef | Assign | @@ -158,7 +158,7 @@ Assign { Identifier "=" consumeToTerminator } -PropertyAccess { +DotGet { Identifier "." Identifier } diff --git a/src/parser/shrimp.terms.ts b/src/parser/shrimp.terms.ts index a1ac6a8..251d3b3 100644 --- a/src/parser/shrimp.terms.ts +++ b/src/parser/shrimp.terms.ts @@ -25,7 +25,7 @@ export const Underscore = 36, NamedArg = 37, NamedArgPrefix = 38, - PropertyAccess = 40, + DotGet = 40, IfExpr = 41, ThenBlock = 44, ElsifExpr = 45, diff --git a/src/parser/shrimp.ts b/src/parser/shrimp.ts index d6f1fab..5826da6 100644 --- a/src/parser/shrimp.ts +++ b/src/parser/shrimp.ts @@ -8,7 +8,7 @@ export const parser = LRParser.deserialize({ states: ".dQVQaOOO#OQbO'#CdO#cQPO'#CeO#qQPO'#DkO$qQaO'#CcO$xOSO'#CsOOQ`'#Do'#DoO%WQPO'#DnO%oQaO'#DyOOQ`'#C{'#C{OOQO'#Dl'#DlO%wQPO'#DkO&VQaO'#EOOOQO'#DV'#DVOOQO'#Dk'#DkO&^QPO'#DjOOQ`'#Dj'#DjOOQ`'#D`'#D`QVQaOOOOQ`'#Dn'#DnOOQ`'#Cb'#CbO&fQaO'#DROOQ`'#Dm'#DmOOQ`'#Da'#DaO&sQbO,58{O'dQaO,59pO'iQaO,59yO&VQaO,59PO&VQaO,59PO'vQbO'#CdO)RQPO'#CeO)cQPO,58}O)tQPO,58}O)oQPO,58}O*oQPO,58}O*wQaO'#CuO+PQWO'#CvOOOO'#Ds'#DsOOOO'#Db'#DbO+eOSO,59_OOQ`,59_,59_OOQ`'#Dc'#DcO+sQaO'#C}O+{QPO,5:eO,QQaO'#DeO,VQPO,58zO,hQPO,5:jO,oQPO,5:jOOQ`,5:U,5:UOOQ`-E7^-E7^OOQ`,59m,59mOOQ`-E7_-E7_OOQO1G/[1G/[OOQO1G/e1G/eOOQO1G.k1G.kO,tQPO1G.kO&VQaO,59UO&VQaO,59UOOQ`1G.i1G.iOOOO,59a,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