Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add structured output tests #32

Merged
merged 6 commits into from
Dec 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .github/workflows/pull-request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ on:
- develop

jobs:
windows-latest:
name: windows-latest
runs-on: windows-latest
windows-2019:
name: windows-2019
runs-on: windows-2019
steps:
- uses: actions/checkout@v3
- name: Setup dotnet
Expand Down
2 changes: 1 addition & 1 deletion build/Build.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

[ExtendedGitHubActions(
"pull-request",
GitHubActionsImage.WindowsLatest,
GitHubActionsImage.WindowsServer2019,
GitHubActionsImage.UbuntuLatest,
GitHubActionsImage.MacOsLatest,
OnPullRequestBranches = [ MainBranch, DevelopBranch ],
Expand Down
49 changes: 47 additions & 2 deletions src/Visp.Compiler/Syntax/Syntax.fs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@

namespace rec Visp.Compiler.Syntax

open Visp.Compiler.Writer
open Visp.Compiler.Text
open System.Diagnostics
open Visp.Common

[<Struct; NoEquality; NoComparison; DebuggerDisplay("{idText}({idRange})")>]
type Ident(text: string, range: range) =
Expand Down Expand Up @@ -111,7 +111,15 @@ type SynStringKind =
| Interpolated of plain: int
| InterpolatedTripleQuote of triple: int

[<NoEquality; NoComparison; RequireQualifiedAccess>]
type SyntaxWriteUtilThreadStatics =
[<System.ThreadStatic; DefaultValue>]
static val mutable private normalizeLineEndings: bool

static member NormalizeLineEndings
with get () = SyntaxWriteUtilThreadStatics.normalizeLineEndings
and set v = SyntaxWriteUtilThreadStatics.normalizeLineEndings <- v

[<NoEquality; NoComparison; RequireQualifiedAccess; StructuredFormatDisplay("{StructuredText}")>]
type SynConst =
| Unit
| Nil
Expand All @@ -132,6 +140,43 @@ type SynConst =
| Decimal of System.Decimal
| String of text: string * synStringKind: SynStringKind * range: range

member t.StructuredText =
match t with
| Unit -> "Unit"
| Nil -> "Nil"
| Bool it -> sprintf "Bool %A" it
| SByte it -> sprintf "SByte %A" it
| Byte it -> sprintf "Byte %A" it
| Int16 it -> sprintf "Int16 %A" it
| UInt16 it -> sprintf "UInt16 %A" it
| UInt32 it -> sprintf "UInt32 %A" it
| UInt64 it -> sprintf "UInt64 %A" it
| IntPtr it -> sprintf "IntPtr %A" it
| UIntPtr it -> sprintf "UIntPtr %A" it
| Single it -> sprintf "Single %A" it
| Double it -> sprintf "Double %A" it
| Int64 it -> sprintf "Int64 %A" it
| Int32 it -> sprintf "Int32 %A" it
| Char it -> sprintf "Char %A" it
| Decimal it -> sprintf "Decimal %A" it
| String(text, k, r) ->
let sb = PooledStringBuilder.Get()
sb.Append "String (\"" |> ignore

for ch in text do
match ch with
| '\r' when SyntaxWriteUtilThreadStatics.NormalizeLineEndings -> ()
| it -> ignore (sb.Append it)

sb.Append "\", " |> ignore
sb.Append(sprintf "%A" k) |> ignore
sb.Append(", ") |> ignore
sb.Append(sprintf "%A" r) |> ignore

sb.Append ")" |> ignore

sb.ToStringAndReturn()

type SynTyped = SynTyped of name: SynSymbol * argtype: SynType * range: range

[<NoComparison; RequireQualifiedAccess>]
Expand Down
Loading