2 module Msg = Khatus_msg
3 module Time = Khatus_time
6 [ `Bad_format_of_msg_head
7 | `Bad_format_of_msg_content
13 let alphnumdash = ['a'-'z' 'A'-'Z' '0'-'9' '_' '-']+
14 let snake = ['a'-'z' '_']+
17 let node = alphnumdash
19 let key = ['a'-'z' 'A'-'Z' '0'-'9' '_' '-' ':']+
20 let level = ("info" | "error")
21 let priority = ("low" | "med" | "hi")
22 let subject = alphnumdash
24 rule parse_msg = parse
25 | (node as node) sep_1 (modul as modul) sep_1 {
26 match parse_content lexbuf with
27 | Ok content -> Ok Msg.({node; modul; content : content})
34 Error (`Bad_format_of_msg_head)
37 and parse_content = parse
38 | "status_bar" sep_1 {
39 Ok (Msg.Status_bar (tl lexbuf))
42 sep_1 (['0'-'9']+ as mtime)
44 sep_1 (modul as modul)
48 let key = String.split_on_char sep_2 key in
49 let mtime = Time.of_string mtime in
50 Ok (Msg.Cache {mtime; node; modul; key; value = tl lexbuf})
52 | "data" sep_1 (key as key) sep_1 {
53 Ok (Msg.Data {key = String.split_on_char sep_2 key; value = tl lexbuf})
56 Ok (Msg.Error (tl lexbuf))
58 | "alert" sep_1 (priority as priority) (subject as subject) sep_1 {
66 Ok (Msg.Alert {priority; subject; body = tl lexbuf})
68 | "log" sep_1 (snake as location) (level as level) sep_1 {
75 Ok (Msg.Log {location; level; msg = tl lexbuf})
81 Error (`Bad_format_of_msg_content)
85 | (_* as tail) eof {tail}