Minor changes
- Refactor Constructor to IdentifierAlt - Make () -> a unify with a
This commit is contained in:
parent
666256ed15
commit
20af138fa5
4 changed files with 27 additions and 18 deletions
|
@ -9,7 +9,7 @@ import {
|
|||
} from "./cst";
|
||||
import { ArityMismatchDiagnostic, BindingNotFoudDiagnostic, Diagnostics, UnificationFailedDiagnostic } from "./diagnostics";
|
||||
import { assert } from "./util";
|
||||
import { LabeledDirectedHashGraph, LabeledGraph, strongconnect, toposort } from "yagl"
|
||||
import { LabeledDirectedHashGraph, LabeledGraph, strongconnect } from "yagl"
|
||||
|
||||
export enum TypeKind {
|
||||
Arrow,
|
||||
|
@ -1001,6 +1001,14 @@ export class Checker {
|
|||
return success;
|
||||
}
|
||||
|
||||
if (left.kind === TypeKind.Arrow && left.paramTypes.length === 0) {
|
||||
return this.unify(left.returnType, right, solution);
|
||||
}
|
||||
|
||||
if (right.kind === TypeKind.Arrow) {
|
||||
return this.unify(right, left, solution);
|
||||
}
|
||||
|
||||
if (left.kind === TypeKind.Con && right.kind === TypeKind.Con) {
|
||||
if (left.id !== right.id) {
|
||||
return false;
|
||||
|
|
19
src/cst.ts
19
src/cst.ts
|
@ -69,7 +69,7 @@ export const enum SyntaxKind {
|
|||
|
||||
// Tokens
|
||||
Identifier,
|
||||
Constructor,
|
||||
IdentifierAlt,
|
||||
CustomOperator,
|
||||
Assignment,
|
||||
LParen,
|
||||
|
@ -207,6 +207,7 @@ export class Scope {
|
|||
if (isNodeWithScope(curr)) {
|
||||
return curr.getScope();
|
||||
}
|
||||
curr = curr.parent;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
@ -502,9 +503,9 @@ export class StringLiteral extends TokenBase {
|
|||
|
||||
}
|
||||
|
||||
export class Constructor extends TokenBase {
|
||||
export class IdentifierAlt extends TokenBase {
|
||||
|
||||
public readonly kind = SyntaxKind.Constructor;
|
||||
public readonly kind = SyntaxKind.IdentifierAlt;
|
||||
|
||||
public constructor(
|
||||
public text: string,
|
||||
|
@ -792,7 +793,7 @@ export type Token
|
|||
| LBracket
|
||||
| RBracket
|
||||
| Identifier
|
||||
| Constructor
|
||||
| IdentifierAlt
|
||||
| CustomOperator
|
||||
| Integer
|
||||
| StringLiteral
|
||||
|
@ -828,7 +829,7 @@ export class ReferenceTypeExpression extends SyntaxBase {
|
|||
|
||||
public constructor(
|
||||
public modulePath: Array<[Identifier, Dot]>,
|
||||
public name: Identifier,
|
||||
public name: IdentifierAlt,
|
||||
) {
|
||||
super();
|
||||
}
|
||||
|
@ -900,7 +901,7 @@ export class NamedTuplePattern extends SyntaxBase {
|
|||
public readonly kind = SyntaxKind.NamedTuplePattern;
|
||||
|
||||
public constructor(
|
||||
public name: Constructor,
|
||||
public name: IdentifierAlt,
|
||||
public elements: Pattern[],
|
||||
) {
|
||||
super();
|
||||
|
@ -995,7 +996,7 @@ export class StructPattern extends SyntaxBase {
|
|||
public readonly kind = SyntaxKind.StructPattern;
|
||||
|
||||
public constructor(
|
||||
public name: Constructor,
|
||||
public name: IdentifierAlt,
|
||||
public lbrace: LBrace,
|
||||
public elements: StructPatternElement[],
|
||||
public rbrace: RBrace,
|
||||
|
@ -1205,7 +1206,7 @@ export class StructExpression extends SyntaxBase {
|
|||
public readonly kind = SyntaxKind.StructExpression;
|
||||
|
||||
public constructor(
|
||||
public name: Constructor,
|
||||
public name: IdentifierAlt,
|
||||
public lbrace: LBrace,
|
||||
public elements: StructExpressionElement[],
|
||||
public rbrace: RBrace,
|
||||
|
@ -1228,7 +1229,7 @@ export class NamedTupleExpression extends SyntaxBase {
|
|||
public readonly kind = SyntaxKind.NamedTupleExpression;
|
||||
|
||||
public constructor(
|
||||
public name: Constructor,
|
||||
public name: IdentifierAlt,
|
||||
public elements: Expression[],
|
||||
) {
|
||||
super();
|
||||
|
|
|
@ -156,17 +156,17 @@ export class Parser {
|
|||
}
|
||||
|
||||
public parseReferenceTypeExpression(): ReferenceTypeExpression {
|
||||
const name = this.expectToken(SyntaxKind.Identifier);
|
||||
const name = this.expectToken(SyntaxKind.IdentifierAlt);
|
||||
return new ReferenceTypeExpression([], name);
|
||||
}
|
||||
|
||||
public parseTypeExpression(): TypeExpression {
|
||||
const t0 = this.peekToken();
|
||||
switch (t0.kind) {
|
||||
case SyntaxKind.Identifier:
|
||||
case SyntaxKind.IdentifierAlt:
|
||||
return this.parseReferenceTypeExpression();
|
||||
default:
|
||||
this.raiseParseError(t0, [ SyntaxKind.Identifier ]);
|
||||
this.raiseParseError(t0, [ SyntaxKind.IdentifierAlt ]);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -218,7 +218,7 @@ export class Parser {
|
|||
return this.parseExpressionWithParens();
|
||||
case SyntaxKind.Identifier:
|
||||
return this.parseReferenceExpression();
|
||||
case SyntaxKind.Constructor:
|
||||
case SyntaxKind.IdentifierAlt:
|
||||
{
|
||||
this.getToken();
|
||||
const t1 = this.peekToken();
|
||||
|
@ -384,7 +384,7 @@ export class Parser {
|
|||
}
|
||||
|
||||
private parsePatternStartingWithConstructor() {
|
||||
const name = this.expectToken(SyntaxKind.Constructor);
|
||||
const name = this.expectToken(SyntaxKind.IdentifierAlt);
|
||||
const t2 = this.peekToken();
|
||||
if (t2.kind === SyntaxKind.LBrace) {
|
||||
this.getToken();
|
||||
|
@ -467,7 +467,7 @@ export class Parser {
|
|||
{
|
||||
this.getToken();
|
||||
const t1 = this.peekToken();
|
||||
if (t1.kind === SyntaxKind.Constructor) {
|
||||
if (t1.kind === SyntaxKind.IdentifierAlt) {
|
||||
return this.parsePatternStartingWithConstructor();
|
||||
} else {
|
||||
return this.parseTuplePattern();
|
||||
|
|
|
@ -25,7 +25,7 @@ import {
|
|||
RBracket,
|
||||
ReturnKeyword,
|
||||
CustomOperator,
|
||||
Constructor,
|
||||
IdentifierAlt,
|
||||
Integer,
|
||||
TextFile,
|
||||
Dot,
|
||||
|
@ -353,7 +353,7 @@ export class Scanner extends BufferedStream<Token> {
|
|||
case 'elif': return new ElifKeyword(startPos);
|
||||
default:
|
||||
if (isUpper(text[0])) {
|
||||
return new Constructor(text, startPos);
|
||||
return new IdentifierAlt(text, startPos);
|
||||
} else {
|
||||
return new Identifier(text, startPos);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue