-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1eb6849
commit f3f539c
Showing
6 changed files
with
216 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import { Statement } from './statement' | ||
import { Pattern } from './match' | ||
|
||
export type AstNodeKind = | ||
'module' | ||
| 'var-def' | ||
| 'fn-def' | ||
| 'kind-def' | ||
| 'impl-def' | ||
| 'type-def' | ||
| 'return-stmt' | ||
| 'unary-expr' | ||
| 'binary-expr' | ||
|
||
export interface Module { | ||
type: 'module' | ||
statements: Statement[] | ||
} | ||
|
||
export interface Type { | ||
type: 'type' | ||
name: Identifier | ||
typeParams: Type[] | ||
} | ||
|
||
export type Identifier = string | ||
|
||
export interface Param { | ||
type: 'param' | ||
pattern: Pattern | ||
paramType?: Type | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
import { BinaryOp, UnaryOp } from './op' | ||
import { Identifier, Param, Type } from './ast' | ||
import { Block } from './statement' | ||
import { MatchExpr, Pattern } from './match' | ||
|
||
export type Expr = UnaryExpr | BinaryExpr | ||
|
||
export interface UnaryExpr { | ||
type: 'unary-expr' | ||
unaryOp: UnaryOp | ||
operand: Operand | ||
} | ||
|
||
export interface BinaryExpr { | ||
type: 'binary-expr' | ||
binaryOp: BinaryOp | ||
lOperand: Operand | ||
rOperand: Operand | ||
} | ||
|
||
export type Operand = | ||
IfExpr | ||
| WhileExpr | ||
| ForExpr | ||
| MatchExpr | ||
| ClosureExpr | ||
| Expr | ||
| ListExpr | ||
| StringLiteral | ||
| CharLiteral | ||
| IntLiteral | ||
| FloatLiteral | ||
| Identifier | ||
|
||
export interface IfExpr { | ||
type: 'if-expr' | ||
condition: Expr | ||
thenBlock: Block | ||
elseBlock?: Block | ||
} | ||
|
||
export interface WhileExpr { | ||
type: 'while-expr' | ||
condition: Expr | ||
block: Block | ||
} | ||
|
||
export interface ForExpr { | ||
type: 'for-expr' | ||
pattern: Pattern | ||
expr: Expr | ||
block: Block | ||
} | ||
|
||
export interface ClosureExpr { | ||
type: 'closure-expr' | ||
name: Identifier | ||
typeParams: Type[] | ||
params: Param[] | ||
block: Block | ||
returnType?: Type | ||
} | ||
|
||
export interface ListExpr { | ||
type: 'list-expr' | ||
exprs: Expr[] | ||
} | ||
|
||
export interface StringLiteral { | ||
type: 'string-literal' | ||
value: string | ||
} | ||
|
||
export interface CharLiteral { | ||
type: 'char-literal' | ||
value: string | ||
} | ||
|
||
export interface IntLiteral { | ||
type: 'int-literal' | ||
value: string | ||
} | ||
|
||
export interface FloatLiteral { | ||
type: 'float-literal' | ||
value: string | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import { Expr } from './expr' | ||
import { Block } from './statement' | ||
|
||
export type Pattern = ConPattern | Expr | Hole | ||
|
||
export interface ConPattern { | ||
type: 'con-pattern' | ||
// TODO | ||
} | ||
|
||
export interface Hole { | ||
type: 'hole' | ||
} | ||
|
||
export interface MatchExpr { | ||
type: 'match-expr' | ||
expr: Expr | ||
clauses: MatchClause | ||
} | ||
|
||
export interface MatchClause { | ||
type: 'match-clause' | ||
pattern: Pattern | ||
block: Block | ||
guard?: Expr | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
export type UnaryOp = 'todo' | ||
|
||
export type BinaryOp = 'todo' | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import { Identifier, Param, Type } from './ast' | ||
import { TypeDef } from './type-def' | ||
import { Expr } from './expr' | ||
import { Pattern } from './match' | ||
|
||
export type Statement = VarDef | FnDef | KindDef | ImplDef | TypeDef | ReturnStmt | Expr | ||
|
||
export interface VarDef { | ||
type: 'var-def' | ||
pattern: Pattern | ||
varType: Type | ||
expr: Expr | ||
} | ||
|
||
export interface FnDef { | ||
type: 'fn-def' | ||
name: Identifier | ||
typeParams: Type[] | ||
params: Param[] | ||
block?: Block | ||
returnType?: Type | ||
} | ||
|
||
export interface KindDef { | ||
type: 'kind-def' | ||
name: Identifier | ||
kindParams: Type[] | ||
block: Block | ||
} | ||
|
||
export interface ImplDef { | ||
type: 'impl-def' | ||
name: Identifier | ||
implParams: Type[] | ||
forKind?: Type | ||
block: Block | ||
} | ||
|
||
export interface ReturnStmt { | ||
type: 'return-stmt' | ||
} | ||
|
||
export interface Block { | ||
type: 'block' | ||
statements: Statement[] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { Identifier, Param, Type } from './ast' | ||
|
||
export interface TypeDef { | ||
type: 'type-def' | ||
name: Identifier | ||
typeParams: Param[] | ||
variants: TypeCon[] | ||
} | ||
|
||
export interface TypeCon { | ||
type: 'type-con' | ||
fieldDefs: FieldDef[] | ||
} | ||
|
||
export interface FieldDef { | ||
type: 'field-def' | ||
name: Identifier | ||
fieldType: Type | ||
} | ||
|