Browse Source

Tokenizer will now only accept multi-line strings if the newline is preceeded by a backspace.

master
Bryan Miller 5 years ago
parent
commit
908ba8852d
1 changed files with 11 additions and 6 deletions
  1. +11
    -6
      src/MOS/6502/assembler/tokenizer.js

+ 11
- 6
src/MOS/6502/assembler/tokenizer.js View File

} }


function isOp(c){ function isOp(c){
return ("=+-/*#".indexOf(c) >= 0);
return ("=+-/*#<>!".indexOf(c) >= 0);
} }




this.__stream = GetTextStream(input); this.__stream = GetTextStream(input);
} }


genTokenObject(type, val){
genTokenObject(type, val, line, col){
return { return {
type: type, type: type,
val: val, val: val,
line: this.__stream.line(),
col: this.__stream.col()
line: (typeof(line) === 'number') ? line : this.__stream.line(),
col: (typeof(col) === 'number') ? col : this.__stream.col()
} }
} }


readString(end){ readString(end){
var str = ""; var str = "";
var escaped = false; var escaped = false;
var line = this.__stream.line();
var col = this.__stream.col();
console.log(line);
this.__stream.next(); this.__stream.next();
while (!this.__stream.eof()){ while (!this.__stream.eof()){
let c = this.__stream.next(); let c = this.__stream.next();
escaped = false; escaped = false;
} else if (c === "\\"){ } else if (c === "\\"){
escaped = true; escaped = true;
} else if (c === "\n"){
this.__stream.die("String terminated early.");
} else if (c === end){ } else if (c === end){
break; break;
} else { } else {
str += c; str += c;
} }
} }
return this.genTokenObject('string', str);
return this.genTokenObject('string', str, line, col);
} }


readDirective(){ readDirective(){
} else if (isPunctuation(c)){ } else if (isPunctuation(c)){
return this.genTokenObject('punc', this.__stream.next()); return this.genTokenObject('punc', this.__stream.next());
} else if (isOp(c)){ } else if (isOp(c)){
return this.genTokenObject('op', this.__stream.next());
return this.genTokenObject('op', this.readWhile(isOp));
} }
this.__stream.die("Unable to process character '" + c + "'."); this.__stream.die("Unable to process character '" + c + "'.");
} }

Loading…
Cancel
Save