Commit c4abe601 authored by Thorsten Wißmann's avatar Thorsten Wißmann
Browse files

Improve error messages and role parsing

parent 38a9d3cf
......@@ -54,4 +54,5 @@ let eval a f = f a
let id a = a
let foreach_l a f = List.iter f a
let (<<) f g x = f(g(x))
let repeat n fct = for i = 1 to n do fct () done
......@@ -27,5 +27,6 @@ val flip : ('a -> 'b -> 'c) -> ('b -> 'a -> 'c)
val eval : 'a -> ('a -> 'b) -> 'b
val id : 'a -> 'a
val foreach_l : ('a list) -> ('a -> unit) -> unit
val repeat : int -> (unit -> unit) -> unit
val (<<) : ('b -> 'c) -> ('a -> 'b) -> ('a -> 'c)
......@@ -4,7 +4,9 @@ module L = List
(* Just a copy'n'paste from the *.mli file *)
type uri = string
type role = uri
type role =
| ROLE of uri
| INVERSE of role
type class_exp =
| THING
......@@ -54,7 +56,20 @@ let precedence ce = match ce with
| MIN (_,_,_) | MAX (_,_,_) -> 2
| AND _ | OR _ -> 3
let string_of_role : role -> string = id
let precedence_role r = match r with
| ROLE _ -> 0
| INVERSE _ -> 1
let string_of_role r =
let rec sor oldpred r =
let p = precedence_role r in
(if p >= oldpred then "(" else "")^(
match r with
| ROLE str -> str
| INVERSE r -> sor p r ^ "¯"
)^(if p >= oldpred then ")" else "")
in
sor 10 r
let string_of_class_exp ce =
let rec soc oldpred ce =
......
type uri = string
type role = uri
type role =
| ROLE of uri
| INVERSE of role
type class_exp =
| THING
......
......@@ -59,7 +59,7 @@ let tokens_of_string_stream (lines:string Stream.t) : string annotated list =
!lastline
in
let tokenize l =
let col = ref 0 in
let col = ref 1 in
let linenr = nextline () in
let annotation s =
let c = !col in
......@@ -194,9 +194,11 @@ let parse_prefix a lst : OWL.prefix =
)
| _ -> raise (ParseError (a,("Missing Prefix-definition")))
let parse_role t : OWL.role = match t with
| INode ((str,_),[]) -> str
| INode ((_,a),_) -> raise (ParseError (a, "Only named roles without parameters are supported"))
let rec parse_role (INode ((str,a),sub)) : OWL.role =
if ((String.contains str ':') && (sub = [])) then OWL.ROLE str
else match str, sub with
| "ObjectInverseOf",[r] -> OWL.INVERSE (parse_role r)
| _,_ -> raise (ParseError (a, "Unknown role construct \""^str^"\""))
let rec parse_class_exp (INode ((name,anno), sub): string annotated intree) : OWL.class_exp =
let pr = parse_role in
......@@ -272,7 +274,16 @@ let parse_intree_list (strAnIts: string annotated intree list) =
(!prefs, !ontos)
let parse str =
let tree = tree_of_string str in
let itlist = intree_list_of_tree tree in
parse_intree_list itlist
try (let tree = tree_of_string str in
let itlist = intree_list_of_tree tree in
parse_intree_list itlist
) with ParseError ((file,line,col), msg) -> ( (* beautify error message *)
let stream = line_stream_of_string str in
repeat (line - 1) (fun () -> Stream.junk stream);
let content = Stream.next stream in
let indent = ref "" in
repeat (col - 1) (fun () -> indent := " " ^ !indent);
let msg = msg ^"\n"^ content ^"\n"^ !indent ^"^-- here" in
raise (ParseError((file,line,col), msg))
)
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment