2 module Msg = Khatus_msg
3 module Time = Khatus_time
7 let alphnumdash = ['a'-'z' 'A'-'Z' '0'-'9' '_' '-']+
8 let snake = ['a'-'z' '_']+
11 let node = alphnumdash
13 let key = ['a'-'z' 'A'-'Z' '0'-'9' '_' '-' ':']+
14 let level = ("info" | "error")
15 let priority = ("low" | "med" | "hi")
16 let subject = alphnumdash
18 rule parse_msg = parse
19 | (node as node) sep_1 (modul as modul) sep_1 {
20 match parse_content lexbuf with
21 | Ok content -> Ok Msg.({node; modul; content : content})
28 Error (`Bad_format_of_msg_head)
31 and parse_content = parse
32 | "status_bar" sep_1 {
33 Ok (Msg.Status_bar (tl lexbuf))
36 sep_1 (['0'-'9']+ as mtime)
38 sep_1 (modul as modul)
42 let key = String.split_on_char sep_2 key in
43 let mtime = Time.of_string mtime in
44 Ok (Msg.Cache {mtime; node; modul; key; value = tl lexbuf})
46 | "data" sep_1 (key as key) sep_1 {
47 Ok (Msg.Data {key = String.split_on_char sep_2 key; value = tl lexbuf})
50 Ok (Msg.Error (tl lexbuf))
52 | "alert" sep_1 (priority as priority) (subject as subject) sep_1 {
60 Ok (Msg.Alert {priority; subject; body = tl lexbuf})
62 | "log" sep_1 (snake as location) (level as level) sep_1 {
69 Ok (Msg.Log {location; level; msg = tl lexbuf})
75 Error (`Bad_format_of_msg_content)
79 | (_* as tail) eof {tail}