Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: allow numeric ranges in subscript range definitions #375

Merged
merged 7 commits into from
Oct 18, 2023
Prev Previous commit
Next Next commit
separate subscript lists from range definitions to match the parser
ToddFincannonEI committed Oct 18, 2023

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
commit d67fd6185d02755bbf283e14ac1129e91b7aa171
26 changes: 18 additions & 8 deletions packages/compile/src/model/subscript-range-reader.js
Original file line number Diff line number Diff line change
@@ -48,21 +48,31 @@ export default class SubscriptRangeReader extends ModelReader {
}
}
visitSubscriptList(ctx) {
// Get the subscripts from each element of the list, which can include both
// individual subscript indices and numeric ranges.
// Get the subscripts from each subscript index in the list.
for (let child of ctx.children) {
if (child.symbol?.type === ModelParser.Id) {
let subscript = child.getText()
if (ctx.parentCtx.ruleIndex === ModelParser.RULE_subscriptRange) {
this.indNames.push(subscript)
} else if (ctx.parentCtx.ruleIndex === ModelParser.RULE_subscriptMapping) {
this.mappingValue.push(subscript)
}
this.addSubscriptIndex(ctx, child)
}
}
}
visitSubscriptDefList(ctx) {
// Subscript range definitions can have indices and numeric subscript sequences.
for (let child of ctx.children) {
if (child.symbol?.type === ModelParser.Id) {
this.addSubscriptIndex(ctx, child)
} else if (child.ruleIndex === ModelParser.RULE_subscriptSequence) {
this.visitSubscriptSequence(child)
}
}
}
addSubscriptIndex(ctx, child) {
let subscript = child.getText()
if (ctx.parentCtx.ruleIndex === ModelParser.RULE_subscriptRange) {
this.indNames.push(subscript)
} else if (ctx.parentCtx.ruleIndex === ModelParser.RULE_subscriptMapping) {
this.mappingValue.push(subscript)
}
}
visitSubscriptMapping(ctx) {
let toDim = ctx.Id().getText()
// If a subscript list is part of the mapping, mappingValue will be set by visitSubscriptList.