mirror of
https://github.com/Noratrieb/riverdelta.git
synced 2026-01-16 17:35:02 +01:00
some cleanup
This commit is contained in:
parent
5c6ade6cbb
commit
000f17b97e
6 changed files with 22 additions and 30 deletions
|
|
@ -3,7 +3,7 @@
|
||||||
exports[`should tokenize an emtpy function 1`] = `
|
exports[`should tokenize an emtpy function 1`] = `
|
||||||
[
|
[
|
||||||
{
|
{
|
||||||
"kind": "kw_function",
|
"kind": "function",
|
||||||
"span": {
|
"span": {
|
||||||
"end": 8,
|
"end": 8,
|
||||||
"start": 0,
|
"start": 0,
|
||||||
|
|
@ -18,31 +18,31 @@ exports[`should tokenize an emtpy function 1`] = `
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"kind": "p_popen",
|
"kind": "(",
|
||||||
"span": {
|
"span": {
|
||||||
"end": 15,
|
"end": 15,
|
||||||
"start": 14,
|
"start": 14,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"kind": "p_pclose",
|
"kind": ")",
|
||||||
"span": {
|
"span": {
|
||||||
"end": 16,
|
"end": 16,
|
||||||
"start": 15,
|
"start": 15,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"kind": "p_bopen",
|
"kind": "=",
|
||||||
"span": {
|
"span": {
|
||||||
"end": 18,
|
"end": 18,
|
||||||
"start": 17,
|
"start": 17,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"kind": "p_bclose",
|
"kind": ";",
|
||||||
"span": {
|
"span": {
|
||||||
"end": 19,
|
"end": 20,
|
||||||
"start": 18,
|
"start": 19,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
]
|
]
|
||||||
|
|
@ -59,7 +59,7 @@ exports[`should tokenize hello world 1`] = `
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"kind": "p_popen",
|
"kind": "(",
|
||||||
"span": {
|
"span": {
|
||||||
"end": 6,
|
"end": 6,
|
||||||
"start": 5,
|
"start": 5,
|
||||||
|
|
@ -74,7 +74,7 @@ exports[`should tokenize hello world 1`] = `
|
||||||
"value": "hello world",
|
"value": "hello world",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"kind": "p_pclose",
|
"kind": ")",
|
||||||
"span": {
|
"span": {
|
||||||
"end": 20,
|
"end": 20,
|
||||||
"start": 19,
|
"start": 19,
|
||||||
|
|
|
||||||
12
src/ast.ts
12
src/ast.ts
|
|
@ -266,16 +266,16 @@ export type Folder = {
|
||||||
|
|
||||||
export const DEFAULT_FOLDER: Folder = {
|
export const DEFAULT_FOLDER: Folder = {
|
||||||
item(item) {
|
item(item) {
|
||||||
return super_fold_item(item, this);
|
return superFoldItem(item, this);
|
||||||
},
|
},
|
||||||
expr(expr) {
|
expr(expr) {
|
||||||
return super_fold_expr(expr, this);
|
return superFoldExpr(expr, this);
|
||||||
},
|
},
|
||||||
ident(ident) {
|
ident(ident) {
|
||||||
return ident;
|
return ident;
|
||||||
},
|
},
|
||||||
type(type) {
|
type(type) {
|
||||||
return super_fold_type(type, this);
|
return superFoldType(type, this);
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -283,7 +283,7 @@ export function fold_ast(ast: Ast, folder: Folder): Ast {
|
||||||
return ast.map((item) => folder.item(item));
|
return ast.map((item) => folder.item(item));
|
||||||
}
|
}
|
||||||
|
|
||||||
export function super_fold_item(item: Item, folder: Folder): Item {
|
export function superFoldItem(item: Item, folder: Folder): Item {
|
||||||
switch (item.kind) {
|
switch (item.kind) {
|
||||||
case "function": {
|
case "function": {
|
||||||
const args = item.node.args.map(({ name, type, span }) => ({
|
const args = item.node.args.map(({ name, type, span }) => ({
|
||||||
|
|
@ -307,7 +307,7 @@ export function super_fold_item(item: Item, folder: Folder): Item {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export function super_fold_expr(expr: Expr, folder: Folder): Expr {
|
export function superFoldExpr(expr: Expr, folder: Folder): Expr {
|
||||||
const span = expr.span;
|
const span = expr.span;
|
||||||
switch (expr.kind) {
|
switch (expr.kind) {
|
||||||
case "empty": {
|
case "empty": {
|
||||||
|
|
@ -373,7 +373,7 @@ export function super_fold_expr(expr: Expr, folder: Folder): Expr {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export function super_fold_type(type: Type, folder: Folder): Type {
|
export function superFoldType(type: Type, folder: Folder): Type {
|
||||||
const span = type.span;
|
const span = type.span;
|
||||||
switch (type.kind) {
|
switch (type.kind) {
|
||||||
case "ident": {
|
case "ident": {
|
||||||
|
|
|
||||||
|
|
@ -7,11 +7,7 @@ import { typeck } from "./typeck";
|
||||||
|
|
||||||
const input = `
|
const input = `
|
||||||
function main() = (
|
function main() = (
|
||||||
let a = 0 in
|
let true = false in print(true)
|
||||||
let b = a in
|
|
||||||
let c = b in
|
|
||||||
let d = c in
|
|
||||||
d;
|
|
||||||
);
|
);
|
||||||
`;
|
`;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
import { tokenize } from "./lexer";
|
import { tokenize } from "./lexer";
|
||||||
|
|
||||||
it("should tokenize an emtpy function", () => {
|
it("should tokenize an emtpy function", () => {
|
||||||
const input = `function hello() = {}`;
|
const input = `function hello() = ;`;
|
||||||
|
|
||||||
const tokens = tokenize(input);
|
const tokens = tokenize(input);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -5,8 +5,8 @@ import {
|
||||||
Identifier,
|
Identifier,
|
||||||
Resolution,
|
Resolution,
|
||||||
fold_ast,
|
fold_ast,
|
||||||
super_fold_expr,
|
superFoldExpr,
|
||||||
super_fold_item,
|
superFoldItem,
|
||||||
} from "./ast";
|
} from "./ast";
|
||||||
import { CompilerError } from "./error";
|
import { CompilerError } from "./error";
|
||||||
|
|
||||||
|
|
@ -87,7 +87,7 @@ export function resolve(ast: Ast): Ast {
|
||||||
item.node.returnType && this.type(item.node.returnType);
|
item.node.returnType && this.type(item.node.returnType);
|
||||||
|
|
||||||
item.node.args.forEach(({ name }) => scopes.push(name));
|
item.node.args.forEach(({ name }) => scopes.push(name));
|
||||||
const body = super_fold_expr(item.node.body, this);
|
const body = superFoldExpr(item.node.body, this);
|
||||||
item.node.args.forEach(({ name }) => popScope(name));
|
item.node.args.forEach(({ name }) => popScope(name));
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
|
@ -104,7 +104,7 @@ export function resolve(ast: Ast): Ast {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return super_fold_item(item, this);
|
return superFoldItem(item, this);
|
||||||
},
|
},
|
||||||
expr(expr) {
|
expr(expr) {
|
||||||
if (expr.kind === "let") {
|
if (expr.kind === "let") {
|
||||||
|
|
@ -124,7 +124,7 @@ export function resolve(ast: Ast): Ast {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
return super_fold_expr(expr, this);
|
return superFoldExpr(expr, this);
|
||||||
},
|
},
|
||||||
ident(ident) {
|
ident(ident) {
|
||||||
const res = resolveIdent(ident);
|
const res = resolveIdent(ident);
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,3 @@
|
||||||
import { check } from "prettier";
|
|
||||||
import {
|
import {
|
||||||
Ast,
|
Ast,
|
||||||
COMPARISON_KINDS,
|
COMPARISON_KINDS,
|
||||||
|
|
@ -6,7 +5,6 @@ import {
|
||||||
EQUALITY_KINDS,
|
EQUALITY_KINDS,
|
||||||
Expr,
|
Expr,
|
||||||
ExprBinary,
|
ExprBinary,
|
||||||
ExprCall,
|
|
||||||
ExprUnary,
|
ExprUnary,
|
||||||
Folder,
|
Folder,
|
||||||
Identifier,
|
Identifier,
|
||||||
|
|
@ -14,11 +12,9 @@ import {
|
||||||
Resolution,
|
Resolution,
|
||||||
Ty,
|
Ty,
|
||||||
TyFn,
|
TyFn,
|
||||||
TyVar,
|
|
||||||
Type,
|
Type,
|
||||||
binaryExprPrecedenceClass,
|
binaryExprPrecedenceClass,
|
||||||
fold_ast,
|
fold_ast,
|
||||||
super_fold_expr,
|
|
||||||
} from "./ast";
|
} from "./ast";
|
||||||
import { CompilerError, Span } from "./error";
|
import { CompilerError, Span } from "./error";
|
||||||
import { printTy } from "./printer";
|
import { printTy } from "./printer";
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue