Commit 382c98bd authored by Andrei Paskevich's avatar Andrei Paskevich

Lexer: handle (*) entirely in the lexer

this avoids handling LEFTPAR_STAR_RIGHTPAR in the parser
parent 3ead22d3
...@@ -52,7 +52,6 @@ ...@@ -52,7 +52,6 @@
"converter", CONVERTER; "converter", CONVERTER;
"literal", LITERAL; "literal", LITERAL;
] ]
} }
let space = [' ' '\t' '\r'] let space = [' ' '\t' '\r']
...@@ -65,12 +64,18 @@ let op_char = ['=' '<' '>' '~' '+' '-' '*' '/' '%' ...@@ -65,12 +64,18 @@ let op_char = ['=' '<' '>' '~' '+' '-' '*' '/' '%'
rule token = parse rule token = parse
| '\n' | '\n'
{ new_line lexbuf; token lexbuf } { Lexing.new_line lexbuf; token lexbuf }
| space+ | space+
{ token lexbuf } { token lexbuf }
| "(*)" | "(**)"
{ LEFTPAR_STAR_RIGHTPAR } { token lexbuf }
| "(*" | "(*(*"
{ Lexlib.comment lexbuf; Lexlib.comment lexbuf; token lexbuf }
| "(*" '\n'
{ Lexing.new_line lexbuf; Lexlib.comment lexbuf; token lexbuf }
| "(*(*)"
| "(*" eof
| "(*" [^ ')']
{ Lexlib.comment lexbuf; token lexbuf } { Lexlib.comment lexbuf; token lexbuf }
| '_' | '_'
{ UNDERSCORE } { UNDERSCORE }
......
...@@ -26,7 +26,7 @@ ...@@ -26,7 +26,7 @@
%token BLACKLIST %token BLACKLIST
%token MODULE EXCEPTION VAL CONVERTER LITERAL %token MODULE EXCEPTION VAL CONVERTER LITERAL
%token FUNCTION PREDICATE TYPE PROP ALL FILENAME TRANSFORM PLUGIN %token FUNCTION PREDICATE TYPE PROP ALL FILENAME TRANSFORM PLUGIN
%token LEFTPAR_STAR_RIGHTPAR COMMA CONSTANT %token COMMA CONSTANT
%token LEFTSQ RIGHTSQ LARROW %token LEFTSQ RIGHTSQ LARROW
%nonassoc SYNTAX REMOVE PRELUDE %nonassoc SYNTAX REMOVE PRELUDE
...@@ -133,7 +133,6 @@ ident: ...@@ -133,7 +133,6 @@ ident:
ident_rich: ident_rich:
| ident { $1 } | ident { $1 }
| LEFTPAR_STAR_RIGHTPAR { Ident.infix "*" }
| LEFTPAR operator RIGHTPAR { $2 } | LEFTPAR operator RIGHTPAR { $2 }
operator: operator:
......
...@@ -166,9 +166,15 @@ rule token = parse ...@@ -166,9 +166,15 @@ rule token = parse
(['p' 'P'] (['-' '+']? digit+ as e))? (['p' 'P'] (['-' '+']? digit+ as e))?
{ REAL (Number.real_const_hex i f { REAL (Number.real_const_hex i f
(Opt.map Lexlib.remove_leading_plus e)) } (Opt.map Lexlib.remove_leading_plus e)) }
| "(*)" | "(**)"
{ LEFTPAR_STAR_RIGHTPAR } { token lexbuf }
| "(*" | "(*(*"
{ Lexlib.comment lexbuf; Lexlib.comment lexbuf; token lexbuf }
| "(*" '\n'
{ Lexing.new_line lexbuf; Lexlib.comment lexbuf; token lexbuf }
| "(*(*)"
| "(*" eof
| "(*" [^ ')']
{ Lexlib.comment lexbuf; token lexbuf } { Lexlib.comment lexbuf; token lexbuf }
| "'" (lident as id) | "'" (lident as id)
{ QUOTE_LIDENT id } { QUOTE_LIDENT id }
......
...@@ -147,7 +147,7 @@ ...@@ -147,7 +147,7 @@
%token BAR %token BAR
%token COLON COMMA %token COLON COMMA
%token DOT DOTDOT EQUAL LT GT LTGT MINUS %token DOT DOTDOT EQUAL LT GT LTGT MINUS
%token LEFTPAR LEFTPAR_STAR_RIGHTPAR LEFTSQ %token LEFTPAR LEFTSQ
%token LARROW LRARROW OR %token LARROW LRARROW OR
%token RIGHTPAR RIGHTSQ %token RIGHTPAR RIGHTSQ
%token UNDERSCORE %token UNDERSCORE
...@@ -1183,11 +1183,6 @@ lident_rich: ...@@ -1183,11 +1183,6 @@ lident_rich:
lident_op_id: lident_op_id:
| LEFTPAR lident_op RIGHTPAR { mk_id $2 $startpos($2) $endpos($2) } | LEFTPAR lident_op RIGHTPAR { mk_id $2 $startpos($2) $endpos($2) }
| LEFTPAR_STAR_RIGHTPAR
{ (* parentheses are removed from the location *)
let s = let s = $startpos in { s with Lexing.pos_cnum = s.Lexing.pos_cnum + 1 } in
let e = let e = $endpos in { e with Lexing.pos_cnum = e.Lexing.pos_cnum - 1 } in
mk_id (Ident.infix "*") s e }
lident_op: lident_op:
| op_symbol { Ident.infix $1 } | op_symbol { Ident.infix $1 }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment