-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Major refactoring of string handling
- Support interpolated strings - Multiline strings are lifted to the top-level of the program because by default the F# includes the indentation of the current scope as part of the string, this made it very difficult to format multiline strings because there were no guarantees what the actual result would end up being. We also normalize multiline strings to match C# raw-string literals on how the indentation is managed. This may not work 100% accurately but it should be an improvement and it can be improved in the future.
- Loading branch information
Showing
33 changed files
with
1,617 additions
and
636 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
// Copyright 2023 Ville Penttinen | ||
// Distributed under the MIT License. | ||
// https://github.com/vipentti/visp-fs/blob/main/LICENSE.md | ||
|
||
module Visp.Compiler.ParseUtils | ||
|
||
open FSharp.Text.Lexing | ||
open Visp.Compiler | ||
open Visp.Compiler.SyntaxParser | ||
open Visp.Compiler.LexHelpers | ||
open Visp.Compiler.Syntax.Macros | ||
|
||
let mkTokenizerWithArgs args = | ||
let tokens args buf = | ||
let next = | ||
match args.mode with | ||
| LexMode.Default -> Lexer.token args false buf | ||
| LexMode.TokenStream _ -> Lexer.tokenStream args false buf | ||
|
||
// eprintfn "%A %A %i" next args.mode args.depth | ||
|
||
match next with | ||
| QUOTE_SYM -> args.mode <- LexMode.TokenStream TokenStreamMode.QuoteSym | ||
| QUOTE_KW -> // args.mode <- LexMode.TokenStream TokenStreamMode.Quote | ||
args.Nested <| LexMode.TokenStream TokenStreamMode.Quote | ||
| QUASIQUOTE_KW -> args.Nested <| LexMode.TokenStream TokenStreamMode.Quasiquote | ||
| SYNTAX_MACRO -> args.Nested <| LexMode.TokenStream TokenStreamMode.SyntaxMacroStart | ||
| SYMBOL s when args.mode.IsSyntaxMacroStart -> | ||
args.mode <- LexMode.TokenStream TokenStreamMode.Macro | ||
macroTable.AddMacroName s | ||
() | ||
| MACRO_NAME _ -> args.Nested <| LexMode.TokenStream TokenStreamMode.Macro | ||
| HASH_PAREN | ||
| HASH_BRACKET | ||
| LPAREN | ||
| LBRACE | ||
| LBRACKET | ||
| HASH_BRACE -> args.NestIfNotDefault() | ||
| RPAREN | ||
| RBRACE | ||
| RBRACKET -> args.UnnestIfNotDefault() | ||
| _ -> () | ||
|
||
next | ||
|
||
tokens args | ||
|
||
let mkTokenizer () = | ||
mkTokenizerWithArgs <| mkDefaultLextArgs () | ||
|
||
|
||
let parseStringToExpr fileName str = | ||
let lexbuf = LexBuffer<_>.FromString str | ||
lexbuf.EndPos <- Position.FirstLine fileName | ||
let tokenizer = mkTokenizer () | ||
|
||
try | ||
raw_expr tokenizer lexbuf | ||
with :? ParseHelpers.SyntaxError as syn -> | ||
outputSyntaxError syn | ||
reraise () |
Oops, something went wrong.