Skip to content

Commit

Permalink
Count span horizontal position from 1
Browse files Browse the repository at this point in the history
  • Loading branch information
shsms committed Nov 11, 2023
1 parent 5bc8b89 commit c32fcd1
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 29 deletions.
4 changes: 2 additions & 2 deletions src/parse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ impl Tokenizer<'_> {
file_id,
chars,
line: 1,
pos: 0,
pos: 1,
}
}

Expand All @@ -73,7 +73,7 @@ impl Tokenizer<'_> {
self.chars.next().map(|ch| {
if ch == '\n' {
self.line += 1;
self.pos = 0;
self.pos = 1;
} else {
self.pos += 1;
}
Expand Down
54 changes: 27 additions & 27 deletions tests/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ fn test_comparison_of_numbers() -> Result<(), Error> {
tulisp_assert! { program: "(> 5.0 10.0)", result: "nil" }
tulisp_assert! {
program: "(let ((a 10)) (> a))",
error: "<eval_string>:1.14-1.19: ERR OutOfRange: gt requires at least 2 arguments"
error: "<eval_string>:1.15-1.20: ERR OutOfRange: gt requires at least 2 arguments"
}

// Greater than or equal
Expand All @@ -80,7 +80,7 @@ fn test_comparison_of_numbers() -> Result<(), Error> {
tulisp_assert! { program: "(>= 5.0 10.0)", result: "nil" }
tulisp_assert! {
program: "(let ((a 10)) (>= a))",
error: "<eval_string>:1.14-1.20: ERR OutOfRange: ge requires at least 2 arguments"
error: "<eval_string>:1.15-1.21: ERR OutOfRange: ge requires at least 2 arguments"
}

// Less than
Expand All @@ -95,7 +95,7 @@ fn test_comparison_of_numbers() -> Result<(), Error> {
tulisp_assert! { program: "(< 5.0 10.0)", result: "t" }
tulisp_assert! {
program: "(let ((a 10)) (< a))",
error: "<eval_string>:1.14-1.19: ERR OutOfRange: lt requires at least 2 arguments"
error: "<eval_string>:1.15-1.20: ERR OutOfRange: lt requires at least 2 arguments"
}

// Less than or equal
Expand All @@ -110,7 +110,7 @@ fn test_comparison_of_numbers() -> Result<(), Error> {
tulisp_assert! { program: "(<= 5.0 10.0)", result: "t" }
tulisp_assert! {
program: "(let ((a 10)) (<= a))",
error: "<eval_string>:1.14-1.20: ERR OutOfRange: le requires at least 2 arguments"
error: "<eval_string>:1.15-1.21: ERR OutOfRange: le requires at least 2 arguments"
}

Ok(())
Expand Down Expand Up @@ -283,7 +283,7 @@ fn test_defun() -> Result<(), Error> {
}
tulisp_assert! {
program: "(defun j (&rest x y) nil) (j)",
error: "<eval_string>:1.18-1.19: ERR TypeMismatch: Too many &rest parameters",
error: "<eval_string>:1.19-1.20: ERR TypeMismatch: Too many &rest parameters",
}
tulisp_assert! {
program: r##"(defun j (&rest x) x) (list (j) (j 10) (j 100 200))"##,
Expand All @@ -303,11 +303,11 @@ fn test_defun() -> Result<(), Error> {
}
tulisp_assert! {
program: "(defun add (x y) (+ x y)) (add 10)",
error: "<eval_string>:1.26-1.34: ERR TypeMismatch: Too few arguments",
error: "<eval_string>:1.27-1.35: ERR TypeMismatch: Too few arguments",
}
tulisp_assert! {
program: "(defun add (x y) (+ x y)) (add 10 20 30)",
error: "<eval_string>:1.37-1.39: ERR TypeMismatch: Too many arguments",
error: "<eval_string>:1.38-1.40: ERR TypeMismatch: Too many arguments",
}
tulisp_assert! {
program: "(defmacro num () 4) (macroexpand '(num))",
Expand All @@ -329,11 +329,11 @@ fn test_defun() -> Result<(), Error> {
}
tulisp_assert! {
program: "(defmacro inc (var) (list 'setq var (list '+ 1 var))) (let ((x 4)) (inc))",
error: "<eval_string>:1.68-1.73: ERR TypeMismatch: Too few arguments",
error: "<eval_string>:1.69-1.74: ERR TypeMismatch: Too few arguments",
}
tulisp_assert! {
program: "(defmacro inc (var) (list 'setq var (list '+ 1 var))) (let ((x 4)) (inc 4 5))",
error: "<eval_string>:1.75-1.76: ERR TypeMismatch: Too many arguments",
error: "<eval_string>:1.76-1.77: ERR TypeMismatch: Too many arguments",
}
tulisp_assert! {
program: r##"
Expand Down Expand Up @@ -416,11 +416,11 @@ fn test_eval() -> Result<(), Error> {
}
tulisp_assert! {
program: "(let ((y j) (j 10)) (funcall j))",
error: "<eval_string>:1.9-1.10: ERR TypeMismatch: Variable definition is void: j",
error: "<eval_string>:1.10-1.11: ERR TypeMismatch: Variable definition is void: j",
}
tulisp_assert! {
program: "(let ((j 10)) (+ j j))(+ j j)",
error: "<eval_string>:1.25-1.26: ERR TypeMismatch: Variable definition is void: j",
error: "<eval_string>:1.26-1.27: ERR TypeMismatch: Variable definition is void: j",
}
Ok(())
}
Expand All @@ -429,7 +429,7 @@ fn test_eval() -> Result<(), Error> {
fn test_strings() -> Result<(), Error> {
tulisp_assert! {
program: r##"(concat 'hello 'world)"##,
error: "<eval_string>:1.0-1.22: ERR TypeMismatch: Not a string: hello"
error: "<eval_string>:1.1-1.23: ERR TypeMismatch: Not a string: hello"
}
tulisp_assert! { program: r##"(concat "hello" " world")"##, result: r#""hello world""# }
tulisp_assert! {
Expand Down Expand Up @@ -466,11 +466,11 @@ fn test_cons() -> Result<(), Error> {
};
tulisp_assert! {
program: "(cons 1)",
error: "<eval_string>:1.0-1.8: ERR TypeMismatch: cons requires exactly 2 arguments",
error: "<eval_string>:1.1-1.9: ERR TypeMismatch: cons requires exactly 2 arguments",
};
tulisp_assert! {
program: "(cons 1 2 3)",
error: "<eval_string>:1.0-1.12: ERR TypeMismatch: cons requires exactly 2 arguments",
error: "<eval_string>:1.1-1.13: ERR TypeMismatch: cons requires exactly 2 arguments",
};
Ok(())
}
Expand All @@ -487,11 +487,11 @@ fn test_quote() -> Result<(), Error> {
};
tulisp_assert! {
program: "(quote)",
error: "<eval_string>:1.0-1.7: ERR TypeMismatch: quote: expected one argument",
error: "<eval_string>:1.1-1.8: ERR TypeMismatch: quote: expected one argument",
};
tulisp_assert! {
program: "(quote 1 2)",
error: "<eval_string>:1.0-1.11: ERR TypeMismatch: quote: expected one argument",
error: "<eval_string>:1.1-1.12: ERR TypeMismatch: quote: expected one argument",
};
Ok(())
}
Expand Down Expand Up @@ -543,7 +543,7 @@ fn test_lists() -> Result<(), Error> {
(setq items
(append items '(10)))
"#,
error: "<eval_string>:3.22-3.27: ERR TypeMismatch: Variable definition is void: items",
error: "<eval_string>:3.23-3.28: ERR TypeMismatch: Variable definition is void: items",
}

tulisp_assert! {
Expand Down Expand Up @@ -628,15 +628,15 @@ fn test_lists() -> Result<(), Error> {
fn test_math() -> Result<(), Error> {
tulisp_assert! {
program: "(/ 10 0)",
error: "<eval_string>:1.0-1.8: ERR Undefined: Division by zero",
error: "<eval_string>:1.1-1.9: ERR Undefined: Division by zero",
}
tulisp_assert! {
program: "(/ 0 10)",
result: "0",
}
tulisp_assert! {
program: "(let ((a 10) (b 0)) (/ a b))",
error: "<eval_string>:1.20-1.27: ERR Undefined: Division by zero",
error: "<eval_string>:1.21-1.28: ERR Undefined: Division by zero",
}

tulisp_assert! { program: "(/ 24 2 2)", result: "6" }
Expand Down Expand Up @@ -680,15 +680,15 @@ fn test_let() -> Result<(), Error> {
(jj 20))
(append kk (+ vv jj 1)))
"#,
error: "<eval_string>:4.18-4.20: ERR TypeMismatch: Variable definition is void: kk",
error: "<eval_string>:4.19-4.21: ERR TypeMismatch: Variable definition is void: kk",
}
tulisp_assert! {
program: "(let ((22 (+ 55 1)) (jj 20)) (+ vv jj 1))",
error: "<eval_string>:1.7-1.9: ERR TypeMismatch: Expected Symbol: Can't assign to 22",
error: "<eval_string>:1.8-1.10: ERR TypeMismatch: Expected Symbol: Can't assign to 22",
}
tulisp_assert! {
program: "(let (18 (vv (+ 55 1)) (jj 20)) (+ vv jj 1))",
error: "<eval_string>:1.5-1.31: ERR SyntaxError: varitems inside a let-varlist should be a var or a binding: 18",
error: "<eval_string>:1.6-1.32: ERR SyntaxError: varitems inside a let-varlist should be a var or a binding: 18",
}

tulisp_assert! {
Expand Down Expand Up @@ -772,7 +772,7 @@ fn test_sort() -> Result<(), Error> {
}
tulisp_assert! {
program: "(sort '(20 10 30 15 45) '<<)",
error: "<eval_string>:1.25-1.27: ERR TypeMismatch: Variable definition is void: <<",
error: "<eval_string>:1.26-1.28: ERR TypeMismatch: Variable definition is void: <<",
}
tulisp_assert! {
program: "(defun << (v1 v2) (> v1 v2)) (sort '(20 10 30 15 45) '<<)",
Expand Down Expand Up @@ -955,12 +955,12 @@ fn test_typed_iter() -> Result<(), Error> {
tulisp_assert! {
ctx: ctx,
program: "(add_ints_no_default 20)",
error: "<eval_string>:1.21-1.23: ERR TypeMismatch: In call to \"add_ints_no_default\", arg \"ints\" needs to be a list",
error: "<eval_string>:1.22-1.24: ERR TypeMismatch: In call to \"add_ints_no_default\", arg \"ints\" needs to be a list",
}
tulisp_assert! {
ctx: ctx,
program: "(add_ints 20)",
error: "<eval_string>:1.10-1.12: ERR TypeMismatch: In call to \"add_ints\", arg \"ints\" needs to be a list",
error: "<eval_string>:1.11-1.13: ERR TypeMismatch: In call to \"add_ints\", arg \"ints\" needs to be a list",
}
Ok(())
}
Expand Down Expand Up @@ -1006,7 +1006,7 @@ fn test_any() -> Result<(), Error> {
tulisp_assert! {
ctx: ctx,
program: "(get_int 55)",
error: "<eval_string>:1.9-1.11: ERR TypeMismatch: Expected Any(Rc<dyn Any>): 55",
error: "<eval_string>:1.10-1.12: ERR TypeMismatch: Expected Any(Rc<dyn Any>): 55",
}
Ok(())
}
Expand All @@ -1024,7 +1024,7 @@ fn test_load() -> Result<(), Error> {
tulisp_assert! {
ctx: ctx,
program: r#"(load "tests/bad-load.lisp")"#,
error: "tests/bad-load.lisp:1.8-1.9: ERR ParsingError: Unexpected closing parenthesis",
error: "tests/bad-load.lisp:1.9-1.10: ERR ParsingError: Unexpected closing parenthesis",
}

Ok(())
Expand Down

0 comments on commit c32fcd1

Please sign in to comment.