Skip to content

Commit

Permalink
Normalize SOURCE_DIRECTORY in tests and specify custom debugToken for…
Browse files Browse the repository at this point in the history
… KEYWORD_STRING token
  • Loading branch information
vipentti committed Dec 26, 2023
1 parent c1fb001 commit b507fbf
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 9 deletions.
1 change: 1 addition & 0 deletions src/Visp.Compiler/ParseUtils.fs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
18 changes: 13 additions & 5 deletions src/Visp.Compiler/Syntax/LexHelpers.fs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 0 additions & 2 deletions tests/Visp.Compiler.UnitTests/Program.fs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
// Distributed under the MIT License.
// https://github.com/vipentti/visp-fs/blob/main/LICENSE.md

open VerifyTests

module Program =
[<EntryPoint>]
let main _ = 0
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit b507fbf

Please sign in to comment.