From b507fbf909d8f5154f316cfa2d805a5c9afb2460 Mon Sep 17 00:00:00 2001 From: Ville Penttinen Date: Tue, 26 Dec 2023 16:01:16 +0100 Subject: [PATCH] Normalize SOURCE_DIRECTORY in tests and specify custom debugToken for KEYWORD_STRING token --- src/Visp.Compiler/ParseUtils.fs | 1 + src/Visp.Compiler/Syntax/LexHelpers.fs | 18 +++++++++++++----- tests/Visp.Compiler.UnitTests/Program.fs | 2 -- ...yword-strings-0.returns tokens.verified.txt | 3 +-- 4 files changed, 15 insertions(+), 9 deletions(-) diff --git a/src/Visp.Compiler/ParseUtils.fs b/src/Visp.Compiler/ParseUtils.fs index edc8df8..4ffe300 100644 --- a/src/Visp.Compiler/ParseUtils.fs +++ b/src/Visp.Compiler/ParseUtils.fs @@ -137,6 +137,7 @@ let debugTokenOutput args (lexbuf: LexBuffer<_>) = function | STRING(text, kind, cont) -> Syntax.StringWriterUtils.writeDebugStringType "STRING" text kind cont + | KEYWORD_STRING(lhs, rhs) -> sprintf "KEYWORD_STRING (\"%s\", \"%s\")" lhs rhs | it -> sprintf "%A" it seq { diff --git a/src/Visp.Compiler/Syntax/LexHelpers.fs b/src/Visp.Compiler/Syntax/LexHelpers.fs index 77b8d02..5e05a86 100644 --- a/src/Visp.Compiler/Syntax/LexHelpers.fs +++ b/src/Visp.Compiler/Syntax/LexHelpers.fs @@ -461,11 +461,19 @@ let symbolOrKeywordToken (args: LexArgs) (lexbuf: FSharp.Text.Lexing.LexBuffer<_ | "__SOURCE_DIRECTORY__" -> let filename = lexbuf.StartPos.FileName - if String.IsNullOrWhiteSpace(filename) then - String.Empty - else - filename |> System.IO.Path.GetFullPath |> System.IO.Path.GetDirectoryName - |> fun dir -> KEYWORD_STRING(s, dir) + let dirname = + if String.IsNullOrWhiteSpace(filename) then + String.Empty + else + filename |> System.IO.Path.GetFullPath |> System.IO.Path.GetDirectoryName + + let dirname = + if Syntax.SyntaxWriteUtilThreadStatics.NormalizeLineEndings then + dirname.Replace('\\', '/') + else + dirname + + dirname |> fun dir -> KEYWORD_STRING(s, dir) | it -> if args.IsTokenStreamMode then match s with diff --git a/tests/Visp.Compiler.UnitTests/Program.fs b/tests/Visp.Compiler.UnitTests/Program.fs index 29dbee1..10b4dee 100644 --- a/tests/Visp.Compiler.UnitTests/Program.fs +++ b/tests/Visp.Compiler.UnitTests/Program.fs @@ -2,8 +2,6 @@ // Distributed under the MIT License. // https://github.com/vipentti/visp-fs/blob/main/LICENSE.md -open VerifyTests - module Program = [] let main _ = 0 diff --git a/tests/Visp.Compiler.UnitTests/token-snapshots/tests_parsing_keyword-strings-0.returns tokens.verified.txt b/tests/Visp.Compiler.UnitTests/token-snapshots/tests_parsing_keyword-strings-0.returns tokens.verified.txt index ff26058..f9c2dba 100644 --- a/tests/Visp.Compiler.UnitTests/token-snapshots/tests_parsing_keyword-strings-0.returns tokens.verified.txt +++ b/tests/Visp.Compiler.UnitTests/token-snapshots/tests_parsing_keyword-strings-0.returns tokens.verified.txt @@ -11,8 +11,7 @@ RPAREN Default 0 1 LParen LPAREN Default 0 2 LParen SYMBOL "printfn" Default 0 2 LParen STRING ("Source Directory: %s", Regular, Token []) Default 0 2 LParen -KEYWORD_STRING - ("__SOURCE_DIRECTORY__", "{SolutionDirectory}visp/tests/parsing") Default 0 2 LParen +KEYWORD_STRING ("__SOURCE_DIRECTORY__", "{SolutionDirectory}visp/tests/parsing") Default 0 2 LParen RPAREN Default 0 1 LParen LPAREN Default 0 2 LParen SYMBOL "printfn" Default 0 2 LParen