mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 08:47:34 +00:00
js: Follow Serenity C++ naming conventions
This commit is contained in:
parent
37918d4141
commit
9540174b40
1 changed files with 25 additions and 25 deletions
|
@ -62,10 +62,10 @@ private:
|
||||||
static JS::Value save_to_file(JS::Interpreter&);
|
static JS::Value save_to_file(JS::Interpreter&);
|
||||||
};
|
};
|
||||||
|
|
||||||
bool dump_ast = false;
|
static bool s_dump_ast = false;
|
||||||
bool print_last_result = false;
|
static bool s_print_last_result = false;
|
||||||
static OwnPtr<Line::Editor> editor;
|
static OwnPtr<Line::Editor> s_editor;
|
||||||
static int repl_line_level = 0;
|
static int s_repl_line_level = 0;
|
||||||
|
|
||||||
static String prompt_for_level(int level)
|
static String prompt_for_level(int level)
|
||||||
{
|
{
|
||||||
|
@ -85,8 +85,8 @@ String read_next_piece()
|
||||||
|
|
||||||
do {
|
do {
|
||||||
|
|
||||||
String line = editor->get_line(prompt_for_level(repl_line_level));
|
String line = s_editor->get_line(prompt_for_level(s_repl_line_level));
|
||||||
editor->add_to_history(line);
|
s_editor->add_to_history(line);
|
||||||
|
|
||||||
piece.append(line);
|
piece.append(line);
|
||||||
auto lexer = JS::Lexer(line);
|
auto lexer = JS::Lexer(line);
|
||||||
|
@ -96,18 +96,18 @@ String read_next_piece()
|
||||||
case JS::TokenType::BracketOpen:
|
case JS::TokenType::BracketOpen:
|
||||||
case JS::TokenType::CurlyOpen:
|
case JS::TokenType::CurlyOpen:
|
||||||
case JS::TokenType::ParenOpen:
|
case JS::TokenType::ParenOpen:
|
||||||
repl_line_level++;
|
s_repl_line_level++;
|
||||||
break;
|
break;
|
||||||
case JS::TokenType::BracketClose:
|
case JS::TokenType::BracketClose:
|
||||||
case JS::TokenType::CurlyClose:
|
case JS::TokenType::CurlyClose:
|
||||||
case JS::TokenType::ParenClose:
|
case JS::TokenType::ParenClose:
|
||||||
repl_line_level--;
|
s_repl_line_level--;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} while (repl_line_level > 0);
|
} while (s_repl_line_level > 0);
|
||||||
|
|
||||||
return piece.to_string();
|
return piece.to_string();
|
||||||
}
|
}
|
||||||
|
@ -337,14 +337,14 @@ JS::Value ReplObject::load_file(JS::Interpreter& interpreter)
|
||||||
}
|
}
|
||||||
auto parser = JS::Parser(JS::Lexer(source));
|
auto parser = JS::Parser(JS::Lexer(source));
|
||||||
auto program = parser.parse_program();
|
auto program = parser.parse_program();
|
||||||
if (dump_ast)
|
if (s_dump_ast)
|
||||||
program->dump(0);
|
program->dump(0);
|
||||||
|
|
||||||
if (parser.has_errors())
|
if (parser.has_errors())
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
interpreter.run(*program);
|
interpreter.run(*program);
|
||||||
if (print_last_result)
|
if (s_print_last_result)
|
||||||
print(interpreter.last_value());
|
print(interpreter.last_value());
|
||||||
}
|
}
|
||||||
return JS::Value(true);
|
return JS::Value(true);
|
||||||
|
@ -359,7 +359,7 @@ void repl(JS::Interpreter& interpreter)
|
||||||
repl_statements.append(piece);
|
repl_statements.append(piece);
|
||||||
auto parser = JS::Parser(JS::Lexer(piece));
|
auto parser = JS::Parser(JS::Lexer(piece));
|
||||||
auto program = parser.parse_program();
|
auto program = parser.parse_program();
|
||||||
if (dump_ast)
|
if (s_dump_ast)
|
||||||
program->dump(0);
|
program->dump(0);
|
||||||
|
|
||||||
if (parser.has_errors()) {
|
if (parser.has_errors()) {
|
||||||
|
@ -397,8 +397,8 @@ int main(int argc, char** argv)
|
||||||
const char* script_path = nullptr;
|
const char* script_path = nullptr;
|
||||||
|
|
||||||
Core::ArgsParser args_parser;
|
Core::ArgsParser args_parser;
|
||||||
args_parser.add_option(dump_ast, "Dump the AST", "dump-ast", 'A');
|
args_parser.add_option(s_dump_ast, "Dump the AST", "dump-ast", 'A');
|
||||||
args_parser.add_option(print_last_result, "Print last result", "print-last-result", 'l');
|
args_parser.add_option(s_print_last_result, "Print last result", "print-last-result", 'l');
|
||||||
args_parser.add_option(gc_on_every_allocation, "GC on every allocation", "gc-on-every-allocation", 'g');
|
args_parser.add_option(gc_on_every_allocation, "GC on every allocation", "gc-on-every-allocation", 'g');
|
||||||
args_parser.add_option(syntax_highlight, "Enable live syntax highlighting", "syntax-highlight", 's');
|
args_parser.add_option(syntax_highlight, "Enable live syntax highlighting", "syntax-highlight", 's');
|
||||||
args_parser.add_option(test_mode, "Run the interpreter with added functionality for the test harness", "test-mode", 't');
|
args_parser.add_option(test_mode, "Run the interpreter with added functionality for the test harness", "test-mode", 't');
|
||||||
|
@ -418,19 +418,19 @@ int main(int argc, char** argv)
|
||||||
if (test_mode)
|
if (test_mode)
|
||||||
enable_test_mode(*interpreter);
|
enable_test_mode(*interpreter);
|
||||||
|
|
||||||
editor = make<Line::Editor>();
|
s_editor = make<Line::Editor>();
|
||||||
|
|
||||||
signal(SIGINT, [](int) {
|
signal(SIGINT, [](int) {
|
||||||
sigint_handler();
|
sigint_handler();
|
||||||
editor->interrupted();
|
s_editor->interrupted();
|
||||||
});
|
});
|
||||||
|
|
||||||
signal(SIGWINCH, [](int) {
|
signal(SIGWINCH, [](int) {
|
||||||
editor->resized();
|
s_editor->resized();
|
||||||
});
|
});
|
||||||
|
|
||||||
editor->initialize();
|
s_editor->initialize();
|
||||||
editor->on_display_refresh = [syntax_highlight](Line::Editor& editor) {
|
s_editor->on_display_refresh = [syntax_highlight](Line::Editor& editor) {
|
||||||
auto stylize = [&](Line::Span span, Line::Style styles) {
|
auto stylize = [&](Line::Span span, Line::Style styles) {
|
||||||
if (syntax_highlight)
|
if (syntax_highlight)
|
||||||
editor.stylize(span, styles);
|
editor.stylize(span, styles);
|
||||||
|
@ -442,7 +442,7 @@ int main(int argc, char** argv)
|
||||||
builder.append(" ");
|
builder.append(" ");
|
||||||
String str = builder.build();
|
String str = builder.build();
|
||||||
|
|
||||||
size_t open_indents = repl_line_level;
|
size_t open_indents = s_repl_line_level;
|
||||||
|
|
||||||
JS::Lexer lexer(str, false);
|
JS::Lexer lexer(str, false);
|
||||||
bool indenters_starting_line = true;
|
bool indenters_starting_line = true;
|
||||||
|
@ -568,7 +568,7 @@ int main(int argc, char** argv)
|
||||||
editor.set_prompt(prompt_for_level(open_indents));
|
editor.set_prompt(prompt_for_level(open_indents));
|
||||||
};
|
};
|
||||||
|
|
||||||
auto complete = [&interpreter, &editor = *editor](const String& token) -> Vector<Line::CompletionSuggestion> {
|
auto complete = [&interpreter, &editor = *s_editor](const String& token) -> Vector<Line::CompletionSuggestion> {
|
||||||
if (token.length() == 0)
|
if (token.length() == 0)
|
||||||
return {}; // nyeh
|
return {}; // nyeh
|
||||||
|
|
||||||
|
@ -630,8 +630,8 @@ int main(int argc, char** argv)
|
||||||
editor.suggest(token.length());
|
editor.suggest(token.length());
|
||||||
return results;
|
return results;
|
||||||
};
|
};
|
||||||
editor->on_tab_complete_first_token = [complete](auto& value) { return complete(value); };
|
s_editor->on_tab_complete_first_token = [complete](auto& value) { return complete(value); };
|
||||||
editor->on_tab_complete_other_token = [complete](auto& value) { return complete(value); };
|
s_editor->on_tab_complete_other_token = [complete](auto& value) { return complete(value); };
|
||||||
repl(*interpreter);
|
repl(*interpreter);
|
||||||
} else {
|
} else {
|
||||||
interpreter = JS::Interpreter::create<JS::GlobalObject>();
|
interpreter = JS::Interpreter::create<JS::GlobalObject>();
|
||||||
|
@ -659,7 +659,7 @@ int main(int argc, char** argv)
|
||||||
auto parser = JS::Parser(JS::Lexer(source));
|
auto parser = JS::Parser(JS::Lexer(source));
|
||||||
auto program = parser.parse_program();
|
auto program = parser.parse_program();
|
||||||
|
|
||||||
if (dump_ast)
|
if (s_dump_ast)
|
||||||
program->dump(0);
|
program->dump(0);
|
||||||
|
|
||||||
if (parser.has_errors()) {
|
if (parser.has_errors()) {
|
||||||
|
@ -675,7 +675,7 @@ int main(int argc, char** argv)
|
||||||
interpreter->clear_exception();
|
interpreter->clear_exception();
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
if (print_last_result)
|
if (s_print_last_result)
|
||||||
print(result);
|
print(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue