Skip to content

Commit

Permalink
Fix attribute argument parsing and support -|| operator as replacemen…
Browse files Browse the repository at this point in the history
…t for ||
  • Loading branch information
vipentti committed Dec 23, 2023
1 parent 1fdff94 commit 432b262
Show file tree
Hide file tree
Showing 12 changed files with 1,795 additions and 1,606 deletions.
11 changes: 7 additions & 4 deletions src/Visp.Compiler/Lexer.fsl
Original file line number Diff line number Diff line change
Expand Up @@ -251,13 +251,15 @@ rule token (args: LexArgs) (skip: bool) = parse
| eof { EOF }

// punct
| "||" { BAR_BAR }
| "-||" { BAR_BAR }
| '(' { LPAREN }
| ')' { RPAREN }
| '{' { LBRACE }
| '}' { RBRACE }
| '[' { LBRACKET }
| ']' { RBRACKET }
| "::" { COLON_COLON }
| "::" { COLON_COLON }
| ':' anyspace+ { COLON }
| ',' { COMMA }
| '|' { BAR }
Expand All @@ -276,8 +278,8 @@ rule token (args: LexArgs) (skip: bool) = parse
| "|}" { BAR_BRACE }
| "[|" { BRACKET_BAR }
| "|]" { BAR_BRACKET }
| "(|" { PAREN_BAR }
| "|)" { BAR_PAREN }
| "(|" { PAREN_BAR }
| "|)" { BAR_PAREN }
| ".." { DOTDOT }
| "'" { QUOTE_SYM }
| ".[" { DOT_BRACKET }
Expand Down Expand Up @@ -430,7 +432,6 @@ rule token (args: LexArgs) (skip: bool) = parse
| ">=" { GREATER_EQUALS }
| "<=" { LESS_EQUALS }
| "&&" { AMP_AMP }
| "||" { BAR_BAR }
| "!=" { BANG_EQUALS }
| '=' { EQUALS }

Expand Down Expand Up @@ -512,6 +513,8 @@ and tokenStream (args: LexArgs) (skip: bool) = parse
| "::" anyspace+ { COLON_COLON }
| ':' anyspace+ { COLON }
| ',' { COMMA }
| "||" { SYMBOL (lexeme lexbuf) }
| "-||" { SYMBOL (lexeme lexbuf) }
| '|' { BAR }
| '.' anyspace+ { DOT }
| "#(" { HASH_PAREN }
Expand Down
6 changes: 4 additions & 2 deletions src/Visp.Compiler/Parser.fsy
Original file line number Diff line number Diff line change
Expand Up @@ -993,8 +993,10 @@ rev_attributes:
| rev_attributes DOT attribute { $3 :: $1 }

attribute:
| syn_type_name expr
{ { TypeName = $1; ArgExpr = $2; Range = lhs parseState } }
| syn_type_name LPAREN expr RPAREN
{ { TypeName = $1; ArgExpr = $3; Range = lhs parseState } }
| syn_type_name LBRACKET expr RBRACKET
{ { TypeName = $1; ArgExpr = $3; Range = lhs parseState } }
| syn_type_name
{ { TypeName = $1; ArgExpr = Syntax.UnitExpr <| lhs parseState; Range = lhs parseState } }

Expand Down
1,567 changes: 795 additions & 772 deletions src/Visp.Compiler/Syntax/FsLexYaccOutput/Lexer.fs

Large diffs are not rendered by default.

1,669 changes: 841 additions & 828 deletions src/Visp.Compiler/Syntax/FsLexYaccOutput/Parser.fs

Large diffs are not rendered by default.

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

[<VerifyXunit.UsesVerify>]
module ``tests_type_record-4`` =
[<Fact>]
let ``can parse`` () = TestUtils.runTest "tests/type/record-4.visp"

[<VerifyXunit.UsesVerify>]
module ``tests_functions_apply-method-args-0`` =
[<Fact>]
Expand Down Expand Up @@ -150,6 +155,11 @@ module ``tests_parsing_props`` =
[<Fact>]
let ``can parse`` () = TestUtils.runTest "tests/parsing/props.visp"

[<VerifyXunit.UsesVerify>]
module ``tests_parsing_operators-0`` =
[<Fact>]
let ``can parse`` () = TestUtils.runTest "tests/parsing/operators-0.visp"

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

#nowarn "0020" // unused results from functions

open Visp.Runtime.Library

let state = { Todo = () }
// line 8 @"operators-0.visp"
let OrTest a b =
// line 8 @"operators-0.visp"
a || b

// line 9 @"operators-0.visp"
let AndTest a b =
// line 9 @"operators-0.visp"
a && b

// line 11 @"operators-0.visp"
printfn "OrTest %A" (OrTest false false)
// line 12 @"operators-0.visp"
printfn "OrTest %A" (OrTest false true)
// line 13 @"operators-0.visp"
printfn "OrTest %A" (OrTest true false)
// line 14 @"operators-0.visp"
printfn "OrTest %A" (OrTest true true)
// line 16 @"operators-0.visp"
printfn "AndTest %A" (AndTest false false)
// line 17 @"operators-0.visp"
printfn "AndTest %A" (AndTest false true)
// line 18 @"operators-0.visp"
printfn "AndTest %A" (AndTest true false)
// line 19 @"operators-0.visp"
let visp_result_todo =
// line 19 @"operators-0.visp"
printfn "AndTest %A" (AndTest true true)
// line 19 @"operators-0.visp"
printfn "%A" visp_result_todo

Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
// This file is auto-generated

#nowarn "0020" // unused results from functions

open Visp.Runtime.Library

let state = { Todo = () }
[<StructuredFormatDisplay"{Structuredtext}">]
// line 8 @"record-4.visp"
type TestRec =
{ value: int }
// line 12 @"record-4.visp"
member t.Structuredtext =
// line 12 @"record-4.visp"
t.ToString()
// line 14 @"record-4.visp"
override t.ToString () =
// line 14 @"record-4.visp"
sprintf "TestRec(%i)" ((t.value))

// line 19 @"record-4.visp"
printfn "%A" ({
// line 19 @"record-4.visp"
value = 99
})
// line 20 @"record-4.visp"
let visp_result_todo =
// line 20 @"record-4.visp"
printfn "%A" ({
// line 20 @"record-4.visp"
value = 1
})
// line 20 @"record-4.visp"
printfn "%A" visp_result_todo

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

[<VerifyXunit.UsesVerify>]
module ``tests_type_record-4`` =
[<Fact>]
let ``can execute`` () = TestUtils.runTest "tests/type/record-4.visp"

[<VerifyXunit.UsesVerify>]
module ``tests_functions_apply-method-args-0`` =
[<Fact>]
Expand Down Expand Up @@ -150,6 +155,11 @@ module ``tests_parsing_props`` =
[<Fact>]
let ``can execute`` () = TestUtils.runTest "tests/parsing/props.visp"

[<VerifyXunit.UsesVerify>]
module ``tests_parsing_operators-0`` =
[<Fact>]
let ``can execute`` () = TestUtils.runTest "tests/parsing/operators-0.visp"

[<VerifyXunit.UsesVerify>]
module ``tests_parsing_call-tuple-args-0`` =
[<Fact>]
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
OrTest false
OrTest true
OrTest true
OrTest true
AndTest false
AndTest false
AndTest false
AndTest true
()

ExitCode: 0
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
TestRec(99)
TestRec(1)
()

ExitCode: 0
19 changes: 19 additions & 0 deletions visp/tests/parsing/operators-0.visp
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
;; 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 OrTest (a b) (-|| a b))
(fn AndTest (a b) (&& a b))

(printfn "OrTest %A" (OrTest false false))
(printfn "OrTest %A" (OrTest false true))
(printfn "OrTest %A" (OrTest true false))
(printfn "OrTest %A" (OrTest true true))

(printfn "AndTest %A" (AndTest false false))
(printfn "AndTest %A" (AndTest false true))
(printfn "AndTest %A" (AndTest true false))
(printfn "AndTest %A" (AndTest true true))
20 changes: 20 additions & 0 deletions visp/tests/type/record-4.visp
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
;; 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:

(#[StructuredFormatDisplay("{Structuredtext}")]
record TestRec
[value: int]

(member t.Structuredtext (.ToString t))

(override fn t.ToString() (sprintf "TestRec(%i)" (+value t)))
)



(printfn "%A" {| [value 99] |})
(printfn "%A" {| [value 1] |})

0 comments on commit 432b262

Please sign in to comment.