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

Light Cleanup #61

Merged
merged 2 commits into from
Nov 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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