ajout de Sheebr + support de shutdown + auto install kernel
This commit is contained in:
@@ -0,0 +1,5 @@
|
||||
let environment = {
|
||||
path: ["/sheebr", "/usr/bin"]
|
||||
}
|
||||
|
||||
module.exports = environment
|
||||
@@ -0,0 +1,57 @@
|
||||
const { isAlpha } = require('./utils')
|
||||
|
||||
|
||||
class Lexer{
|
||||
constructor(source){
|
||||
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++;
|
||||
|
||||
}
|
||||
|
||||
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))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
module.exports = {
|
||||
Lexer
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,31 @@
|
||||
async function getline(str) {
|
||||
process.stdout.write(str)
|
||||
process.stdin.resume();
|
||||
process.stdin.setEncoding('utf8')
|
||||
let line = ""
|
||||
return new Promise((res, rej) => {
|
||||
process.stdin.on('data', function(chunk) {
|
||||
|
||||
line += chunk
|
||||
if (chunk.toString('utf-8').endsWith('\n')) {
|
||||
process.stdin.pause()
|
||||
res(line.substring(0, line.length -1))
|
||||
}
|
||||
})
|
||||
process.stdin.on('error', function(err) {
|
||||
rej(err)
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
function isAlpha(str){
|
||||
return /^[a-zA-Z]*$/.test(str);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
module.exports = {
|
||||
isAlpha, getline
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user