mirror of
https://github.com/fluencelabs/assemblyscript
synced 2025-06-12 06:21:29 +00:00
AST cleanup; Definition generators scaffolding
This commit is contained in:
@ -427,7 +427,6 @@
|
||||
(local $6 i32)
|
||||
(local $7 i32)
|
||||
(local $8 i32)
|
||||
(local $9 i32)
|
||||
(if
|
||||
(i32.eqz
|
||||
(i32.ne
|
||||
@ -493,14 +492,14 @@
|
||||
)
|
||||
)
|
||||
(block $break|0
|
||||
(set_local $9
|
||||
(set_local $5
|
||||
(get_local $7)
|
||||
)
|
||||
(loop $continue|0
|
||||
(if
|
||||
(i32.le_s
|
||||
(i32.add
|
||||
(get_local $9)
|
||||
(get_local $5)
|
||||
(get_local $8)
|
||||
)
|
||||
(get_local $4)
|
||||
@ -516,7 +515,7 @@
|
||||
(i32.const 4)
|
||||
)
|
||||
(i32.shl
|
||||
(get_local $9)
|
||||
(get_local $5)
|
||||
(i32.const 1)
|
||||
)
|
||||
)
|
||||
@ -531,13 +530,13 @@
|
||||
)
|
||||
)
|
||||
(return
|
||||
(get_local $9)
|
||||
(get_local $5)
|
||||
)
|
||||
)
|
||||
)
|
||||
(set_local $9
|
||||
(set_local $5
|
||||
(i32.add
|
||||
(get_local $9)
|
||||
(get_local $5)
|
||||
(i32.const 1)
|
||||
)
|
||||
)
|
||||
|
@ -21,10 +21,10 @@ glob.sync(filter, { cwd: __dirname + "/parser" }).forEach(filename => {
|
||||
|
||||
var failed = false;
|
||||
var parser = new Parser();
|
||||
var sourceText = fs.readFileSync(__dirname + "/parser/" + filename, { encoding: "utf8" }).replace(/\r?\n/g, "\n").replace(/^\/\/.*\r?\n/mg, "");
|
||||
var sourceText = fs.readFileSync(__dirname + "/parser/" + filename, { encoding: "utf8" }).replace(/\r?\n/g, "\n");
|
||||
parser.parseFile(sourceText, filename, true);
|
||||
var serializedSourceText = ASTBuilder.build(parser.program.sources[0]);
|
||||
var actual = serializedSourceText + parser.diagnostics.map(diagnostic => "// " + diagnostic + "\n").join("");
|
||||
var actual = serializedSourceText + parser.diagnostics.map(diagnostic => "// " + diagnostic +"\n").join("");
|
||||
var fixture = filename + ".fixture.ts";
|
||||
|
||||
if (isCreate) {
|
||||
|
@ -1,13 +1,27 @@
|
||||
export class Test<T> {
|
||||
instanceFunction(): void {
|
||||
}
|
||||
static staticFunction(): void {
|
||||
}
|
||||
get instanceGetter(): i32 {
|
||||
return 0;
|
||||
}
|
||||
static set staticSetter(v: i32) {
|
||||
}
|
||||
export class Valid<T> {
|
||||
constructor() {}
|
||||
instanceFunction(): void {}
|
||||
static staticFunction(): void {}
|
||||
get instanceGetter(): i32 {}
|
||||
static set staticSetter(v: i32) {}
|
||||
instanceField: i32;
|
||||
static staticField: i32;
|
||||
}
|
||||
export class Invalid<T> {
|
||||
|
||||
// 1092: Type parameters cannot appear on a constructor declaration
|
||||
constructor<T>() {}
|
||||
|
||||
// 1110: Type expected.
|
||||
instanceFunction() {}
|
||||
|
||||
// 1094: An accessor cannot have type parameters.
|
||||
// 1054: A 'get' accessor cannot have parameters.
|
||||
// 1110: Type expected.
|
||||
get instanceGetter<T>(a: i32) {}
|
||||
|
||||
// 1094: An accessor cannot have type parameters.
|
||||
// 1049: A 'set' accessor must have exactly one parameter.
|
||||
// 1095: A 'set' accessor cannot have a return type annotation.
|
||||
set instanceSetter<T>(): i32 {}
|
||||
}
|
||||
|
@ -1,13 +1,23 @@
|
||||
export class Test<T> {
|
||||
instanceFunction(): void {
|
||||
export class Valid<T> {
|
||||
constructor() {}
|
||||
instanceFunction(): void {}
|
||||
static staticFunction(): void {}
|
||||
get instanceGetter(): i32 {}
|
||||
static set staticSetter(v: i32) {}
|
||||
instanceField: i32;
|
||||
static staticField: i32;
|
||||
}
|
||||
static staticFunction(): void {
|
||||
}
|
||||
get instanceGetter(): i32 {
|
||||
return 0;
|
||||
}
|
||||
static set staticSetter(v: i32) {
|
||||
}
|
||||
instanceField: i32;
|
||||
static staticField: i32;
|
||||
export class Invalid<T> {
|
||||
constructor<T>() {}
|
||||
instanceFunction(): {}
|
||||
get instanceGetter<T>(a: i32): {}
|
||||
set instanceSetter<T>() {}
|
||||
}
|
||||
// ERROR 1092: "Type parameters cannot appear on a constructor declaration." in class.ts:13:13
|
||||
// ERROR 1110: "Type expected." in class.ts:16:20
|
||||
// ERROR 1094: "An accessor cannot have type parameters." in class.ts:21:20
|
||||
// ERROR 1054: "A 'get' accessor cannot have parameters." in class.ts:21:6
|
||||
// ERROR 1110: "Type expected." in class.ts:21:31
|
||||
// ERROR 1094: "An accessor cannot have type parameters." in class.ts:26:20
|
||||
// ERROR 1049: "A 'set' accessor must have exactly one parameter." in class.ts:26:6
|
||||
// ERROR 1095: "A 'set' accessor cannot have a return type annotation." in class.ts:26:25
|
||||
|
@ -1,4 +1,7 @@
|
||||
var; while for let; a from "./other";
|
||||
// 1003: Identifier expected.
|
||||
var;
|
||||
// 1005: '(' expected.
|
||||
while for let; a from "./other";
|
||||
do {
|
||||
;
|
||||
} while (false);
|
||||
|
@ -3,7 +3,7 @@ a;
|
||||
from;
|
||||
"./other";
|
||||
do {
|
||||
;
|
||||
;
|
||||
} while (false);
|
||||
// ERROR 1003: "Identifier expected." in continue-on-error.ts @ 0,3
|
||||
// ERROR 1005: "'(' expected." in continue-on-error.ts @ 5,10
|
||||
// ERROR 1003: "Identifier expected." in continue-on-error.ts:2:0
|
||||
// ERROR 1005: "'(' expected." in continue-on-error.ts:4:0
|
||||
|
@ -1,5 +1,5 @@
|
||||
do {
|
||||
;
|
||||
} while (a != b);
|
||||
|
||||
do b; while (a);
|
||||
do b;
|
||||
while (a);
|
||||
|
@ -1,5 +1,5 @@
|
||||
do {
|
||||
;
|
||||
;
|
||||
} while (a != b);
|
||||
do b;
|
||||
while (a);
|
||||
|
@ -1,10 +1,10 @@
|
||||
export const enum A {
|
||||
B = 1,
|
||||
C,
|
||||
D = 3
|
||||
B = 1,
|
||||
C,
|
||||
D = 3
|
||||
}
|
||||
enum E {
|
||||
F,
|
||||
G = 1 + 2,
|
||||
H = 3 * 4
|
||||
F,
|
||||
G = 1 + 2,
|
||||
H = 3 * 4
|
||||
}
|
||||
|
@ -1,9 +1,9 @@
|
||||
for (var i: i32 = 0; i < 10; ++i) {
|
||||
;
|
||||
;
|
||||
}
|
||||
for (i = 0; i < 10; ++i) {
|
||||
;
|
||||
;
|
||||
}
|
||||
for (;;) {
|
||||
;
|
||||
;
|
||||
}
|
||||
|
@ -1,16 +1,16 @@
|
||||
var a = function(): void {
|
||||
;
|
||||
;
|
||||
};
|
||||
var b = function someName(): void {
|
||||
;
|
||||
;
|
||||
};
|
||||
var c = function(a: i32, b: i32): i32 {
|
||||
;
|
||||
;
|
||||
};
|
||||
var d = (): void => {
|
||||
;
|
||||
;
|
||||
};
|
||||
var e = (a: i32, b: i32): i32 => {
|
||||
;
|
||||
;
|
||||
};
|
||||
var f = (a: i32): i32 => a;
|
||||
|
@ -1,7 +1,4 @@
|
||||
function simple(): void {
|
||||
}
|
||||
function typeparams<T, V extends T>(a: V | null = null): void {
|
||||
}
|
||||
function simple(): void {}
|
||||
function typeparams<T, V extends T>(a: V | null = null): void {}
|
||||
@decorator()
|
||||
function withdecorator(): void {
|
||||
}
|
||||
function withdecorator(): void {}
|
||||
|
@ -1,7 +1,4 @@
|
||||
function simple(): void {
|
||||
}
|
||||
function typeparams<T, V extends T>(a: V | null = null): void {
|
||||
}
|
||||
function simple(): void {}
|
||||
function typeparams<T, V extends T>(a: V | null = null): void {}
|
||||
@decorator()
|
||||
function withdecorator(): void {
|
||||
}
|
||||
function withdecorator(): void {}
|
||||
|
@ -1,9 +1,16 @@
|
||||
import { A } from "./other";
|
||||
|
||||
import { A, B, C } from "./other";
|
||||
|
||||
import { A as B, C, D as E, F } from "./other";
|
||||
|
||||
import {
|
||||
A
|
||||
} from "./other";
|
||||
import {
|
||||
A,
|
||||
B,
|
||||
C
|
||||
} from "./other";
|
||||
import {
|
||||
A as B,
|
||||
C,
|
||||
D as E,
|
||||
F
|
||||
} from "./other";
|
||||
import * as A from "./other";
|
||||
|
||||
import "./other";
|
||||
|
@ -1,16 +1,16 @@
|
||||
import {
|
||||
A
|
||||
A
|
||||
} from "./other";
|
||||
import {
|
||||
A,
|
||||
B,
|
||||
C
|
||||
A,
|
||||
B,
|
||||
C
|
||||
} from "./other";
|
||||
import {
|
||||
A as B,
|
||||
C,
|
||||
D as E,
|
||||
F
|
||||
A as B,
|
||||
C,
|
||||
D as E,
|
||||
F
|
||||
} from "./other";
|
||||
import * as A from "./other";
|
||||
import "./other";
|
||||
|
@ -45,7 +45,6 @@
|
||||
0b0;
|
||||
0b1;
|
||||
0b1111111111111111111111111111111;
|
||||
|
||||
"123";
|
||||
"1\"23";
|
||||
"1\"2\\3";
|
||||
|
@ -1,14 +1,11 @@
|
||||
declare namespace A {
|
||||
namespace B {
|
||||
export namespace C {
|
||||
var aVar: i32;
|
||||
const aConst: i32 = 0;
|
||||
function aFunc(): void {
|
||||
}
|
||||
enum AnEnum {
|
||||
}
|
||||
class AClass {
|
||||
}
|
||||
}
|
||||
}
|
||||
namespace B {
|
||||
export namespace C {
|
||||
var aVar: i32;
|
||||
const aConst: i32 = 0;
|
||||
function aFunc(): void {}
|
||||
enum AnEnum {}
|
||||
class AClass {}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,6 +1,11 @@
|
||||
function restValid(a: i32, ...b: i32[]): void {}
|
||||
function optionalValid(a: i32, b?: i32): void {}
|
||||
|
||||
// 1014: A rest parameter must be last in a parameter list.
|
||||
function restParameterMustBeLast(...a: i32[], b: i32): void {}
|
||||
|
||||
function optionalValid(a: i32, b?: i32): void {}
|
||||
// 1016: A required parameter cannot follow an optional parameter.
|
||||
function optionalCannotPrecedeRequired(a?: i32, b: i32): void {}
|
||||
|
||||
// 1016: A required parameter cannot follow an optional parameter.
|
||||
function optionalWithInitializerCannotPrecedeRequired(a: i32 = 1, b: i32): void {}
|
||||
|
@ -1,13 +1,8 @@
|
||||
function restValid(a: i32, ...b: Array<i32>): void {
|
||||
}
|
||||
function restParameterMustBeLast(...a: Array<i32>, b: i32): void {
|
||||
}
|
||||
function optionalValid(a: i32, b?: i32): void {
|
||||
}
|
||||
function optionalCannotPrecedeRequired(a?: i32, b: i32): void {
|
||||
}
|
||||
function optionalWithInitializerCannotPrecedeRequired(a: i32 = 1, b: i32): void {
|
||||
}
|
||||
// ERROR 1014: "A rest parameter must be last in a parameter list." in parameter-order.ts @ 85,86
|
||||
// ERROR 1016: "A required parameter cannot follow an optional parameter." in parameter-order.ts @ 210,211
|
||||
// ERROR 1016: "A required parameter cannot follow an optional parameter." in parameter-order.ts @ 293,294
|
||||
function restValid(a: i32, ...b: Array<i32>): void {}
|
||||
function optionalValid(a: i32, b?: i32): void {}
|
||||
function restParameterMustBeLast(...a: Array<i32>, b: i32): void {}
|
||||
function optionalCannotPrecedeRequired(a?: i32, b: i32): void {}
|
||||
function optionalWithInitializerCannotPrecedeRequired(a: i32 = 1, b: i32): void {}
|
||||
// ERROR 1014: "A rest parameter must be last in a parameter list." in parameter-order.ts:5:36
|
||||
// ERROR 1016: "A required parameter cannot follow an optional parameter." in parameter-order.ts:8:48
|
||||
// ERROR 1016: "A required parameter cannot follow an optional parameter." in parameter-order.ts:11:66
|
||||
|
@ -1,30 +1,10 @@
|
||||
// with modifiers
|
||||
/(abc)\//ig;
|
||||
|
||||
// without modifiers
|
||||
/(abc)\//;
|
||||
|
||||
// can be assigned
|
||||
var re = /(abc)\//ig;
|
||||
|
||||
// generally behaves like an expression
|
||||
var noRe = !/(abc)\//i;
|
||||
|
||||
// inner line break is unterminated
|
||||
/(abc)\//ig; // with modifiers
|
||||
/(abc)\//; // without modifiers
|
||||
var re = /(abc)\//ig; // can be assigned
|
||||
var noRe = !/(abc)\//i; // generally behaves like an expression
|
||||
/a
|
||||
b/ig;
|
||||
|
||||
// just a comment
|
||||
b/ig; // inner line break is unterminated
|
||||
//ig;
|
||||
|
||||
// duplicate flags
|
||||
|
||||
/(abc)\//iig;
|
||||
|
||||
// invalid flags
|
||||
|
||||
/(abc)\//iX;
|
||||
|
||||
// surrounding AST remains intact
|
||||
|
||||
false && /abc/gX.test(someString) || true;
|
||||
/(abc)\//iig; // duplicate flags
|
||||
/(abc)\//iX; // invalid flags
|
||||
false && /abc/gX.test(someString) || true; // surrounding AST remains intact
|
||||
|
@ -5,8 +5,8 @@ var noRe = !/(abc)\//i;
|
||||
/(abc)\//iig;
|
||||
/(abc)\//iX;
|
||||
false && /abc/gX.test(someString) || true;
|
||||
// ERROR 1161: "Unterminated regular expression literal." in regexp.ts @ 75,76
|
||||
// ERROR 1005: "'/' expected." in regexp.ts @ 74,76
|
||||
// ERROR 209: "Invalid regular expression flags." in regexp.ts @ 95,98
|
||||
// ERROR 209: "Invalid regular expression flags." in regexp.ts @ 111,113
|
||||
// ERROR 209: "Invalid regular expression flags." in regexp.ts @ 131,133
|
||||
// ERROR 1161: "Unterminated regular expression literal." in regexp.ts:5:1
|
||||
// ERROR 1005: "'/' expected." in regexp.ts:5:0
|
||||
// ERROR 209: "Invalid regular expression flags." in regexp.ts:8:9
|
||||
// ERROR 209: "Invalid regular expression flags." in regexp.ts:9:9
|
||||
// ERROR 209: "Invalid regular expression flags." in regexp.ts:10:14
|
||||
|
@ -1,5 +1,4 @@
|
||||
// a host-bindings syntax experiment
|
||||
|
||||
@binding(BindingCall.NEW, [ BindingType.STRING ], BindingType.OBJECT_HANDLE)
|
||||
export class ExternalString {
|
||||
|
||||
|
@ -1,65 +1,65 @@
|
||||
@binding(BindingCall.NEW, [BindingType.STRING], BindingType.OBJECT_HANDLE)
|
||||
export class ExternalString {
|
||||
@binding(BindingCall.FUNCTION, [BindingType.U32, BindingType.U32], BindingType.OBJECT_HANDLE)
|
||||
static fromCharCode(char: u16, schar: u16 = <u16>-1): String {
|
||||
return unreachable();
|
||||
}
|
||||
@binding(BindingCall.FUNCTION, [BindingType.U32], BindingType.OBJECT_HANDLE)
|
||||
static fromCodePoint(codepoint: u32): String {
|
||||
return unreachable();
|
||||
}
|
||||
@binding(BindingCall.THIS, [BindingType.U32], BindingType.OBJECT_HANDLE)
|
||||
charAt(index: u32): String {
|
||||
return unreachable();
|
||||
}
|
||||
@binding(BindingCall.THIS, [BindingType.U32], BindingType.PASS_THRU)
|
||||
charCodeAt(index: u32): u16 {
|
||||
return unreachable();
|
||||
}
|
||||
@binding(BindingCall.THIS, [BindingType.U32], BindingType.PASS_THRU)
|
||||
codePointAt(index: u32): u32 {
|
||||
return unreachable();
|
||||
}
|
||||
@binding(BindingCall.THIS, [BindingType.OBJECT_HANDLE], BindingType.OBJECT_HANDLE)
|
||||
@operator("+")
|
||||
concat(other: String): String {
|
||||
return unreachable();
|
||||
}
|
||||
@binding(BindingCall.THIS, [BindingType.OBJECT_HANDLE], BindingType.PASS_THRU)
|
||||
endsWith(other: String): bool {
|
||||
return unreachable();
|
||||
}
|
||||
@binding(BindingCall.THIS, [BindingType.OBJECT_HANDLE], BindingType.PASS_THRU)
|
||||
indexOf(other: String): i32 {
|
||||
return unreachable();
|
||||
}
|
||||
@binding(BindingCall.THIS, [BindingType.OBJECT_HANDLE], BindingType.PASS_THRU)
|
||||
startsWith(other: String): bool {
|
||||
return unreachable();
|
||||
}
|
||||
@binding(BindingCall.THIS, [BindingType.U32, BindingType.U32], BindingType.OBJECT_HANDLE)
|
||||
substr(start: i32, length: i32): String {
|
||||
return unreachable();
|
||||
}
|
||||
@binding(BindingCall.THIS, [BindingType.U32, BindingType.U32], BindingType.OBJECT_HANDLE)
|
||||
substring(start: i32, end: i32): String {
|
||||
return unreachable();
|
||||
}
|
||||
@binding(BindingCall.THIS, [], BindingType.OBJECT_HANDLE)
|
||||
trim(): String {
|
||||
return unreachable();
|
||||
}
|
||||
@binding(BindingCall.THIS, [], BindingType.OBJECT_HANDLE)
|
||||
trimLeft(): String {
|
||||
return unreachable();
|
||||
}
|
||||
@binding(BindingCall.THIS, [], BindingType.OBJECT_HANDLE)
|
||||
trimRight(): String {
|
||||
return unreachable();
|
||||
}
|
||||
@binding(BindingCall.THIS, [BindingType.OBJECT_HANDLE], BindingType.PASS_THRU)
|
||||
@operator("==")
|
||||
equals(other: String): bool {
|
||||
return unreachable();
|
||||
}
|
||||
@binding(BindingCall.FUNCTION, [BindingType.U32, BindingType.U32], BindingType.OBJECT_HANDLE)
|
||||
static fromCharCode(char: u16, schar: u16 = <u16>-1): String {
|
||||
return unreachable();
|
||||
}
|
||||
@binding(BindingCall.FUNCTION, [BindingType.U32], BindingType.OBJECT_HANDLE)
|
||||
static fromCodePoint(codepoint: u32): String {
|
||||
return unreachable();
|
||||
}
|
||||
@binding(BindingCall.THIS, [BindingType.U32], BindingType.OBJECT_HANDLE)
|
||||
charAt(index: u32): String {
|
||||
return unreachable();
|
||||
}
|
||||
@binding(BindingCall.THIS, [BindingType.U32], BindingType.PASS_THRU)
|
||||
charCodeAt(index: u32): u16 {
|
||||
return unreachable();
|
||||
}
|
||||
@binding(BindingCall.THIS, [BindingType.U32], BindingType.PASS_THRU)
|
||||
codePointAt(index: u32): u32 {
|
||||
return unreachable();
|
||||
}
|
||||
@binding(BindingCall.THIS, [BindingType.OBJECT_HANDLE], BindingType.OBJECT_HANDLE)
|
||||
@operator("+")
|
||||
concat(other: String): String {
|
||||
return unreachable();
|
||||
}
|
||||
@binding(BindingCall.THIS, [BindingType.OBJECT_HANDLE], BindingType.PASS_THRU)
|
||||
endsWith(other: String): bool {
|
||||
return unreachable();
|
||||
}
|
||||
@binding(BindingCall.THIS, [BindingType.OBJECT_HANDLE], BindingType.PASS_THRU)
|
||||
indexOf(other: String): i32 {
|
||||
return unreachable();
|
||||
}
|
||||
@binding(BindingCall.THIS, [BindingType.OBJECT_HANDLE], BindingType.PASS_THRU)
|
||||
startsWith(other: String): bool {
|
||||
return unreachable();
|
||||
}
|
||||
@binding(BindingCall.THIS, [BindingType.U32, BindingType.U32], BindingType.OBJECT_HANDLE)
|
||||
substr(start: i32, length: i32): String {
|
||||
return unreachable();
|
||||
}
|
||||
@binding(BindingCall.THIS, [BindingType.U32, BindingType.U32], BindingType.OBJECT_HANDLE)
|
||||
substring(start: i32, end: i32): String {
|
||||
return unreachable();
|
||||
}
|
||||
@binding(BindingCall.THIS, [], BindingType.OBJECT_HANDLE)
|
||||
trim(): String {
|
||||
return unreachable();
|
||||
}
|
||||
@binding(BindingCall.THIS, [], BindingType.OBJECT_HANDLE)
|
||||
trimLeft(): String {
|
||||
return unreachable();
|
||||
}
|
||||
@binding(BindingCall.THIS, [], BindingType.OBJECT_HANDLE)
|
||||
trimRight(): String {
|
||||
return unreachable();
|
||||
}
|
||||
@binding(BindingCall.THIS, [BindingType.OBJECT_HANDLE], BindingType.PASS_THRU)
|
||||
@operator("==")
|
||||
equals(other: String): bool {
|
||||
return unreachable();
|
||||
}
|
||||
}
|
||||
|
@ -3,5 +3,8 @@ var b: i32;
|
||||
const c: i32 = 0;
|
||||
var d = 2;
|
||||
|
||||
var e; // type expected
|
||||
const f: i32; // must be initialized
|
||||
// 1110: Type expected.
|
||||
var e;
|
||||
|
||||
// 1155: 'const' declarations must be initialized.
|
||||
const f: i32;
|
||||
|
@ -4,5 +4,5 @@ const c: i32 = 0;
|
||||
var d = 2;
|
||||
var e;
|
||||
const f: i32;
|
||||
// ERROR 1110: "Type expected." in var.ts @ 59,59
|
||||
// ERROR 1155: "'const' declarations must be initialized." in var.ts @ 84,85
|
||||
// ERROR 1110: "Type expected." in var.ts:7:5
|
||||
// ERROR 1155: "'const' declarations must be initialized." in var.ts:10:6
|
||||
|
@ -1,10 +1,10 @@
|
||||
while (1) {
|
||||
;
|
||||
;
|
||||
}
|
||||
while (false) {
|
||||
;
|
||||
;
|
||||
}
|
||||
while ("str") {
|
||||
;
|
||||
;
|
||||
}
|
||||
while (1) ;
|
||||
while (1);
|
||||
|
@ -7,24 +7,27 @@ require("../src/glue/js");
|
||||
const { Tokenizer, Token } = require("../src/tokenizer");
|
||||
const { Source, SourceKind } = require("../src/ast");
|
||||
|
||||
const text = fs.readFileSync(__dirname + "/../src/tokenizer.ts").toString();
|
||||
var file = process.argv.length > 2 ? process.argv[2] : path.join(__dirname, "..", "src", "tokenizer.ts");
|
||||
const text = fs.readFileSync(file).toString();
|
||||
const tn = new Tokenizer(new Source("compiler.ts", text, SourceKind.ENTRY));
|
||||
|
||||
do {
|
||||
let token = tn.next();
|
||||
let range = tn.range();
|
||||
process.stdout.write(Token[token] + " @ " + range.line + ":" + range.column);
|
||||
if (token == Token.IDENTIFIER) {
|
||||
console.log(Token[token] + " > " + tn.readIdentifier());
|
||||
process.stdout.write(" > " + tn.readIdentifier());
|
||||
} else if (token == Token.INTEGERLITERAL) {
|
||||
console.log(Token[token] + " > " + tn.readInteger());
|
||||
process.stdout.write(" > " + tn.readInteger());
|
||||
} else if (token == Token.FLOATLITERAL) {
|
||||
console.log(Token[token] + " > " + tn.readFloat());
|
||||
process.stdout.write(" > " + tn.readFloat());
|
||||
} else if (token == Token.STRINGLITERAL) {
|
||||
console.log(Token[token] + " > " + tn.readString());
|
||||
process.stdout.write(" > " + tn.readString());
|
||||
} else if (token == Token.ENDOFFILE) {
|
||||
console.log(Token[token]);
|
||||
process.stdout.write("\n");
|
||||
break;
|
||||
} else {
|
||||
let range = tn.range();
|
||||
console.log(Token[token] + " > " + range.source.text.substring(range.start, range.end));
|
||||
process.stdout.write(" > " + range.source.text.substring(range.start, range.end));
|
||||
}
|
||||
process.stdout.write("\n");
|
||||
} while (true);
|
||||
|
Reference in New Issue
Block a user