Skip to content

Commit

Permalink
Cleanup (#61)
Browse files Browse the repository at this point in the history
  • Loading branch information
drew-y authored Nov 11, 2024
1 parent 66524f7 commit 54476e0
Show file tree
Hide file tree
Showing 9 changed files with 19 additions and 13 deletions.
4 changes: 2 additions & 2 deletions src/parser/lexer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ export const lexer = (chars: CharStream): Token => {
const consumeOperator = (chars: CharStream, token: Token) => {
while (isOpChar(chars.next)) {
if (token.value === ">" && (chars.next === ">" || chars.next === ":")) {
break; // Ugly hack to support generics, means >> is not a valid operator
break; // Ugly hack to support generics, means >> is not a valid operator. At least until we write a custom parser for the generics reader macro.
}

token.addChar(chars.consumeChar());
Expand All @@ -93,7 +93,7 @@ const nextIsNumber = (chars: CharStream) =>
(isDigitSign(chars.next) && isDigit(chars.at(1) ?? ""));

const consumeSpaces = (chars: CharStream, token: Token) => {
while (chars.next === " " && token.span < 2) {
while (chars.next === " " && token.length < 2) {
token.addChar(chars.consumeChar());
}
};
12 changes: 9 additions & 3 deletions src/parser/syntax-macros/functional-notation.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
import { idIs, isOp } from "../grammar.js";
import { Expr, List, ListValue } from "../../syntax-objects/index.js";

// Note: The current version of this function was modified by GPT o1.
// I wrote the original version an have made modifications to the version
// produced by o1. The intent was to have o1 improve the performance. But
// now I'm not sure the added complexity produced by o1 was worth the cost.
// Might still be worth re-writing again to something similar to the original.

export const functionalNotation = (list: List): List => {
const array = list.toArray();
let isTuple = false;
Expand Down Expand Up @@ -46,12 +52,12 @@ type Accumulator = { result: ListValue[]; skip: number };
const handleNextExpression = (
acc: Accumulator,
expr: Expr,
nextExpr: Expr,
nextExpr: List,
array: Expr[],
index: number
) => {
if ((nextExpr as List).calls("generics")) {
const generics = nextExpr as List;
if (nextExpr.calls("generics")) {
const generics = nextExpr;
const nextNextExpr = array[index + 2];
if (nextNextExpr && nextNextExpr.isList()) {
acc.result.push(processGenerics(expr, generics, nextNextExpr as List));
Expand Down
2 changes: 1 addition & 1 deletion src/parser/token.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export class Token {
this.location = location;
}

get span() {
get length() {
return this.value.length;
}

Expand Down
2 changes: 1 addition & 1 deletion src/semantics/resolution/resolve-entities.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Block } from "../../syntax-objects/block.js";
import { Expr } from "../../syntax-objects/expr.js";
import { nop } from "../../syntax-objects/helpers.js";
import { nop } from "../../syntax-objects/lib/helpers.js";
import { List } from "../../syntax-objects/list.js";
import { VoydModule } from "../../syntax-objects/module.js";
import { ObjectLiteral } from "../../syntax-objects/object-literal.js";
Expand Down
2 changes: 1 addition & 1 deletion src/semantics/resolution/resolve-impl.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { nop } from "../../syntax-objects/helpers.js";
import { nop } from "../../syntax-objects/lib/helpers.js";
import { Implementation } from "../../syntax-objects/implementation.js";
import { ObjectType, TypeAlias } from "../../syntax-objects/types.js";
import { getExprType } from "./get-expr-type.js";
Expand Down
2 changes: 1 addition & 1 deletion src/semantics/resolution/resolve-object-type.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Call } from "../../syntax-objects/call.js";
import { nop } from "../../syntax-objects/helpers.js";
import { nop } from "../../syntax-objects/lib/helpers.js";
import { List } from "../../syntax-objects/list.js";
import {
ObjectType,
Expand Down
2 changes: 1 addition & 1 deletion src/syntax-objects/implementation.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Expr } from "./expr.js";
import { Fn } from "./fn.js";
import { nop } from "./helpers.js";
import { nop } from "./lib/helpers.js";
import { Identifier } from "./identifier.js";
import { ChildList } from "./lib/child-list.js";
import { Child } from "./lib/child.js";
Expand Down
2 changes: 1 addition & 1 deletion src/syntax-objects/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ export * from "./syntax.js";
export * from "./bool.js";
export * from "./expr.js";
export * from "./float.js";
export * from "./helpers.js";
export * from "./lib/helpers.js";
export * from "./identifier.js";
export * from "./int.js";
export * from "./list.js";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Nop } from "./nop.js";
import { Whitespace } from "./whitespace.js";
import { Nop } from "../nop.js";
import { Whitespace } from "../whitespace.js";

export const newLine = () => new Whitespace({ value: "\n" });

Expand Down

0 comments on commit 54476e0

Please sign in to comment.