From 77544bdfad2af41514ec1435f706fee87ea2969e Mon Sep 17 00:00:00 2001 From: Sébastien Dailly Date: Mon, 7 Feb 2022 15:38:37 +0100 Subject: Added viz.js code --- viz.js/process/tab_Lexer.mll | 65 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 65 insertions(+) create mode 100755 viz.js/process/tab_Lexer.mll (limited to 'viz.js/process/tab_Lexer.mll') 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) } + -- cgit v1.2.3