feat(lexer): initial (wip) implementation.

This commit is contained in:
Chirayu Krishnappa
2014-09-26 13:52:12 -07:00
parent cff47d4f8e
commit c85ab3a5a4
7 changed files with 658 additions and 2 deletions

View File

@ -17,4 +17,10 @@ class ListWrapper {
static get(m, k) => m[k];
static void set(m, k, v) { m[k] = v; }
static contains(m, k) => m.containsKey(k);
static void push(List l, e) { l.add(e); }
}
class SetWrapper {
static Set createFromList(List l) { return new Set.from(l); }
static bool has(Set s, key) { return s.contains(key); }
}

View File

@ -15,4 +15,10 @@ export class ListWrapper {
static clone(array) {
return Array.prototype.slice.call(array, 0);
}
static push(l, e) { l.push(e); }
}
export class SetWrapper {
static createFromList(lst:List) { return new Set(lst); }
static has(s:Set, key):boolean { return s.has(key); }
}

View File

@ -9,4 +9,40 @@ class FIELD {
class CONST {}
class ABSTRACT {}
class IMPLEMENTS {}
class IMPLEMENTS {}
class StringWrapper {
static String fromCharCode(int code) {
return new String.fromCharCode(code);
}
static charCodeAt(String s, int index) {
return s.codeUnitAt(index);
}
}
class StringJoiner {
List<String> _parts = <String>[];
void add(String part) {
_parts.add(part);
}
String toString() => _parts.join("");
}
class NumberWrapper {
static int parseIntAutoRadix(String text) {
return int.parse(text);
}
static int parseInt(String text, int radix) {
return int.parse(text, radix: radix);
}
static double parseFloat(String text) {
return double.parse(text);
}
}

View File

@ -9,4 +9,52 @@ export class FIELD {
export class CONST {}
export class ABSTRACT {}
export class IMPLEMENTS {}
export class IMPLEMENTS {}
export class StringWrapper {
static fromCharCode(code:number/*int*/) {
return String.fromCharCode(code);
}
static charCodeAt(s:string, index:number/*int*/) {
return s.charCodeAt(index);
}
}
export class StringJoiner {
constructor() {
this.parts = [];
}
add(part:string) {
this.parts.push(part);
}
toString():string {
return this.parts.join("");
}
}
export class NumberWrapper {
static parseIntAutoRadix(text:string):number/*int*/ {
var result:number/*int*/ = parseInt(text);
if (isNaN(result)) {
throw new Error("Invalid integer literal when parsing " + text);
}
return result;
}
static parseInt(text:string, radix:number/*int*/):number/*int*/ {
var result:number/*int*/ = parseInt(text, radix);
if (isNaN(result)) {
throw new Error("Invalid integer literal when parsing " + text + " in base " + radix);
}
return result;
}
// TODO: NaN is a valid literal but is returned by parseFloat to indicate an error.
static parseFloat(text:string):number/*int*/ {
return parseFloat(text);
}
}