Skip to content

Commit

Permalink
Use attributes
Browse files Browse the repository at this point in the history
  • Loading branch information
drew-y committed Sep 13, 2024
1 parent 1170473 commit e5649b8
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 9 deletions.
2 changes: 1 addition & 1 deletion src/parser/parse-chars.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export const parseChars = (

if (token.is("(")) {
const subList = parseChars(file, { nested: true });
subList.mayBeTuple = true;
subList.setAttribute("tuple?", true);
list.push(subList);
continue;
}
Expand Down
8 changes: 4 additions & 4 deletions src/parser/syntax-macros/functional-notation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export const functionalNotation = (list: List): List => {
return handleNextExpression(acc, expr, nextExpr, array, index);
}

if (list.mayBeTuple && idIs(expr, ",")) {
if (list.getAttribute("tuple?") && idIs(expr, ",")) {
isTuple = true;
}

Expand Down Expand Up @@ -76,12 +76,12 @@ const finalizeResult = (result: ListValue[], isTuple: boolean): List => {
};

const processGenerics = (expr: Expr, generics: List, params?: List): List => {
generics.mayBeTuple = false;
generics.setAttribute("tuple?", false);

const list = params || new List([]);
list.insert(expr);
list.insert(",", 1);
list.mayBeTuple = false;
list.setAttribute("tuple?", false);
const functional = functionalNotation(list);

functional.insert(functionalNotation(generics), 2);
Expand All @@ -92,6 +92,6 @@ const processGenerics = (expr: Expr, generics: List, params?: List): List => {
const processParamList = (expr: Expr, params: List): List => {
params.insert(expr);
params.insert(",", 1);
params.mayBeTuple = false;
params.setAttribute("tuple?", false);
return functionalNotation(params);
};
4 changes: 0 additions & 4 deletions src/syntax-objects/list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,12 @@ type ListOpts =

export class List extends Syntax {
readonly syntaxType = "list";
/** True when the list was defined by the user using parenthesis i.e. (hey, there) */
mayBeTuple?: boolean;
#store = new ChildList(undefined, this);

constructor(opts: ListOpts) {
opts = Array.isArray(opts) ? { value: opts } : opts;
super(opts);
const value = opts.value;
this.mayBeTuple = opts.isParentheticalList;

if (!value || value instanceof Array) {
this.push(...(value ?? []));
Expand Down Expand Up @@ -213,7 +210,6 @@ export class List extends Syntax {
return new List({
...super.getCloneOpts(parent),
value: this.#store.toClonedArray(),
isParentheticalList: this.mayBeTuple,
});
}
}
Expand Down

0 comments on commit e5649b8

Please sign in to comment.