diff --git a/src/Visp.Compiler/Syntax/LexHelpers.fs b/src/Visp.Compiler/Syntax/LexHelpers.fs index 560fa4d..7bd1f0d 100644 --- a/src/Visp.Compiler/Syntax/LexHelpers.fs +++ b/src/Visp.Compiler/Syntax/LexHelpers.fs @@ -241,6 +241,10 @@ let specialSymbol (s: string) = | it when it.Length > 1 && it[0] = '+' && isLetter it[1] -> Some(PROP_PLUS s) | it when it.Length > 1 && it[0] = '.' && isLetter it[1] -> Some(DOT_METHOD s) | it when it.Length > 1 && it[0] = '-' && isLetter it[1] -> Some(APPLY_METHOD s) + | "+" -> Some(OP_PLUS) + | "-" -> Some(OP_MINUS) + | "/" -> Some(OP_DIV) + | "*" -> Some(OP_MULT) | _ -> None let symbolOrKeyword (s: string) = diff --git a/tests/Visp.Compiler.UnitTests/ParsingTests.generated.fs b/tests/Visp.Compiler.UnitTests/ParsingTests.generated.fs index bc75800..bbb93a6 100644 --- a/tests/Visp.Compiler.UnitTests/ParsingTests.generated.fs +++ b/tests/Visp.Compiler.UnitTests/ParsingTests.generated.fs @@ -195,6 +195,11 @@ module ``tests_macros_struct-example-1`` = [] let ``can parse`` () = TestUtils.runTest "tests/macros/struct-example-1.visp" +[] +module ``tests_macros_count-exprs-0`` = + [] + let ``can parse`` () = TestUtils.runTest "tests/macros/count-exprs-0.visp" + [] module ``tests_macros_syntax-macro-2`` = [] diff --git a/tests/Visp.Compiler.UnitTests/snapshots/tests_macros_count-exprs-0.can parse.verified.txt b/tests/Visp.Compiler.UnitTests/snapshots/tests_macros_count-exprs-0.can parse.verified.txt new file mode 100644 index 0000000..79673d7 --- /dev/null +++ b/tests/Visp.Compiler.UnitTests/snapshots/tests_macros_count-exprs-0.can parse.verified.txt @@ -0,0 +1,26 @@ +// This file is auto-generated + +#nowarn "0020" // unused results from functions + +open Visp.Runtime.Library + +let state = { Todo = () } +// line 8 @"count-exprs-0.visp" +let macro_CountExprsExampleTest1 = "__MACRO_INIT__" +// line 15 @"count-exprs-0.visp" +let exprCount = + // line 15 @"count-exprs-0.visp" + (1) + + ((1) + + ((1) + + ((1) + + ((1) + + ((1) + + (1)))))) +// line 17 @"count-exprs-0.visp" +let visp_result_todo = + // line 17 @"count-exprs-0.visp" + printfn ("exprs: %A") (exprCount) +// line 17 @"count-exprs-0.visp" +printfn ("%A") (visp_result_todo) + diff --git a/tests/Visp.Compiler.UnitTests/snapshots/tests_macros_struct-example-1.can parse.verified.txt b/tests/Visp.Compiler.UnitTests/snapshots/tests_macros_struct-example-1.can parse.verified.txt index 407b808..3b91dde 100644 --- a/tests/Visp.Compiler.UnitTests/snapshots/tests_macros_struct-example-1.can parse.verified.txt +++ b/tests/Visp.Compiler.UnitTests/snapshots/tests_macros_struct-example-1.can parse.verified.txt @@ -17,11 +17,12 @@ type Range (start: int64, len: int64) = // line 8 @"struct-example-1.visp" member _.End = // line 8 @"struct-example-1.visp" - CoreMethods.``add``(start, len) + (start) + + (len) // line 8 @"struct-example-1.visp" member d.Offset v = // line 8 @"struct-example-1.visp" - CoreMethods.``sub``(v, (d.Start)) + v - (d.Start) // line 8 @"struct-example-1.visp" member d.Contains v = @@ -78,13 +79,14 @@ type SourceDestMap (dest: int64, src: int64, len: int64) = ((d.Src).Contains src)) then // line 29 @"struct-example-1.visp" - CoreMethods.``add``(d + (d |> (fun a1 -> // line 29 @"struct-example-1.visp" (a1.Dest)) |> (fun a1 -> // line 29 @"struct-example-1.visp" - (a1.Start)), ((d.Src).Offset src)) + (a1.Start))) + + (((d.Src).Offset src)) else // line 29 @"struct-example-1.visp" if CoreMethods.isTruthy( diff --git a/tests/Visp.Compiler.UnitTests/snapshots/tests_macros_struct-macro-0.can parse.verified.txt b/tests/Visp.Compiler.UnitTests/snapshots/tests_macros_struct-macro-0.can parse.verified.txt index 5a0de22..0c1851e 100644 --- a/tests/Visp.Compiler.UnitTests/snapshots/tests_macros_struct-macro-0.can parse.verified.txt +++ b/tests/Visp.Compiler.UnitTests/snapshots/tests_macros_struct-macro-0.can parse.verified.txt @@ -19,7 +19,8 @@ type Example (x: int, y: int) = // line 16 @"struct-macro-0.visp" member d.Sum () = // line 16 @"struct-macro-0.visp" - CoreMethods.``add``((d.X), (d.Y)) + ((d.X)) + + ((d.Y)) // line 22 @"struct-macro-0.visp" let instance = diff --git a/tests/Visp.Compiler.UnitTests/snapshots/tests_macros_struct-macro-2.can parse.verified.txt b/tests/Visp.Compiler.UnitTests/snapshots/tests_macros_struct-macro-2.can parse.verified.txt index 51fe013..a4f9701 100644 --- a/tests/Visp.Compiler.UnitTests/snapshots/tests_macros_struct-macro-2.can parse.verified.txt +++ b/tests/Visp.Compiler.UnitTests/snapshots/tests_macros_struct-macro-2.can parse.verified.txt @@ -21,7 +21,8 @@ type Example (x: int, y: int) = // line 22 @"struct-macro-2.visp" member d.Sum () = // line 22 @"struct-macro-2.visp" - CoreMethods.``add``((d.X), (d.Y)) + ((d.X)) + + ((d.Y)) // line 22 @"struct-macro-2.visp" let mkExample x y = diff --git a/tests/Visp.Compiler.UnitTests/snapshots/tests_macros_syntax-macro-0.can parse.verified.txt b/tests/Visp.Compiler.UnitTests/snapshots/tests_macros_syntax-macro-0.can parse.verified.txt index 018e60e..0e9a137 100644 --- a/tests/Visp.Compiler.UnitTests/snapshots/tests_macros_syntax-macro-0.can parse.verified.txt +++ b/tests/Visp.Compiler.UnitTests/snapshots/tests_macros_syntax-macro-0.can parse.verified.txt @@ -15,7 +15,8 @@ let name arg = match arg with | (a, b) -> // line 21 @"syntax-macro-0.visp" - CoreMethods.``add``(a, b) + (a) + + (b) | _ -> 0 diff --git a/tests/Visp.Compiler.UnitTests/snapshots/tests_macros_syntax-macro-2.can parse.verified.txt b/tests/Visp.Compiler.UnitTests/snapshots/tests_macros_syntax-macro-2.can parse.verified.txt index 15aa384..6c2cd9a 100644 --- a/tests/Visp.Compiler.UnitTests/snapshots/tests_macros_syntax-macro-2.can parse.verified.txt +++ b/tests/Visp.Compiler.UnitTests/snapshots/tests_macros_syntax-macro-2.can parse.verified.txt @@ -17,14 +17,16 @@ let lambda = match arg with | (a , b) -> // line 28 @"syntax-macro-2.visp" - CoreMethods.``add``(a, b)) + (a) + + (b)) // line 29 @"syntax-macro-2.visp" let named arg = // line 29 @"syntax-macro-2.visp" match arg with | (a , b) -> // line 29 @"syntax-macro-2.visp" - CoreMethods.``add``(a, b) + (a) + + (b) // line 32 @"syntax-macro-2.visp" printfn ("lambda: %i") (lambda (1, 2)) diff --git a/tests/Visp.ExecutionTests/ExecutionTests.generated.fs b/tests/Visp.ExecutionTests/ExecutionTests.generated.fs index db0ace0..b1e4045 100644 --- a/tests/Visp.ExecutionTests/ExecutionTests.generated.fs +++ b/tests/Visp.ExecutionTests/ExecutionTests.generated.fs @@ -195,6 +195,11 @@ module ``tests_macros_struct-example-1`` = [] let ``can execute`` () = TestUtils.runTest "tests/macros/struct-example-1.visp" +[] +module ``tests_macros_count-exprs-0`` = + [] + let ``can execute`` () = TestUtils.runTest "tests/macros/count-exprs-0.visp" + [] module ``tests_macros_syntax-macro-2`` = [] diff --git a/tests/Visp.ExecutionTests/snapshots/tests_macros_count-exprs-0.can execute.verified.txt b/tests/Visp.ExecutionTests/snapshots/tests_macros_count-exprs-0.can execute.verified.txt new file mode 100644 index 0000000..154b77e --- /dev/null +++ b/tests/Visp.ExecutionTests/snapshots/tests_macros_count-exprs-0.can execute.verified.txt @@ -0,0 +1,4 @@ +exprs: 7 +() + +ExitCode: 0 diff --git a/visp/tests/macros/count-exprs-0.visp b/visp/tests/macros/count-exprs-0.visp new file mode 100644 index 0000000..7073643 --- /dev/null +++ b/visp/tests/macros/count-exprs-0.visp @@ -0,0 +1,17 @@ +;; Copyright 2023 Ville Penttinen +;; Distributed under the MIT License. +;; https://github.com/vipentti/visp-fs/blob/main/LICENSE.md +;; +;; for basic syntax highlighting +;; vim: set syntax=clojure: + +(syntax-macro CountExprsExampleTest1 + [(_) 0] + [(_ _) 1] + [(_ head tail ...) + (+ 1 (CountExprsExampleTest1 tail ...))] +) + +(let exprCount (CountExprsExampleTest1 [] [] [] [] [] [] [])) + +(printfn "exprs: %A" exprCount)