scanning errors are now nice
This commit is contained in:
parent
c6709bb2e8
commit
d6a004d9ac
4
pkg/rudus.d.ts
vendored
4
pkg/rudus.d.ts
vendored
|
@ -14,8 +14,8 @@ export interface InitOutput {
|
|||
readonly __wbindgen_malloc: (a: number, b: number) => number;
|
||||
readonly __wbindgen_realloc: (a: number, b: number, c: number, d: number) => number;
|
||||
readonly __wbindgen_export_6: WebAssembly.Table;
|
||||
readonly closure305_externref_shim: (a: number, b: number, c: any) => void;
|
||||
readonly closure329_externref_shim: (a: number, b: number, c: any, d: any) => void;
|
||||
readonly closure304_externref_shim: (a: number, b: number, c: any) => void;
|
||||
readonly closure328_externref_shim: (a: number, b: number, c: any, d: any) => void;
|
||||
readonly __wbindgen_start: () => void;
|
||||
}
|
||||
|
||||
|
|
|
@ -240,13 +240,13 @@ function _assertNum(n) {
|
|||
function __wbg_adapter_20(arg0, arg1, arg2) {
|
||||
_assertNum(arg0);
|
||||
_assertNum(arg1);
|
||||
wasm.closure305_externref_shim(arg0, arg1, arg2);
|
||||
wasm.closure304_externref_shim(arg0, arg1, arg2);
|
||||
}
|
||||
|
||||
function __wbg_adapter_50(arg0, arg1, arg2, arg3) {
|
||||
_assertNum(arg0);
|
||||
_assertNum(arg1);
|
||||
wasm.closure329_externref_shim(arg0, arg1, arg2, arg3);
|
||||
wasm.closure328_externref_shim(arg0, arg1, arg2, arg3);
|
||||
}
|
||||
|
||||
async function __wbg_load(module, imports) {
|
||||
|
@ -425,8 +425,8 @@ function __wbg_get_imports() {
|
|||
_assertBoolean(ret);
|
||||
return ret;
|
||||
};
|
||||
imports.wbg.__wbindgen_closure_wrapper7885 = function() { return logError(function (arg0, arg1, arg2) {
|
||||
const ret = makeMutClosure(arg0, arg1, 306, __wbg_adapter_20);
|
||||
imports.wbg.__wbindgen_closure_wrapper7890 = function() { return logError(function (arg0, arg1, arg2) {
|
||||
const ret = makeMutClosure(arg0, arg1, 305, __wbg_adapter_20);
|
||||
return ret;
|
||||
}, arguments) };
|
||||
imports.wbg.__wbindgen_debug_string = function(arg0, arg1) {
|
||||
|
|
Binary file not shown.
4
pkg/rudus_bg.wasm.d.ts
vendored
4
pkg/rudus_bg.wasm.d.ts
vendored
|
@ -9,6 +9,6 @@ export const __wbindgen_free: (a: number, b: number, c: number) => void;
|
|||
export const __wbindgen_malloc: (a: number, b: number) => number;
|
||||
export const __wbindgen_realloc: (a: number, b: number, c: number, d: number) => number;
|
||||
export const __wbindgen_export_6: WebAssembly.Table;
|
||||
export const closure305_externref_shim: (a: number, b: number, c: any) => void;
|
||||
export const closure329_externref_shim: (a: number, b: number, c: any, d: any) => void;
|
||||
export const closure304_externref_shim: (a: number, b: number, c: any) => void;
|
||||
export const closure328_externref_shim: (a: number, b: number, c: any, d: any) => void;
|
||||
export const __wbindgen_start: () => void;
|
||||
|
|
|
@ -3,7 +3,7 @@ use crate::lexer::Token;
|
|||
use crate::validator::VErr;
|
||||
use chumsky::prelude::*;
|
||||
|
||||
const SEPARATOR: &str = "\n\n***\n";
|
||||
const SEPARATOR: &str = "\n\n";
|
||||
|
||||
fn line_number(src: &'static str, span: SimpleSpan) -> usize {
|
||||
src.chars().take(span.start).filter(|c| *c == '\n').count()
|
||||
|
@ -13,16 +13,23 @@ fn get_line(src: &'static str, line: usize) -> String {
|
|||
src.split("\n").nth(line).unwrap().to_string()
|
||||
}
|
||||
|
||||
pub fn lexing(errs: Vec<Rich<'static, char>>) -> String {
|
||||
let mut msg = "Syntax errors".to_string();
|
||||
pub fn lexing(errs: Vec<Rich<'static, char>>, src: &'static str, input: &'static str) -> String {
|
||||
let mut msgs = vec!["Ludus found some errors.".to_string()];
|
||||
for err in errs {
|
||||
msg = format!("{msg}\n{:#?}", err);
|
||||
let mut msg = vec![];
|
||||
let line_number = line_number(src, *err.span());
|
||||
let line = get_line(src, line_number);
|
||||
let char = src.chars().nth(err.span().start).unwrap();
|
||||
msg.push(format!("Syntax error: unexpected {char}"));
|
||||
msg.push(format!(" on line {} in {}", line_number + 1, input));
|
||||
msg.push(format!(" >>> {line}"));
|
||||
msgs.push(msg.join("\n"));
|
||||
}
|
||||
msg
|
||||
msgs.join(SEPARATOR)
|
||||
}
|
||||
|
||||
pub fn validation(errs: Vec<VErr>) -> String {
|
||||
let mut msgs = vec![];
|
||||
let mut msgs = vec!["Ludus found some errors.".to_string()];
|
||||
for err in errs {
|
||||
let mut msg = vec![];
|
||||
let line_number = line_number(err.src, *err.span);
|
||||
|
|
|
@ -125,7 +125,7 @@ pub async fn ludus(src: String) {
|
|||
// lex the source
|
||||
let (tokens, lex_errs) = lexer().parse(src).into_output_errors();
|
||||
if !lex_errs.is_empty() {
|
||||
send_err_to_ludus_console(lexing(lex_errs)).await;
|
||||
send_err_to_ludus_console(lexing(lex_errs, src, "user script")).await;
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user