aboutsummaryrefslogtreecommitdiff
path: root/viz.js/process/tab_Lexer.mll
diff options
context:
space:
mode:
Diffstat (limited to 'viz.js/process/tab_Lexer.mll')
-rwxr-xr-xviz.js/process/tab_Lexer.mll65
1 files changed, 65 insertions, 0 deletions
diff --git a/viz.js/process/tab_Lexer.mll b/viz.js/process/tab_Lexer.mll
new file mode 100755
index 0000000..67793e4
--- /dev/null
+++ b/viz.js/process/tab_Lexer.mll
@@ -0,0 +1,65 @@
+{
+ open Js_of_ocaml
+ exception SyntaxError of string * Lexing.lexbuf
+ exception Eof
+
+ type arrow =
+ | Forward
+ | Backward
+ | Both
+ | None
+
+ type jstring = Js.js_string Js.t
+
+ type res =
+ | NewLine
+ | Root of jstring
+ | Entry of jstring * (jstring * jstring * arrow) option
+ | Redirection of jstring * jstring * arrow
+ | Separator
+
+ let get_arrow = begin function
+ | "<-" -> Backward
+ | "<->" -> Both
+ | "--" -> None
+ | _ -> Forward
+ end
+
+}
+
+let space = ['\000' '\t' '\x0C' ' ']
+let spaces = space*
+let newline = spaces ("\r\n" | '\n' | '\r')+
+
+(* Any character except the delimiters and spaces *)
+let regular = [^ '\n' '\x0C' '\r' ]
+let target_id = ['A'-'Z' 'a'-'z' '0'-'9']+ (':' ['0'-'9']+)?
+
+let arrow = "->" | "--" | "<-" | "<->"
+
+rule parse_line = shortest
+ | eof { raise Eof }
+
+ | newline {NewLine}
+
+ | space+ '-'+ newline {Separator}
+
+ | (target_id as _1) newline { Root (Js.string _1) }
+
+ | (spaces as _1)
+ (arrow as _arrow) space+
+ (target_id as _target) spaces
+ (regular* as comment) newline
+ { Redirection ( Js.string _target, Js.string comment, (get_arrow _arrow))}
+
+ | spaces
+ (regular+ as _2) space+
+ (arrow as _arrow) space+
+ (target_id as _target) spaces
+ (regular* as comment) newline
+ { Entry (Js.string _2, Some (Js.string _target, Js.string comment, (get_arrow _arrow)))}
+
+ | (space+ as _1)
+ (regular+ as _2) newline
+ { Entry (Js.string _2, None) }
+