-
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
Showing
31 changed files
with
663 additions
and
754 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,16 @@ | ||
import { Parser } from "../parser"; | ||
import { Source, SourceKind } from "./Source"; | ||
|
||
export class Program { | ||
public sources: Source[]; | ||
public entry!: Source; | ||
constructor(sources: Source[]) { | ||
this.sources = sources; | ||
const entrySource = this.sources.filter(v => v.sourceKind == SourceKind.UserEntry); | ||
if (entrySource.length > 1) throw new Error("Cannot have more than two entry files!"); | ||
for (const source of this.sources) { | ||
if (source.sourceKind === SourceKind.UserEntry) this.entry = source; | ||
source.parser = new Parser(source, this); | ||
} | ||
} | ||
} |
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 |
---|---|---|
@@ -1,18 +1,38 @@ | ||
import { Scope } from "../checker/scope/Scope.js"; | ||
import { Parser } from "../parser/index.js"; | ||
import { Tokenizer } from "../tokenizer/index.js"; | ||
import { Declaration } from "./nodes/DoStatement.js"; | ||
import { NodeKind } from "./nodes/Node.js"; | ||
import { Statement } from "./nodes/Statement.js"; | ||
|
||
export class Source { | ||
public kind = NodeKind.Source; | ||
public sourceKind: SourceKind; | ||
public fileName: string; | ||
public tokenizer: Tokenizer; | ||
public parser!: Parser; | ||
|
||
public topLevelStatements: Statement[] = []; | ||
public statements: Statement[] = []; | ||
public globalScope: Scope = new Scope(); | ||
constructor( | ||
public name: string, | ||
statements: Statement[] | null = null, | ||
topLevelStatements: Statement[] | null = null, | ||
fileName: string, | ||
text: string, | ||
sourceKind: SourceKind | ||
) { | ||
if (statements) this.statements = statements; | ||
this.fileName = fileName; | ||
this.tokenizer = new Tokenizer(text); | ||
this.sourceKind = sourceKind; | ||
} | ||
parse(): Source { | ||
this.parser.parseSource(); | ||
return this; | ||
} | ||
} | ||
|
||
export enum SourceKind { | ||
User = 1, | ||
UserEntry = 2, | ||
Library = 3, | ||
LibraryEntry = 4 | ||
} |
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
5 changes: 2 additions & 3 deletions
5
src/ast/nodes/BlockExpression.ts → src/ast/nodes/BlockStatement.ts
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
Empty file.
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 |
---|---|---|
@@ -1,16 +1,8 @@ | ||
import { Range } from "../Range"; | ||
import { BlockExpression } from "./BlockExpression"; | ||
import { Expression } from "./Expression.js"; | ||
import { Statement } from "./Statement.js"; | ||
import { EnumDeclaration } from "./EnumDeclaration"; | ||
import { FunctionDeclaration } from "./FunctionDeclaration"; | ||
import { FunctionImportDeclaration } from "./FunctionImportDeclaration"; | ||
import { ImportDeclaration } from "./ImportDeclaration"; | ||
import { ImportFromDeclaration } from "./ImportFromDeclaration"; | ||
import { VariableDeclaration } from "./VariableDeclaration"; | ||
|
||
export class DoStatement extends Statement { | ||
public nameOf: string = "DoStatement"; | ||
public condition: Expression; | ||
public block: BlockExpression; | ||
constructor(condition: Expression, block: BlockExpression, range: Range) { | ||
super(); | ||
this.condition = condition; | ||
this.block = block; | ||
this.range = range; | ||
} | ||
} | ||
export type Declaration = FunctionDeclaration | FunctionImportDeclaration | VariableDeclaration | ImportDeclaration | ImportFromDeclaration | EnumDeclaration; |
2 changes: 1 addition & 1 deletion
2
src/ast/nodes/Function.ts → src/ast/nodes/FunctionDeclaration.ts
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
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
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 |
---|---|---|
@@ -1,16 +1,25 @@ | ||
import { Range } from "../Range"; | ||
import { Node } from "./Node"; | ||
import { Expression } from "./Expression.js"; | ||
import { Statement } from "./Statement.js"; | ||
|
||
export class IfStatement extends Statement { | ||
public nameOf: string = "IfStatement"; | ||
public condition: Expression; | ||
public body: Node; | ||
constructor(condition: Expression, block: Node, range: Range) { | ||
public condition: Expression | null; | ||
public ifTrue: Statement; | ||
public ifFalse: Statement | null; | ||
public kind: IfStatementKind; | ||
constructor(condition: Expression | null, ifTrue: Statement, ifFalse: Statement | null, kind: IfStatementKind, range: Range) { | ||
super(); | ||
this.condition = condition; | ||
this.body = block; | ||
this.ifTrue = ifTrue; | ||
this.ifFalse = ifFalse; | ||
this.kind = kind; | ||
this.range = range; | ||
} | ||
} | ||
|
||
export enum IfStatementKind { | ||
If = 0, | ||
ElseIf = 1, | ||
Else = 2 | ||
} |
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 |
---|---|---|
@@ -1,13 +1,13 @@ | ||
import { Range } from "../Range.js"; | ||
import { Identifier } from "./Identifier.js"; | ||
import { Statement } from "./Statement.js"; | ||
import { StringLiteral } from "./StringLiteral.js"; | ||
|
||
export class ImportDeclaration extends Statement { | ||
public nameOf: string = "ImportDeclaration"; | ||
public path: Identifier; | ||
constructor(path: Identifier, range: Range) { | ||
super(); | ||
this.path = path; | ||
this.range = range; | ||
} | ||
public nameOf: string = "ImportDeclaration"; | ||
public path: StringLiteral; | ||
constructor(path: StringLiteral, range: Range) { | ||
super(); | ||
this.path = path; | ||
this.range = range; | ||
} | ||
} |
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,16 @@ | ||
import { Range } from "../Range.js"; | ||
import { Identifier } from "./Identifier.js"; | ||
import { Statement } from "./Statement.js"; | ||
import { StringLiteral } from "./StringLiteral.js"; | ||
|
||
export class ImportFromDeclaration extends Statement { | ||
public nameOf: string = "ImportFromDeclaration"; | ||
public value: Identifier// | ObjectLiteral | ArrayLiteral; | ||
public path: StringLiteral; | ||
constructor(value: Identifier, path: StringLiteral, range: Range) { | ||
super(); | ||
this.value = value; | ||
this.path = path; | ||
this.range = range; | ||
} | ||
} |
File renamed without changes.
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
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
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
Oops, something went wrong.