diff options
author | Chimrod <> | 2023-10-03 18:19:15 +0200 |
---|---|---|
committer | Chimrod <> | 2023-10-15 19:04:36 +0200 |
commit | 5a18a66763bcc19de117cb83293d7bd25a0ea10c (patch) | |
tree | 1627ae50da1a87e5952b5fab21b7290b0555041e /lib/qparser/lexer.ml | |
parent | 49f69c1ab4d3d8716f30d7bd36a66a4241e16d33 (diff) |
Switched the keyword from string to a sum type
Diffstat (limited to 'lib/qparser/lexer.ml')
-rw-r--r-- | lib/qparser/lexer.ml | 17 |
1 files changed, 14 insertions, 3 deletions
diff --git a/lib/qparser/lexer.ml b/lib/qparser/lexer.ml index fe2b487..383d6a3 100644 --- a/lib/qparser/lexer.ml +++ b/lib/qparser/lexer.ml @@ -11,6 +11,10 @@ exception EOF (* Extract the location name from the pattern *) let location_name = Str.regexp {|.* \(.*\)|} +(** Try to read the identifier and check if this is a function, a keyword, or + just a variable. + + See the tests [Syntax.Operator2] and [Syntax.Call Nl] for two cases. *) let build_ident buffer = let id = Lexbuf.content buffer |> String.uppercase_ascii in try @@ -19,7 +23,14 @@ let build_ident buffer = match value with IF | ELIF -> Lexbuf.incr_level buffer | _ -> () in value - with Not_found -> IDENT id + with Not_found -> + (* If the identifier does not match a keyword and start with [*], then + try it as a '*' operator. *) + if Char.equal '*' id.[0] then ( + Lexbuf.rollback buffer; + let lexbuf = Lexbuf.buffer buffer in + match%sedlex lexbuf with '*' -> STAR | _ -> IDENT id) + else IDENT id let wait_balance : (Buffer.t -> Lexbuf.t -> 'a) -> Lexbuf.t -> 'a = fun rule lexbuf -> @@ -37,7 +48,7 @@ let coma = [%sedlex.regexp? ','] let digit = [%sedlex.regexp? '0' .. '9'] let letters = [%sedlex.regexp? 'a' .. 'z' | 'A' .. 'Z' | '_'] let spaces = [%sedlex.regexp? Plus space] -let ident = [%sedlex.regexp? ('$' | letters), Star (digit | letters)] +let ident = [%sedlex.regexp? Opt ('$' | '*'), letters, Star (digit | letters)] let location_ident = [%sedlex.regexp? letters | digit] let location_prefix = [%sedlex.regexp? '!' | '$' | '#' | '^'] let location = [%sedlex.regexp? Opt location_prefix, Plus location_ident] @@ -104,7 +115,7 @@ let rec skip_comment buffer = | eol -> (* Ugly hack used in order to put the eol in the front of the next parsing. *) - Sedlexing.rollback lexbuf; + Lexbuf.rollback buffer; COMMENT | any -> skip_comment buffer | _ -> raise Not_found |