aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorarie <arie@alleycat.cc>2021-05-19 15:16:03 +0200
committerarie <arie@alleycat.cc>2021-06-28 21:01:35 +0200
commitb4fb04c5e3d61ff7cfd6ad1c62c20770c1e01d35 (patch)
tree7b630eca87a7cada1559d8fc979fb39809a68dfd
parenta50159bc8aa826b5263f76322e97c9522e09f5b4 (diff)
Rdf_turtle:
Two little parsers for irirefs and prefixed_names. To see whether this is the right direction.
-rw-r--r--lib/turtle/dune2
-rw-r--r--lib/turtle/rdf_turtle.ml38
-rw-r--r--lib/turtle/rdf_turtle.mli17
3 files changed, 50 insertions, 7 deletions
diff --git a/lib/turtle/dune b/lib/turtle/dune
index b0e54f1..0ef71f5 100644
--- a/lib/turtle/dune
+++ b/lib/turtle/dune
@@ -1,3 +1,3 @@
(library
(name rdf_turtle)
- (libraries rdf))
+ (libraries rdf angstrom))
diff --git a/lib/turtle/rdf_turtle.ml b/lib/turtle/rdf_turtle.ml
index c9ba771..1dc2a9c 100644
--- a/lib/turtle/rdf_turtle.ml
+++ b/lib/turtle/rdf_turtle.ml
@@ -15,10 +15,14 @@ end
module SMap = Map.Make (Ordered_string)
-type iriref = string
-type language = string
+type iriref = Iriref of string
+let iriref_of_string str = Iriref str
+
+type language = Language of string
+
+type prefixed_name = PrefixedName of string * string
+let prefixed_name_of_string s1 s2 = PrefixedName (s1, s2)
-type prefixed_name = string option * string option
type blank_node = Blank_node of string
type iri = Iriref of iriref | Prefixed_name of prefixed_name
@@ -60,3 +64,31 @@ type parser_state = {
cur_predicate: predicate;
}
+
+module Parser = struct
+ open Angstrom
+
+ let is_whitespace = function
+ | '\x20' | '\x0a' | '\x0d' | '\x09' -> true
+ | _ -> false
+
+ let is_not_whitespace c = c |> is_whitespace |> not
+
+ let whitespace =
+ many @@ choice [string " "; string "\n"; string "\t"]
+ >>| ignore
+
+ let iriref =
+ char '<'
+ *> take_while (fun c -> not @@ Char.equal '>' c)
+ <* char '>'
+ >>| (fun s -> iriref_of_string s)
+
+ let prefixed_name =
+ prefixed_name_of_string
+ <$> take_while (fun c -> not @@ Char.equal ':' c)
+ <* char ':'
+ <*> take_while (is_not_whitespace)
+
+end
+
diff --git a/lib/turtle/rdf_turtle.mli b/lib/turtle/rdf_turtle.mli
index 64f80df..bd48d57 100644
--- a/lib/turtle/rdf_turtle.mli
+++ b/lib/turtle/rdf_turtle.mli
@@ -11,12 +11,12 @@ module Iri = Rdf.Iri
module SMap : Map.S with type key = string
(* we take a string for an iri *)
-type iriref = string
-type language = string
+type iriref = Iriref of string
+type language = Language of string
(* The prefixed name is given by a PNAME_NS and PNAME_LN *)
(* This is the namespace and the local part *)
-type prefixed_name = string option * string option
+type prefixed_name = PrefixedName of string * string
type blank_node = Blank_node of string
type iri = Iriref of iriref | Prefixed_name of prefixed_name
@@ -63,3 +63,14 @@ type parser_state = {
cur_predicate: predicate;
}
+val iriref_of_string : string -> iriref
+
+module Parser : sig
+
+ val whitespace : unit Angstrom.t
+
+ val iriref : iriref Angstrom.t
+
+ val prefixed_name : prefixed_name Angstrom.t
+
+end