diff --git a/src/Visp.Compiler/Syntax/LexHelpers.fs b/src/Visp.Compiler/Syntax/LexHelpers.fs index 5e05a86..4ac3580 100644 --- a/src/Visp.Compiler/Syntax/LexHelpers.fs +++ b/src/Visp.Compiler/Syntax/LexHelpers.fs @@ -468,7 +468,7 @@ let symbolOrKeywordToken (args: LexArgs) (lexbuf: FSharp.Text.Lexing.LexBuffer<_ filename |> System.IO.Path.GetFullPath |> System.IO.Path.GetDirectoryName let dirname = - if Syntax.SyntaxWriteUtilThreadStatics.NormalizeLineEndings then + if Syntax.SyntaxWriteUtilThreadStatics.RunningTests then dirname.Replace('\\', '/') else dirname diff --git a/src/Visp.Compiler/Syntax/Syntax.fs b/src/Visp.Compiler/Syntax/Syntax.fs index c92f79b..f1403b5 100644 --- a/src/Visp.Compiler/Syntax/Syntax.fs +++ b/src/Visp.Compiler/Syntax/Syntax.fs @@ -113,11 +113,11 @@ type SynStringKind = type SyntaxWriteUtilThreadStatics = [] - static val mutable private normalizeLineEndings: bool + static val mutable private runningTests: bool - static member NormalizeLineEndings - with get () = SyntaxWriteUtilThreadStatics.normalizeLineEndings - and set v = SyntaxWriteUtilThreadStatics.normalizeLineEndings <- v + static member RunningTests + with get () = SyntaxWriteUtilThreadStatics.runningTests + and set v = SyntaxWriteUtilThreadStatics.runningTests <- v module StringWriterUtils = let inline writeDebugStringType (name: string) (text: string) kind range = @@ -129,7 +129,7 @@ module StringWriterUtils = for ch in text do match ch with - | '\r' when SyntaxWriteUtilThreadStatics.NormalizeLineEndings -> () + | '\r' when SyntaxWriteUtilThreadStatics.RunningTests -> () | it -> ignore (sb.Append it) sb.Append "\", " |> ignore @@ -184,7 +184,14 @@ type SynConst = | Char it -> sprintf "Char %A" it | Decimal it -> sprintf "Decimal %A" it | UserNum(va, su) -> sprintf "UserNum (%s, %s)" va su - | SourceIdentifier(va, su, _) -> sprintf "SourceIdentifier (%s, %s)" va su + | SourceIdentifier(va, su, _) -> + if SyntaxWriteUtilThreadStatics.RunningTests then + match va with + | "__SOURCE_DIRECTORY__" -> + sprintf "SourceIdentifier (\"%s\", \"%s\")" va (System.IO.Path.GetFileName su) + | _ -> sprintf "SourceIdentifier (\"%s\", \"%s\")" va su + else + sprintf "SourceIdentifier (%s, %s)" va su | String(text, k, r) -> StringWriterUtils.writeDebugStringType "String" text k r type SynTyped = SynTyped of name: SynSymbol * argtype: SynType * range: range diff --git a/tests/Visp.Compiler.UnitTests/TestUtils.fs b/tests/Visp.Compiler.UnitTests/TestUtils.fs index b2c136d..205c097 100644 --- a/tests/Visp.Compiler.UnitTests/TestUtils.fs +++ b/tests/Visp.Compiler.UnitTests/TestUtils.fs @@ -52,7 +52,7 @@ let runTokenTest (name: string) = try let parsed = CoreParser.debugLexFile path let nameParam = name.Replace('/', '_').Replace('\\', '_') - Syntax.SyntaxWriteUtilThreadStatics.NormalizeLineEndings <- true + Syntax.SyntaxWriteUtilThreadStatics.RunningTests <- true let output = parsed |> String.concat "\n" return! verify output "token-snapshots" nameParam with :? ParseHelpers.SyntaxError as syn -> @@ -69,7 +69,7 @@ let runStructuredOutputTest (name: string) = let nameParam = name.Replace('/', '_').Replace('\\', '_') - Syntax.SyntaxWriteUtilThreadStatics.NormalizeLineEndings <- true + Syntax.SyntaxWriteUtilThreadStatics.RunningTests <- true let output = (sprintf "%120A" parsed).Replace("\\r\\n", "\\n").Replace("\r\n", "\n") diff --git a/tests/Visp.Compiler.UnitTests/parsing-snapshots/tests_parsing_keyword-strings-0.structured output.verified.txt b/tests/Visp.Compiler.UnitTests/parsing-snapshots/tests_parsing_keyword-strings-0.structured output.verified.txt index ce21a7b..7756d7e 100644 --- a/tests/Visp.Compiler.UnitTests/parsing-snapshots/tests_parsing_keyword-strings-0.structured output.verified.txt +++ b/tests/Visp.Compiler.UnitTests/parsing-snapshots/tests_parsing_keyword-strings-0.structured output.verified.txt @@ -6,17 +6,15 @@ [FunctionCall (Symbol (SynSymbol printfn), [Const (String ("Line: %s", Regular, (9,13--9,23)), (9,13--9,23)); - Const (SourceIdentifier (__LINE__, 9), (9,24--9,32))], (9,5--9,32)); + Const (SourceIdentifier ("__LINE__", "9"), (9,24--9,32))], (9,5--9,32)); FunctionCall (Symbol (SynSymbol printfn), [Const (String ("Source Directory: %s", Regular, (10,13--10,35)), (10,13--10,35)); - Const - (SourceIdentifier (__SOURCE_DIRECTORY__, {SolutionDirectory}visp/tests/parsing), - (10,36--10,56))], (10,5--10,56)); + Const (SourceIdentifier ("__SOURCE_DIRECTORY__", "parsing"), (10,36--10,56))], (10,5--10,56)); FunctionCall (Symbol (SynSymbol printfn), [Const (String ("Source File: %s", Regular, (11,13--11,30)), (11,13--11,30)); - Const (SourceIdentifier (__SOURCE_FILE__, keyword-strings-0.visp), (11,31--11,46))], (11,5--11,46))], + Const (SourceIdentifier ("__SOURCE_FILE__", "keyword-strings-0.visp"), (11,31--11,46))], (11,5--11,46))], None, (8,1--11,47)), (8,0--12,1)); Expr (LetOrUse