mirror of
https://github.com/fluencelabs/assemblyscript
synced 2025-06-21 02:31:41 +00:00
Initial commit
This commit is contained in:
23
tests/tokenizer.ts
Normal file
23
tests/tokenizer.ts
Normal file
@ -0,0 +1,23 @@
|
||||
import "../src/glue/js";
|
||||
import { Tokenizer, Token } from "../src/tokenizer";
|
||||
import { Source } from "../src/reflection";
|
||||
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);
|
Reference in New Issue
Block a user