Skip to content

Commit

Permalink
Add support for SynType.Fun
Browse files Browse the repository at this point in the history
  • Loading branch information
vipentti committed Dec 19, 2023
1 parent a681984 commit c004cb7
Show file tree
Hide file tree
Showing 8 changed files with 898 additions and 825 deletions.
4 changes: 3 additions & 1 deletion src/Visp.Compiler/Parser.fsy
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ let mkRecoveryPat s = Syntax.parserRecoveryPat (lhs s)
%nonassoc prec_syn_type_open


%nonassoc OP_LESS OP_GREATER
%nonassoc OP_LESS OP_GREATER THREAD_FIRST

%nonassoc OP_MULT
%nonassoc COLON
Expand Down Expand Up @@ -1126,6 +1126,8 @@ syn_type:
SynType.Discard(lhs parseState)
else
SynType.Ident(Ident(text, lhs parseState)) }
| syn_type THREAD_FIRST syn_type %prec prec_syn_type_array
{ SynType.Fun ($1, $3, lhs parseState) }
| syn_type arrayTypeSuffixHelp %prec prec_syn_type_array
{ SynType.Array($2, $1, lhs parseState) }
| syn_type OP_LESS syn_type OP_GREATER %prec prec_syn_type_generic
Expand Down
1,659 changes: 836 additions & 823 deletions src/Visp.Compiler/Syntax/FsLexYaccOutput/Parser.fs

Large diffs are not rendered by default.

6 changes: 5 additions & 1 deletion src/Visp.Compiler/Syntax/SynWriter.fs
Original file line number Diff line number Diff line change
Expand Up @@ -514,7 +514,11 @@ module Write =
writeInlineSpaceSeparated w writeSeg segs

()
| SynType.Fun _ -> failwithf "unsupported SynType: %A" typ
| SynType.Fun(arg, ret, _) ->
writeType w arg
string w " -> "
writeType w ret
()

and writeTypeHelp w _ = writeType w

Expand Down
5 changes: 5 additions & 0 deletions tests/Visp.Compiler.UnitTests/ParsingTests.generated.fs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@ module ``tests_dot_dot-shorthands`` =
[<Fact>]
let ``can parse`` () = TestUtils.runTest "tests/dot/dot-shorthands.visp"

[<VerifyXunit.UsesVerify>]
module ``tests_pats_fn-1`` =
[<Fact>]
let ``can parse`` () = TestUtils.runTest "tests/pats/fn-1.visp"

[<VerifyXunit.UsesVerify>]
module ``tests_pats_fn-0`` =
[<Fact>]
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// This file is auto-generated

#nowarn "0020" // unused results from functions

open Visp.Runtime.Library

let state = { Todo = () }
// line 8 @"fn-1.visp"
let WithPred (pred: ('T -> bool)) t =
// line 9 @"fn-1.visp"
pred t

// line 11 @"fn-1.visp"
printfn "WithPred: %A" (WithPred ((fun arg1 ->
// line 11 @"fn-1.visp"
CoreMethods.``eq?``(arg1, 1))) 1)
// line 12 @"fn-1.visp"
printfn "WithPred: %A" (WithPred ((fun arg1 ->
// line 12 @"fn-1.visp"
CoreMethods.``eq?``(arg1, 1))) 0)
// line 14 @"fn-1.visp"
let visp_result_todo = ()
// line 14 @"fn-1.visp"
printfn "%A" visp_result_todo

5 changes: 5 additions & 0 deletions tests/Visp.ExecutionTests/ExecutionTests.generated.fs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@ module ``tests_dot_dot-shorthands`` =
[<Fact>]
let ``can execute`` () = TestUtils.runTest "tests/dot/dot-shorthands.visp"

[<VerifyXunit.UsesVerify>]
module ``tests_pats_fn-1`` =
[<Fact>]
let ``can execute`` () = TestUtils.runTest "tests/pats/fn-1.visp"

[<VerifyXunit.UsesVerify>]
module ``tests_pats_fn-0`` =
[<Fact>]
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
WithPred: true
WithPred: false
()

ExitCode: 0
14 changes: 14 additions & 0 deletions visp/tests/pats/fn-1.visp
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
;; 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:

(fn WithPred ([pred: (^T -> bool)] t)
(pred t))

(printfn "WithPred: %A" (WithPred #(= %1 1) 1))
(printfn "WithPred: %A" (WithPred #(= %1 1) 0))

()

0 comments on commit c004cb7

Please sign in to comment.