🧑💻 use let
instead of var
This commit is contained in:
parent
3bd47fbe62
commit
dfb7b3d09e
@ -70,15 +70,15 @@
|
|||||||
?></script>
|
?></script>
|
||||||
|
|
||||||
<script type="text/javascript">
|
<script type="text/javascript">
|
||||||
var juice_program = <?php echo(json_encode(file_get_contents("juice-program.jce"))); ?>;
|
let juice_program = <?php echo(json_encode(file_get_contents("juice-program.jce"))); ?>;
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<script type="text/javascript">
|
<script type="text/javascript">
|
||||||
var my_output_callback = function(text){
|
let my_output_callback = function(text){
|
||||||
var line_list = text.split("\n");
|
let line_list = text.split("\n");
|
||||||
|
|
||||||
for(var one_line of line_list){
|
for(let one_line of line_list){
|
||||||
var span_one_line = document.createElement("span");
|
let span_one_line = document.createElement("span");
|
||||||
|
|
||||||
span_one_line.classList.add("line");
|
span_one_line.classList.add("line");
|
||||||
span_one_line.textContent = one_line;
|
span_one_line.textContent = one_line;
|
||||||
@ -86,8 +86,8 @@
|
|||||||
document.getElementById("text-output-area").appendChild(span_one_line);
|
document.getElementById("text-output-area").appendChild(span_one_line);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
var my_error_callback = function(text, type){
|
let my_error_callback = function(text, type){
|
||||||
var span_one_line = document.createElement("span");
|
let span_one_line = document.createElement("span");
|
||||||
|
|
||||||
span_one_line.classList.add("line", "stderr-" + type);
|
span_one_line.classList.add("line", "stderr-" + type);
|
||||||
span_one_line.textContent = text + "\n";
|
span_one_line.textContent = text + "\n";
|
||||||
@ -95,7 +95,7 @@
|
|||||||
document.getElementById("text-output-area").appendChild(span_one_line);
|
document.getElementById("text-output-area").appendChild(span_one_line);
|
||||||
}
|
}
|
||||||
|
|
||||||
var juicescript = new Juicescript({
|
let juicescript = new Juicescript({
|
||||||
callback: {
|
callback: {
|
||||||
stdout: my_output_callback,
|
stdout: my_output_callback,
|
||||||
stderr: my_error_callback
|
stderr: my_error_callback
|
||||||
|
@ -74,7 +74,7 @@ class Juicescript_io {
|
|||||||
*/
|
*/
|
||||||
stderr_build(text, additional){
|
stderr_build(text, additional){
|
||||||
// START WITH EMPTY STRING //
|
// START WITH EMPTY STRING //
|
||||||
var string = "";
|
let string = "";
|
||||||
|
|
||||||
|
|
||||||
// PREFIX //
|
// PREFIX //
|
||||||
|
45
src/lexer.js
45
src/lexer.js
@ -51,7 +51,7 @@ class Juicescript_lexer {
|
|||||||
*/
|
*/
|
||||||
scan_one(){
|
scan_one(){
|
||||||
// consume next character
|
// consume next character
|
||||||
var char = this.next();
|
let char = this.next();
|
||||||
|
|
||||||
// scan character
|
// scan character
|
||||||
switch(char){
|
switch(char){
|
||||||
@ -202,7 +202,7 @@ class Juicescript_lexer {
|
|||||||
// do we have a quote?
|
// do we have a quote?
|
||||||
if(this.peek() === marker){
|
if(this.peek() === marker){
|
||||||
// count backslashes in front of quote
|
// count backslashes in front of quote
|
||||||
var backslash_count = 0;
|
let backslash_count = 0;
|
||||||
while(this.peek(-(backslash_count + 1)) === "\\"){
|
while(this.peek(-(backslash_count + 1)) === "\\"){
|
||||||
backslash_count++;
|
backslash_count++;
|
||||||
};
|
};
|
||||||
@ -232,18 +232,18 @@ class Juicescript_lexer {
|
|||||||
this.next();
|
this.next();
|
||||||
|
|
||||||
// get consumed string
|
// get consumed string
|
||||||
var string = this.source.substring(this.start + 1, this.end - 1);
|
let string = this.source.substring(this.start + 1, this.end - 1);
|
||||||
|
|
||||||
|
|
||||||
// RESOLVE ESCAPE SEQUENCES //
|
// RESOLVE ESCAPE SEQUENCES //
|
||||||
// iterate over whole string
|
// iterate over whole string
|
||||||
var offset = 0;
|
let offset = 0;
|
||||||
var pos = -1;
|
let pos = -1;
|
||||||
while((pos = string.indexOf("\\", offset)) > -1){
|
while((pos = string.indexOf("\\", offset)) > -1){
|
||||||
// defaults for escaping one character
|
// defaults for escaping one character
|
||||||
var char_escaped = string.substring(pos + 1, pos + 2);
|
let char_escaped = string.substring(pos + 1, pos + 2);
|
||||||
var replace = char_escaped;
|
let replace = char_escaped;
|
||||||
var remove_length = replace.length;
|
let remove_length = replace.length;
|
||||||
|
|
||||||
// special escape sequences
|
// special escape sequences
|
||||||
switch(char_escaped){
|
switch(char_escaped){
|
||||||
@ -265,12 +265,12 @@ class Juicescript_lexer {
|
|||||||
// unicode
|
// unicode
|
||||||
case "u":
|
case "u":
|
||||||
// get four-letter codepoint string
|
// get four-letter codepoint string
|
||||||
var next_four_chars = string.substring(pos + 2, pos + 6);
|
let next_four_chars = string.substring(pos + 2, pos + 6);
|
||||||
|
|
||||||
// check if this is valid hexadecimal
|
// check if this is valid hexadecimal
|
||||||
if(/^[0-9a-fA-F]*$/.test(next_four_chars)){
|
if(/^[0-9a-fA-F]*$/.test(next_four_chars)){
|
||||||
// convert codepoint to decimal number
|
// convert codepoint to decimal number
|
||||||
var codepoint = parseInt(next_four_chars, 16);
|
let codepoint = parseInt(next_four_chars, 16);
|
||||||
|
|
||||||
// get corresponding unicode character
|
// get corresponding unicode character
|
||||||
replace = String.fromCharCode(codepoint);
|
replace = String.fromCharCode(codepoint);
|
||||||
@ -334,7 +334,7 @@ class Juicescript_lexer {
|
|||||||
while(this.is_alphanumeric(this.peek())) this.next();
|
while(this.is_alphanumeric(this.peek())) this.next();
|
||||||
|
|
||||||
// get consumed string
|
// get consumed string
|
||||||
var variable = this.source.substring(this.start + 1, this.end);
|
let variable = this.source.substring(this.start + 1, this.end);
|
||||||
|
|
||||||
|
|
||||||
// CHECK IF THERE EVEN IS A NAME //
|
// CHECK IF THERE EVEN IS A NAME //
|
||||||
@ -354,9 +354,9 @@ class Juicescript_lexer {
|
|||||||
*/
|
*/
|
||||||
scan_number(negative = false){
|
scan_number(negative = false){
|
||||||
// DEFAULT VALUES FOR BASE 10 //
|
// DEFAULT VALUES FOR BASE 10 //
|
||||||
var base = null;
|
let base = null;
|
||||||
var is_valid_char = this.is_digit;
|
let is_valid_char = this.is_digit;
|
||||||
var number_string_offset = 0;
|
let number_string_offset = 0;
|
||||||
|
|
||||||
|
|
||||||
// HANDLE OTHER BASES //
|
// HANDLE OTHER BASES //
|
||||||
@ -409,18 +409,19 @@ class Juicescript_lexer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// get consumed string
|
// get consumed string
|
||||||
var number_string = this.source.substring(this.start + number_string_offset, this.end);
|
let number_string = this.source.substring(this.start + number_string_offset, this.end);
|
||||||
|
|
||||||
|
|
||||||
// STORE NUMBER IN TOKEN //
|
// STORE NUMBER IN TOKEN //
|
||||||
// parse number
|
// parse number
|
||||||
|
let number;
|
||||||
if(base !== null){
|
if(base !== null){
|
||||||
// custom base
|
// custom base
|
||||||
var number = parseFloat(parseInt(number_string, base));
|
number = parseFloat(parseInt(number_string, base));
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
// base 10
|
// base 10
|
||||||
var number = parseFloat(number_string);
|
number = parseFloat(number_string);
|
||||||
}
|
}
|
||||||
|
|
||||||
// maybe negate
|
// maybe negate
|
||||||
@ -439,7 +440,7 @@ class Juicescript_lexer {
|
|||||||
while(this.is_alphanumeric(this.peek())) this.next();
|
while(this.is_alphanumeric(this.peek())) this.next();
|
||||||
|
|
||||||
// get consumed string
|
// get consumed string
|
||||||
var identifier = this.source.substring(this.start, this.end);
|
let identifier = this.source.substring(this.start, this.end);
|
||||||
|
|
||||||
|
|
||||||
// CHEKC IF THIS IS A SUFFIXED FLAG //
|
// CHEKC IF THIS IS A SUFFIXED FLAG //
|
||||||
@ -455,7 +456,7 @@ class Juicescript_lexer {
|
|||||||
|
|
||||||
// MAYBE CONVERT IDENTIFIER TO KEYWORD //
|
// MAYBE CONVERT IDENTIFIER TO KEYWORD //
|
||||||
// try to load from lookup table
|
// try to load from lookup table
|
||||||
var keyword = ({
|
let keyword = ({
|
||||||
"DEF": Juicescript.token_type.DEF,
|
"DEF": Juicescript.token_type.DEF,
|
||||||
|
|
||||||
"GLOB": Juicescript.token_type.GLOBAL,
|
"GLOB": Juicescript.token_type.GLOBAL,
|
||||||
@ -491,7 +492,7 @@ class Juicescript_lexer {
|
|||||||
while(this.is_alphanumeric(this.peek())) this.next();
|
while(this.is_alphanumeric(this.peek())) this.next();
|
||||||
|
|
||||||
// get consumed string
|
// get consumed string
|
||||||
var flag = this.source.substring(this.start + 1, this.end);
|
let flag = this.source.substring(this.start + 1, this.end);
|
||||||
|
|
||||||
// consume (=ignore) optional `:` suffix
|
// consume (=ignore) optional `:` suffix
|
||||||
this.match(":");
|
this.match(":");
|
||||||
@ -592,7 +593,7 @@ class Juicescript_lexer {
|
|||||||
*/
|
*/
|
||||||
token_add(options){
|
token_add(options){
|
||||||
// NEW OJECT //
|
// NEW OJECT //
|
||||||
var token = {};
|
let token = {};
|
||||||
|
|
||||||
|
|
||||||
// COLLECT REQUIRED ATTRIBUTES //
|
// COLLECT REQUIRED ATTRIBUTES //
|
||||||
|
@ -57,13 +57,13 @@ class Juicescript {
|
|||||||
parse(program_string){
|
parse(program_string){
|
||||||
// DO SCANNING //
|
// DO SCANNING //
|
||||||
// get lexer
|
// get lexer
|
||||||
var lexer = new Juicescript_lexer(program_string, {
|
let lexer = new Juicescript_lexer(program_string, {
|
||||||
io: this.io
|
io: this.io
|
||||||
});
|
});
|
||||||
|
|
||||||
// run lexical analysis
|
// run lexical analysis
|
||||||
var token_list = lexer.scan();
|
let token_list = lexer.scan();
|
||||||
/**/for(var one_token of token_list){
|
/**/for(let one_token of token_list){
|
||||||
/**/one_token.type = Juicescript.token_type.name(one_token.type);
|
/**/one_token.type = Juicescript.token_type.name(one_token.type);
|
||||||
/**/console.log(one_token);
|
/**/console.log(one_token);
|
||||||
/**/}
|
/**/}
|
||||||
|
Reference in New Issue
Block a user