Skip to content

Commit

Permalink
add read capability for metadata (wip)
Browse files Browse the repository at this point in the history
  • Loading branch information
caroott committed Jun 11, 2024
1 parent 5031507 commit 151ee0d
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 0 deletions.
24 changes: 24 additions & 0 deletions src/YAMLicious/Reader.fs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,30 @@ let isSequenceElement = fun e -> match e with | Intendation _ | SequenceMinusOpe
let private tokenize (yamlList: PreprocessorElement list) (stringDict: Dictionary<int, string>) (commentDict: Dictionary<int, string>) =
let rec loopRead (restlist: PreprocessorElement list) (acc: YAMLElement list) : YAMLElement =
match restlist with
| SchemaNamespace v::Intendation yamlAstList::rest0 -> //create/appendSequenceElement
//printfn "[tokenize] Case1"
let objectList =
PreprocessorElement.Line v.Key::yamlAstList
let sequenceElements = rest0 |> Seq.takeWhile isSequenceElement |> Seq.toList |> collectSequenceElements
let rest = rest0 |> Seq.skipWhile isSequenceElement |> Seq.toList
let current =
YAMLElement.Sequence [
loopRead objectList []
for i in sequenceElements do
loopRead i []
]
loopRead rest (current::acc)
| SchemaNamespace v::rest0 -> //create/appendSequenceElement
//printfn "[tokenize] Case2"
let sequenceElements = rest0 |> Seq.takeWhile isSequenceElement |> Seq.toList |> collectSequenceElements
let rest = rest0 |> Seq.skipWhile isSequenceElement |> Seq.toList
let current =
YAMLElement.Sequence [
loopRead [PreprocessorElement.Line v.Key] []
for i in sequenceElements do
loopRead i []
]
loopRead rest (current::acc)
// Example1:
// - My Value 1 <c f=1/>
// My Value 2
Expand Down
24 changes: 24 additions & 0 deletions tests/YAMLicious.Tests/Tests.YamlRead.fs
Original file line number Diff line number Diff line change
Expand Up @@ -205,4 +205,28 @@ My Key:
]
let actual = Reader.read yaml
Expect.equal actual expected ""

testCase "Namespaces" <| fun _ ->
let yaml = """
$namespaces:
arc: https://github.com/nfdi4plants/ARC_ontology
test: https://github.com/nfdi4plants/TEST_ontology
"""
let expected = YAMLElement.Object [
YAMLElement.Sequence[
YAMLElement.Object [
YAMLElement.Value(YAMLContent.create("namespaces"));
YAMLElement.Mapping(
YAMLContent.create("arc"),
YAMLElement.Value(YAMLContent.create("https://github.com/nfdi4plants/ARC_ontology"))
);
YAMLElement.Mapping(
YAMLContent.create("test"),
YAMLElement.Value(YAMLContent.create("https://github.com/nfdi4plants/TEST_ontology"))
)
]
]
]
let actual = Reader.read yaml
Expect.equal actual expected ""
]

0 comments on commit 151ee0d

Please sign in to comment.