refacto ts + ajout de dessin simple + ajout pinceau
WIP lib graphique
This commit is contained in:
@@ -1,3 +1,7 @@
|
||||
//@ts-check
|
||||
/**
|
||||
* @type {{ [key: string]: string[] }}
|
||||
*/
|
||||
const aliases = {
|
||||
ls: ["ls", "--color"]
|
||||
}
|
||||
|
||||
@@ -1,9 +1,13 @@
|
||||
//@ts-check
|
||||
/**
|
||||
* @type {{ [key: string]: string }}
|
||||
*/
|
||||
let environment = {
|
||||
path: ["/usr/bin", "/usr/sbin", "/usr/lib/sheebr", "/usr/local/bin", "/usr/local/sbin/"],
|
||||
path: ["/usr/bin", "/usr/sbin", "/usr/lib/sheebr", "/usr/local/bin", "/usr/local/sbin/"].join(':'),
|
||||
ls_color: JSON.stringify({
|
||||
di: [01, 34],
|
||||
ln: [01, 36],
|
||||
ex: [01, 32]
|
||||
di: [1, 34],
|
||||
ln: [1, 36],
|
||||
ex: [1, 32]
|
||||
}),
|
||||
node: "/usr/local/bin/node"
|
||||
}
|
||||
|
||||
@@ -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))
|
||||
//}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -24,6 +24,10 @@ async function getline(str) {
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* @param { string } str
|
||||
* @returns
|
||||
*/
|
||||
function isAlpha(str){
|
||||
return /^[a-zA-Z]*$/.test(str)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user