dot-get #1

Merged
probablycorey merged 19 commits from dot-get into main 2025-10-19 17:26:55 +00:00
5 changed files with 12 additions and 21 deletions
Showing only changes of commit 22fba65a53 - Show all commits

@ -1 +1 @@
Subproject commit 0844e99d2d04fb9ba0999f25248a17430bdc5ee6
Subproject commit 1a18a713d7ae86b03a6bef38cc53d12ecfbf9627

View File

@ -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<string>
) {}
constructor(public parent: Scope | null, public vars: Set<string>) {}
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<Scope>({
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<Scope>({
}
// 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(),
})

View File

@ -62,7 +62,7 @@ item {
consumeToTerminator {
PipeExpr |
ambiguousFunctionCall |
PropertyAccess |
DotGet |
IfExpr |
FunctionDef |
Assign |
@ -158,7 +158,7 @@ Assign {
Identifier "=" consumeToTerminator
}
PropertyAccess {
DotGet {
Identifier "." Identifier
}

View File

@ -25,7 +25,7 @@ export const
Underscore = 36,
NamedArg = 37,
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~P$YO!o!tO~OPPOpWOz[Os!pX!O!pX!Q!pX~P$YOs!vO~Os!{O!O!wO!Q!zO~Os#QO!O!wO!Q!zO~Or#SO~Os#QO~Or#TO~P(gOr#TO~Os#UO~O!o#VO~O!o#WO~Ok]mZm~",
goto: "+Z!tPPPP!u#U#d#j#U$VPPPP$lPPPPPPPP$xP%b%bPPPP%fP%{PPP#dPP&O&OP&[&_&hP&lP&O&r&x'Q'W'^'g'nPPP't'x(^(p(v)rPPP*`PPPPP*d*dP*uP*}*}d^Obj!b!f!j!m!p#V#WRqSiYOSbj|!b!f!j!m!p#V#WXfPhm!c|UOPS[behjklm!Y!Z!b!c!f!j!m!p!w#V#WR!]sdRObj!b!f!j!m!p#V#WQoSQ!WkR!XlQqSQ!P[Q!g!ZR#O!w}UOPS[behjklm!Y!Z!b!c!f!j!m!p!w#V#WTuTwd^Obj!b!f!j!m!p#V#WWdPhm!cR!SeR{We^Obj!b!f!j!m!p#V#WR!l!fQ!s!mQ#X#VR#Y#WT!x!s!yQ!|!sR#R!yQbOR!RbUhPm!cR!ThQwTR!_wQzWR!azW!p!j!m#V#WR!u!pS}ZrR!e}Q!y!sR#P!yTaObS_ObQ!VjQ!i!bQ!k!fZ!o!j!m!p#V#WdZObj!b!f!j!m!p#V#WQrSR!d|XgPhm!cdQObj!b!f!j!m!p#V#WWdPhm!cQnSQ!O[Q!SeQ!WkQ!XlQ!g!YQ!h!ZR!}!wdVObj!b!f!j!m!p#V#WfcP[ehklm!Y!Z!c!wRpSTvTwoXOPbehjm!b!c!f!j!m!p#V#WQ!q!jV!r!m#V#We]Obj!b!f!j!m!p#V#W",
nodeNames: "⚠ Identifier Word Program PipeExpr FunctionCall PositionalArg ParenExpr FunctionCallOrIdentifier BinOp operator operator operator operator ConditionalOp operator operator operator operator operator operator operator operator String StringFragment Interpolation EscapeSeq Number Boolean Regex Null FunctionDef keyword Params colon end Underscore NamedArg NamedArgPrefix operator PropertyAccess IfExpr keyword ThenBlock ThenBlock ElsifExpr keyword ElseExpr keyword Assign",
nodeNames: "⚠ Identifier Word Program PipeExpr FunctionCall PositionalArg ParenExpr FunctionCallOrIdentifier BinOp operator operator operator operator ConditionalOp operator operator operator operator operator operator operator operator String StringFragment Interpolation EscapeSeq Number Boolean Regex Null FunctionDef keyword Params colon end Underscore NamedArg NamedArgPrefix operator DotGet IfExpr keyword ThenBlock ThenBlock ElsifExpr keyword ElseExpr keyword Assign",
maxTerm: 82,
context: trackScope,
nodeProps: [