Skip to content

Commit 9ad21ac

Browse files
committed
allow integers in char set
1 parent 6a410a5 commit 9ad21ac

File tree

2 files changed

+6
-5
lines changed

2 files changed

+6
-5
lines changed

common/mik_lexer.mll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ rule token = parse
9191
| "int" { INT_CONVERTER }
9292
| "float" { FLOAT_CONVERTER }
9393
| "$" { PREDEFINED_CLASS "$" }
94-
| digit+ as n { INT (int_of_string n) }
94+
| digit+ as n { INT n }
9595
| module_ident as id { MOD_IDENT id }
9696
| ident as id {
9797
match List.assoc_opt id predefined_classes with

common/mik_parser.mly

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,7 @@ let unclosed_error what startpos endpos =
4040
syntax_error (Printf.sprintf "Unclosed %s" what) startpos endpos
4141
%}
4242

43-
%token <string> CHAR_LITERAL STRING_LITERAL IDENT MOD_IDENT PREDEFINED_CLASS
44-
%token <int> INT
43+
%token <string> CHAR_LITERAL STRING_LITERAL IDENT MOD_IDENT PREDEFINED_CLASS INT
4544
%token SLASH LPAREN RPAREN LBRACKET RBRACKET CARET LBRACE RBRACE EMPTY_STR
4645
%token DASH BAR STAR PLUS QUESTION UNDERSCORE COLON EQUAL AS PIPE
4746
%token INT_CONVERTER FLOAT_CONVERTER EOF
@@ -108,15 +107,16 @@ atom_expr:
108107
wrap_loc $startpos $endpos (Opt $1)
109108
}
110109
| basic_atom LBRACE n = INT RBRACE {
110+
let n = int_of_string n in
111111
let repeat_loc = wrap_loc $startpos($2) $endpos($4) (n, Some n) in
112112
wrap_loc $startpos $endpos (Repeat (repeat_loc, $1))
113113
}
114114
| basic_atom LBRACE min = INT DASH max = INT RBRACE {
115-
let repeat_loc = wrap_loc $startpos($2) $endpos($6) (min, Some max) in
115+
let repeat_loc = wrap_loc $startpos($2) $endpos($6) (int_of_string min, Some (int_of_string max)) in
116116
wrap_loc $startpos $endpos (Repeat (repeat_loc, $1))
117117
}
118118
| basic_atom LBRACE min = INT DASH RBRACE {
119-
let repeat_loc = wrap_loc $startpos($2) $endpos($5) (min, None) in
119+
let repeat_loc = wrap_loc $startpos($2) $endpos($5) (int_of_string min, None) in
120120
wrap_loc $startpos $endpos (Repeat (repeat_loc, $1))
121121
}
122122
(* error cases for repetition *)
@@ -265,5 +265,6 @@ char_set_item:
265265
| CHAR_LITERAL DASH CHAR_LITERAL { $1 ^ "-" ^ $3 }
266266
| CHAR_LITERAL DASH { missing_error "character after '-' in range" $startpos($2) $endpos }
267267
| STRING_LITERAL { $1 }
268+
| INT { $1 }
268269
| PREDEFINED_CLASS { $1 }
269270
| IDENT { $1 }

0 commit comments

Comments
 (0)