forked from AssemblyScript/assemblyscript
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtokenizer.ts
More file actions
23 lines (20 loc) · 796 Bytes
/
tokenizer.ts
File metadata and controls
23 lines (20 loc) · 796 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
import "../src/glue/js";
import { Tokenizer, Token } from "../src/tokenizer";
import { Source } from "../src/ast";
import * as fs from "fs";
const text = fs.readFileSync(__dirname + "/../src/tokenizer.ts").toString();
const tn = new Tokenizer(new Source("tokenizer.ts", text));
let token;
do {
token = tn.next();
let range = tn.range();
console.log(Token[token] + " -> " + range.source.text.substring(range.start, range.end));
if (token == Token.IDENTIFIER)
console.log("> " + tn.readIdentifier());
else if (token == Token.INTEGERLITERAL)
console.log("> " + tn.readInteger());
else if (token == Token.FLOATLITERAL)
console.log("> " + tn.readFloat());
else if (token == Token.STRINGLITERAL)
console.log("> " + tn.readString());
} while (token != Token.ENDOFFILE);