diff options
| author | Sébastien Dailly <sebastien@dailly.me> | 2026-11-18 17:52:21 +0100 |
|---|---|---|
| committer | Sébastien Dailly <sebastien@dailly.me> | 2026-11-18 17:52:21 +0100 |
| commit | 7b5baa29818c9fe6e33d50c8458aa2824274158e (patch) | |
| tree | b46d98b0ba039fc77bcf7a4aabd9f453acde8d91 /lib/configuration/expression_lexer.mll | |
| parent | 7f04f2f18bdaada855e2f3abfd64b420d9dba127 (diff) | |
Updated the configuration format
Diffstat (limited to 'lib/configuration/expression_lexer.mll')
| -rw-r--r-- | lib/configuration/expression_lexer.mll | 125 |
1 files changed, 58 insertions, 67 deletions
diff --git a/lib/configuration/expression_lexer.mll b/lib/configuration/expression_lexer.mll index 1b4602a..041c2fd 100644 --- a/lib/configuration/expression_lexer.mll +++ b/lib/configuration/expression_lexer.mll @@ -1,93 +1,84 @@ { open Expression_parser - exception UnclosedQuote of { content: string ; line : int} + exception UnclosedQuote of { content : string; line : int } } +let spaces = [' ' '\t'] -let spaces = [ ' ' '\t' ] -let letters = [^ '$' '"' '\'' '(' ')' '[' ']' ':' '.' ',' '^' ' ' '\t' '\n' '\r' ] -let digit = [ '0'-'9' ] -let eol = [ '\r' '\n' ] +let letters = + [^'$' '"' '\'' '(' ')' '[' ']' ':' '.' ',' '^' ' ' '\t' '\n' '\r'] -let escaped = [ '\'' '\\'] +let digit = ['0'-'9'] + +let eol = ['\r' '\n'] + +let escaped = ['\'' '\\'] rule token = parse -| eol { Lexing.new_line lexbuf; token lexbuf } -| spaces { token lexbuf } -| '\'' { - try read_quoted_string (Buffer.create 17) lexbuf - with Failure _ -> + | eol { Lexing.new_line lexbuf; token lexbuf } + | spaces { token lexbuf } + | '\'' + { + try read_quoted_string (Buffer.create 17) lexbuf + with Failure _ -> let line = lexbuf.Lexing.lex_curr_p.pos_lnum and content = Bytes.to_string lexbuf.Lexing.lex_buffer in - raise (UnclosedQuote {line; content}) -} -| '"' { read_dquoted_string (Buffer.create 17) lexbuf } -| '#' { skip_comment lexbuf } -| '(' { L_PAREN } -| ')' { R_PAREN } -| '[' { L_BRACKET } -| ']' { R_BRACKET } -| ':' { COLUMN } -| '$' { DOLLAR } -| '.' { DOT } -| ',' { COMA } -| '^' { CONCAT_OPERATOR } -| '+' { BINARY_OPERATOR (Model.Dsl.Add) } -| '-' { BINARY_OPERATOR (Model.Dsl.Minus) } -| '/' { BINARY_OPERATOR (Model.Dsl.Division) } -| "and" { BOOL_OPERATOR (Model.Dsl.And) } -| "or" { BOOL_OPERATOR (Model.Dsl.Or) } -| '<' { INEQUALITY_OPERATOR (Model.Dsl.LT) } -| "<=" { INEQUALITY_OPERATOR (Model.Dsl.LTE) } -| '>' { INEQUALITY_OPERATOR (Model.Dsl.GT) } -| ">=" { INEQUALITY_OPERATOR (Model.Dsl.GTE) } -| "<>" { EQUALITY_OPERATOR (Model.Dsl.Different) } -| '=' { EQUALITY_OPERATOR (Model.Dsl.Equal) } -| digit+ as l { INTEGER l} -| '-' digit+ as l { INTEGER l} -| letters+ as l { IDENT l} -| eof { EOF } + raise (UnclosedQuote { line; content }) + } + | '"' { read_dquoted_string (Buffer.create 17) lexbuf } + | '#' { skip_comment lexbuf } + | '(' { L_PAREN } + | ')' { R_PAREN } + | '[' { L_BRACKET } + | ']' { R_BRACKET } + | ':' { COLUMN } + | '$' { DOLLAR } + | '.' { DOT } + | ',' { COMA } + | '^' { CONCAT_OPERATOR } + | '+' { BINARY_OPERATOR Model.Dsl.Add } + | '-' { BINARY_OPERATOR Model.Dsl.Minus } + | '/' { BINARY_OPERATOR Model.Dsl.Division } + | "and" { BOOL_OPERATOR Model.Dsl.And } + | "or" { BOOL_OPERATOR Model.Dsl.Or } + | '<' { INEQUALITY_OPERATOR Model.Dsl.LT } + | "<=" { INEQUALITY_OPERATOR Model.Dsl.LTE } + | '>' { INEQUALITY_OPERATOR Model.Dsl.GT } + | ">=" { INEQUALITY_OPERATOR Model.Dsl.GTE } + | "<>" { EQUALITY_OPERATOR Model.Dsl.Different } + | '=' { EQUALITY_OPERATOR Model.Dsl.Equal } + | digit+ as l { INTEGER l } + | '-' digit+ as l { INTEGER l } + | letters+ as l { IDENT l } + | eof { EOF } and skip_comment = parse - | [^ '\r' '\n' ] - { skip_comment lexbuf } - | eol - { token lexbuf } + | [^'\r' '\n'] { skip_comment lexbuf } + | eol { token lexbuf } (* Read the content until we got another one quote *) and read_quoted_string buf = parse - | [^ '\'' '\\' ]+ - { Buffer.add_string buf (Lexing.lexeme lexbuf); - read_quoted_string buf lexbuf - } - | "\\\'" - { Buffer.add_char buf '\''; + | [^'\'' '\\']+ + { + Buffer.add_string buf (Lexing.lexeme lexbuf); read_quoted_string buf lexbuf } + | "\\'" + { Buffer.add_char buf '\''; read_quoted_string buf lexbuf } | '\\' - { Buffer.add_char buf '\\'; - read_quoted_string buf lexbuf - } - | '\'' - { LITERAL (Buffer.contents buf) - } + { Buffer.add_char buf '\\'; read_quoted_string buf lexbuf } + | '\'' { LITERAL (Buffer.contents buf) } (* Read the content until we got another one quote *) and read_dquoted_string buf = parse - | [^ '"' '\\' ]+ - { Buffer.add_string buf (Lexing.lexeme lexbuf); + | [^'"' '\\']+ + { + Buffer.add_string buf (Lexing.lexeme lexbuf); read_dquoted_string buf lexbuf } | "\\\"" - { Buffer.add_char buf '"'; - read_dquoted_string buf lexbuf - } + { Buffer.add_char buf '"'; read_dquoted_string buf lexbuf } | '\\' - { Buffer.add_char buf '\\'; - read_dquoted_string buf lexbuf - } - | '"' - { - LITERAL (Buffer.contents buf) - } + { Buffer.add_char buf '\\'; read_dquoted_string buf lexbuf } + | '"' { LITERAL (Buffer.contents buf) } |
