aboutsummaryrefslogtreecommitdiff
path: root/parsing/cLexer.ml
diff options
context:
space:
mode:
authorEnrico Tassi2019-03-05 11:42:17 +0100
committerEnrico Tassi2019-03-31 14:36:28 +0200
commit912eaf40d4efd29b7e3489d51c55b8b79206df79 (patch)
treeb4793da97a5513d460c3d08721cb40692eeddd71 /parsing/cLexer.ml
parented996432fd079583afbb1797c92ad23f654b94eb (diff)
[parsing] Split Tok.t into Tok.t and Tok.pattern
Tokens were having a double role: - the output of the lexer - the items of grammar entries, especially terminals Now tokens are the output of the lexer, and this paves the way for using a richer data type, eg including Loc.t Patterns, as in Plexing.pattern, only represent patterns (for tokens) and now have a bit more structure (eg the wildcard is represented as None, not as "", while a regular pattern for "x" as Some "x")
Diffstat (limited to 'parsing/cLexer.ml')
-rw-r--r--parsing/cLexer.ml30
1 files changed, 15 insertions, 15 deletions
diff --git a/parsing/cLexer.ml b/parsing/cLexer.ml
index 503cfcdb4f..7345afb307 100644
--- a/parsing/cLexer.ml
+++ b/parsing/cLexer.ml
@@ -740,15 +740,15 @@ type te = Tok.t
(** Names of tokens, for this lexer, used in Grammar error messages *)
let token_text = function
- | ("", t) -> "'" ^ t ^ "'"
- | ("IDENT", "") -> "identifier"
- | ("IDENT", t) -> "'" ^ t ^ "'"
- | ("INT", "") -> "integer"
- | ("INT", s) -> "'" ^ s ^ "'"
- | ("STRING", "") -> "string"
- | ("EOI", "") -> "end of input"
- | (con, "") -> con
- | (con, prm) -> con ^ " \"" ^ prm ^ "\""
+ | ("", Some t) -> "'" ^ t ^ "'"
+ | ("IDENT", None) -> "identifier"
+ | ("IDENT", Some t) -> "'" ^ t ^ "'"
+ | ("INT", None) -> "integer"
+ | ("INT", Some s) -> "'" ^ s ^ "'"
+ | ("STRING", None) -> "string"
+ | ("EOI", None) -> "end of input"
+ | (con, None) -> con
+ | (con, Some prm) -> con ^ " \"" ^ prm ^ "\""
let func next_token ?loc cs =
let loct = loct_create () in
@@ -765,9 +765,9 @@ let func next_token ?loc cs =
let make_lexer ~diff_mode = {
Plexing.tok_func = func (next_token ~diff_mode);
Plexing.tok_using =
- (fun pat -> match Tok.of_pattern pat with
- | KEYWORD s -> add_keyword s
- | _ -> ());
+ (fun pat -> match Tok.is_keyword pat with
+ | Some s -> add_keyword s
+ | None -> ());
Plexing.tok_removing = (fun _ -> ());
Plexing.tok_match = Tok.match_pattern;
Plexing.tok_text = token_text }
@@ -807,6 +807,6 @@ let strip s =
let terminal s =
let s = strip s in
let () = match s with "" -> failwith "empty token." | _ -> () in
- if is_ident_not_keyword s then IDENT s
- else if is_number s then INT s
- else KEYWORD s
+ if is_ident_not_keyword s then "IDENT", Some s
+ else if is_number s then "INT", Some s
+ else "", Some s