CSDS Key-Value Notation parser
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

ocaml-linkedin: apply dune fmt

Pure formatting changes from `dune fmt`: doc comment placement moves
from above the binding to below it for `type`s, multi-line `match`
expressions collapse onto one line where they fit, and infix operator
applications pick up spaces (`Soup.($?)` -> `Soup.( $? )`). No
semantic changes.

+42 -15
+35 -15
README.md
··· 6 6 7 7 ## Installation 8 8 9 + Install with opam: 10 + 11 + ```shell 12 + $ opam install kvn 9 13 ``` 10 - opam install kvn 14 + 15 + If opam cannot find the package, it may not yet be released in the public 16 + `opam-repository`. Add the overlay repository, then install it: 17 + 18 + ```shell 19 + $ opam repo add samoht https://tangled.org/gazagnaire.org/opam-overlay.git 20 + $ opam update 21 + $ opam install kvn 11 22 ``` 12 23 13 24 ## Usage 14 25 15 26 ```ocaml 27 + let kvn_data = 28 + "CCSDS_OEM_VERS = 2.0\n\ 29 + META_START\n\ 30 + OBJECT_NAME = ISS\n\ 31 + META_STOP\n" 32 + 16 33 (* Parse a KVN file line by line *) 17 - let st = Kvn.of_string kvn_data in 18 - while not (Kvn.eof st) do 19 - match Kvn.next st with 20 - | Some (_n, line) -> 21 - (match Kvn.classify line with 22 - | Keyword (k, v) -> Printf.printf "%s = %s\n" k v 23 - | Data d -> Printf.printf "data: %s\n" d 24 - | Comment c -> Printf.printf "# %s\n" c 25 - | Blank -> ()) 26 - | None -> () 27 - done 34 + let scan () = 35 + let st = Kvn.of_string kvn_data in 36 + while not (Kvn.eof st) do 37 + (match Kvn.next st with 38 + | Some (_n, line) -> 39 + (match Kvn.classify line with 40 + | Kvn.Keyword (k, v) -> Printf.printf "%s = %s\n" k v 41 + | Kvn.Data d -> Printf.printf "data: %s\n" d 42 + | Kvn.Comment c -> Printf.printf "# %s\n" c 43 + | Kvn.Blank -> ()) 44 + | None -> ()) 45 + done 28 46 29 47 (* Iterate over a metadata block *) 30 - Kvn.iter_block ~start:"META_START" ~stop:"META_STOP" st 31 - ~on_keyword:(fun k v -> Printf.printf "%s = %s\n" k v) 32 - ~on_data:(fun _n _d -> ()) 48 + let iter () = 49 + let st = Kvn.of_string kvn_data in 50 + Kvn.iter_block ~start:"META_START" ~stop:"META_STOP" st 51 + ~on_keyword:(fun k v -> Printf.printf "%s = %s\n" k v) 52 + ~on_data:(fun _n _d -> ()) 33 53 ``` 34 54 35 55 ## API Overview
+4
dune
··· 1 1 (env 2 2 (dev 3 3 (flags :standard %{dune-warnings}))) 4 + 5 + (mdx 6 + (files README.md) 7 + (libraries kvn))
+2
dune-project
··· 1 1 (lang dune 3.21) 2 + (using mdx 0.4) 2 3 (name kvn) 3 4 (source (tangled gazagnaire.org/ocaml-kvn)) 4 5 ··· 19 20 (depends 20 21 (ocaml (>= 4.14)) 21 22 ptime 23 + (mdx :with-test) 22 24 fmt))
+1
kvn.opam
··· 13 13 "dune" {>= "3.21"} 14 14 "ocaml" {>= "4.14"} 15 15 "ptime" 16 + "mdx" {with-test} 16 17 "fmt" 17 18 "odoc" {with-doc} 18 19 ]