refacto ts + ajout de dessin simple + ajout pinceau

WIP lib graphique
This commit is contained in:
Marc
2022-02-08 13:35:49 +01:00
parent a3547ac244
commit 47e764132f
13 changed files with 255 additions and 66 deletions
+40 -35
View File
@@ -1,54 +1,59 @@
//@ts-check
const { isAlpha } = require('./utils')
class Lexer{
constructor(source){
this.tokens = [];
this.current = 0;
this.start = 0;
this.source = source
}
/**
* @param { string } source
*/
constructor(source){
/** @type { string[] } */
this.tokens = [];
this.current = 0;
this.start = 0;
this.source = source
}
scanTokens(){
while(this.current < this.source.length){
this.start = this.current
this.scanToken()
}
return this.tokens;
}
scanToken(){
if(this.source[this.current] == "\""){
this.string()
}
else{
let content = ""
while(this.source[this.current] != ' ' && this.source[this.current] != '\n' && this.current < this.source.length ){
content += this.source[this.current];
this.current++;
}
this.tokens.push(content)
}
this.current++;
scanTokens(){
while(this.current < this.source.length){
this.start = this.current
this.scanToken()
}
return this.tokens;
}
string(){
this.current++;
scanToken(){
if(this.source[this.current] == "\""){
this.string()
}
else{
let content = ""
while(this.source[this.current] != "\"" && this.current < this.source.length){
while(this.source[this.current] != ' ' && this.source[this.current] != '\n' && this.current < this.source.length ){
content += this.source[this.current];
this.current++;
}
this.tokens.push(content)
}
this.current++;
addToken(tokenType, value=""){
this.tokens.push(Token(tokenType, value))
}
string(){
this.current++;
let content = ""
while(this.source[this.current] != "\"" && this.current < this.source.length){
content += this.source[this.current];
this.current++;
}
this.tokens.push(content)
}
//addToken(tokenType, value=""){
// this.tokens.push(Token(tokenType, value))
//}
}