Skip to content

Commit

Permalink
Output representation.json file (#123)
Browse files Browse the repository at this point in the history
  • Loading branch information
ErikSchierboom authored Dec 16, 2022
1 parent 9b72faa commit 8851d43
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
3 changes: 2 additions & 1 deletion src/Exercism.Representers.FSharp/Program.fs
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,13 @@ type Options =
OutputDirectory: string }
member this.InputFile = Path.Combine(this.InputDirectory, sprintf "%s.fs" (this.Slug.Dehumanize().Pascalize()))
member this.RepresentationFile = Path.Combine(this.OutputDirectory, "representation.txt")
member this.RepresentationJsonFile = Path.Combine(this.OutputDirectory, "representation.json")
member this.MappingFile = Path.Combine(this.OutputDirectory, "mapping.json")

let private parseSuccess (options: Options) =
Syntax.parseFile options.InputFile
|> Option.map Syntax.toSimplifiedTreeAndMapping
|> Option.map (Syntax.writeToFile options.RepresentationFile options.MappingFile)
|> Option.map (Syntax.writeToFile options.RepresentationFile options.RepresentationJsonFile options.MappingFile)

let private parseOptions argv =
let parserResult = CommandLine.Parser.Default.ParseArguments<Options>(argv)
Expand Down
9 changes: 7 additions & 2 deletions src/Exercism.Representers.FSharp/Syntax.fs
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,10 @@ let toSimplifiedTreeAndMapping (tree, source) =
|> Map.toList
|> List.map (fun (identifier, placeholder) -> (placeholder, identifier))
|> Map.ofList

let metadata = Map.ofList [("version", 2)]

(simplifiedTree, placeholdersToIdentifiers, source)
(simplifiedTree, placeholdersToIdentifiers, source, metadata)

let private treeToRepresentation tree source =
let config = { FormatConfig.FormatConfig.Default with KeepMaxNumberOfBlankLines = 1 }
Expand All @@ -131,6 +133,9 @@ let private treeToRepresentation tree source =

let private mappingToJson mapping = JsonSerializer.Serialize(mapping)

let writeToFile representationFile mappingFile (tree, mapping, source) =
let private metadataToJson metadata = JsonSerializer.Serialize(metadata)

let writeToFile representationFile representationJsonFile mappingFile (tree, mapping, source, metadata) =
File.WriteAllText(representationFile, treeToRepresentation tree source + "_test")
File.WriteAllText(representationJsonFile, metadataToJson metadata )
File.WriteAllText(mappingFile, mappingToJson mapping)

0 comments on commit 8851d43

Please sign in to comment.