Created
February 2, 2017 08:37
-
-
Save monkieboy/70746fbdd8c17a2dfa94f0ea51e4ae57 to your computer and use it in GitHub Desktop.
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
open System | |
open System.IO | |
type Line = string | |
type Load = string | |
type Lines = Line list | |
type Loads = Load list | |
type Code = Lines | |
type FsxPath = string | |
type Fsx = | |
{ Dependencies : Fsx list | |
ModuleName : string | |
Code : Code } | |
let noDependency = | |
{ Dependencies = [] | |
ModuleName = "" | |
Code = [] } | |
let loadFsx ( fsx : FsxPath ) : Lines = File.ReadAllLines fsx |> Seq.toList | |
/// Gets the module name so that the Fsx record property can be filled | |
let getModuleNameFromFsx ( fsx : FsxPath ) : string = | |
Path.GetFileNameWithoutExtension fsx | |
let getLoads ( lines : Lines ) : Loads = | |
let getFsxFromLoad ( load : Load ) : FsxPath = | |
let trimHashLoad = load.Replace ( "#load ", "" ) | |
let fsxPath = trimHashLoad.Replace ( "\"", "" ) | |
fsxPath | |
lines |> List.filter ( fun line -> line.StartsWith "#load" ) |> List.map getFsxFromLoad | |
/// Gets the code for the fsx file so that the Code property on the Fsx can be filled | |
let getCode ( lines : Lines ) : Code = | |
lines |> List.filter ( fun line -> line.StartsWith "#load" |> not ) | |
let getFsxFromLoad ( load : Load ) : FsxPath = | |
let trimHashLoad = load.Replace ( "#load ", "" ) | |
let fsxPath = trimHashLoad.Replace ( "\"", "" ) | |
fsxPath | |
let rec getTreeFromPath ( fsxPath : Load ) ( tree : Fsx list ) = | |
let name = getModuleNameFromFsx fsxPath | |
let mainLines = loadFsx fsxPath | |
let mainLoads = getLoads mainLines | |
let mainCode = getCode mainLines |> List.map ( (+) " " ) | |
{ noDependency with | |
Dependencies = mainLoads |> List.fold ( fun i s -> ( getTreeFromPath s i ) :: tree ) [ noDependency ] | |
Code = mainCode | |
ModuleName = sprintf "module %s = " name } | |
let buildTree fsxPath = | |
getTreeFromPath fsxPath [] | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment