diff --git a/pkg/rudus.d.ts b/pkg/rudus.d.ts index 0d303b9..363ba34 100644 --- a/pkg/rudus.d.ts +++ b/pkg/rudus.d.ts @@ -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; } diff --git a/pkg/rudus.js b/pkg/rudus.js index 6c2a561..483c42b 100644 --- a/pkg/rudus.js +++ b/pkg/rudus.js @@ -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) { diff --git a/pkg/rudus_bg.wasm b/pkg/rudus_bg.wasm index 825f63d..d7317fa 100644 Binary files a/pkg/rudus_bg.wasm and b/pkg/rudus_bg.wasm differ diff --git a/pkg/rudus_bg.wasm.d.ts b/pkg/rudus_bg.wasm.d.ts index 2d5f3c8..29db78a 100644 --- a/pkg/rudus_bg.wasm.d.ts +++ b/pkg/rudus_bg.wasm.d.ts @@ -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; diff --git a/src/errors.rs b/src/errors.rs index 777bc45..086ced4 100644 --- a/src/errors.rs +++ b/src/errors.rs @@ -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>) -> String { - let mut msg = "Syntax errors".to_string(); +pub fn lexing(errs: Vec>, 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) -> 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); diff --git a/src/lib.rs b/src/lib.rs index 06a3e68..ab8bf89 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -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; }