Skip to content

Commit

Permalink
WIP1
Browse files Browse the repository at this point in the history
  • Loading branch information
knocte committed Sep 4, 2024
1 parent fcdf5c4 commit 6e6b2eb
Showing 1 changed file with 36 additions and 7 deletions.
43 changes: 36 additions & 7 deletions fsxc/Fsxc.fs
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,15 @@ module Program =
| Ref of string
| NugetRef of name: string * version: Option<string>

type PreProcessorConditional =
| If
| Else
| EndIf

type PreProcessorElement =
| Action of PreProcessorAction
| Conditional of PreProcessorConditional

type LineKind =
| Commented
| Normal
Expand Down Expand Up @@ -217,20 +226,23 @@ module Program =

let ReadScriptContents(origScript: FileInfo) : List<LineAction> =

let readPreprocessorLine(line: string) : Option<PreProcessorAction> =
let readPreprocessorLine(line: string) : Option<PreProcessorElement> =
let trimmedLine = line.TrimStart()
if not (trimmedLine.StartsWith "#") then
None
elif (line.StartsWith "#!") then
Some PreProcessorAction.Skip
PreProcessorAction.Skip
|> PreProcessorElement.Action
|> Some
elif (line.StartsWith LOAD_PREPROCESSOR) then
let fileToLoad =
line.Substring(
LOAD_PREPROCESSOR.Length,
line.Length - LOAD_PREPROCESSOR.Length - 1
)

PreProcessorAction.Load fileToLoad |> Some
PreProcessorAction.Load fileToLoad
|> PreProcessorElement.Action
|> Some
elif line.StartsWith REFNUGET_PREPROCESSOR then
let libToRef =
line.Substring(
Expand Down Expand Up @@ -272,7 +284,9 @@ module Program =
else
libToRef, None

PreProcessorAction.NugetRef(libName, maybeVersion) |> Some
PreProcessorAction.NugetRef(libName, maybeVersion)
|> PreProcessorElement.Action
|> Some

elif (line.StartsWith REF_PREPROCESSOR) then
let libToRef =
Expand All @@ -281,7 +295,21 @@ module Program =
line.Length - REF_PREPROCESSOR.Length - 1
)

PreProcessorAction.Ref libToRef |> Some
PreProcessorAction.Ref libToRef
|> PreProcessorElement.Action
|> Some
elif trimmedLine.StartsWith "#else" then
PreProcessorConditional.Else
|> PreProcessorElement.Conditional
|> Some
elif trimmedLine.StartsWith "#endif" then
PreProcessorConditional.EndIf
|> PreProcessorElement.Conditional
|> Some
elif trimmedLine.StartsWith "#if" then
PreProcessorConditional.If
|> PreProcessorElement.Conditional
|> Some
else
failwithf "Unrecognized preprocessor line: %s" line

Expand All @@ -299,8 +327,9 @@ module Program =
let noStateChange() =
let lineKind =
match readPreprocessorLine line with
| Some action -> LineKind.PreProcessorAction action
| Some (PreProcessorElement.Action action) -> LineKind.PreProcessorAction action
| None -> LineKind.Normal
| Some elt -> failwithf "Unexpected element %A" elt

let newAcc =
{
Expand Down

0 comments on commit 6e6b2eb

Please sign in to comment.