parser: Factorized variants of Integer under one production
authorLucas Bajolet <r4pass@hotmail.com>
Fri, 31 Jul 2015 18:13:14 +0000 (14:13 -0400)
committerLucas Bajolet <r4pass@hotmail.com>
Tue, 4 Aug 2015 17:58:35 +0000 (13:58 -0400)
Signed-off-by: Lucas Bajolet <r4pass@hotmail.com>

src/parser/nit.sablecc3xx
src/parser/parser_nodes.nit

index 3904c1f..3466248 100644 (file)
@@ -26,10 +26,17 @@ Helpers
 all = [0 .. 0xFF];
 lowercase = ['a' .. 'z'];
 uppercase = ['A' .. 'Z'];
+
 digit = ['0' .. '9'];
 hexdigit = ['0'..'9'] | ['a'..'f'] | ['A'..'F'] | '_';
 bindigit = '0' | '1' | '_';
 octdigit = ['0' .. '7'] | '_';
+number = digit (digit | '_')*;
+hex_number = ('0x' | '0X') hexdigit+;
+bin_number = ('0b' | '0B') bindigit+;
+oct_number = ('0o' | '0O') octdigit+;
+prec = '8' | '16' | '32';
+
 letter = lowercase | uppercase | digit | '_';
 
 tab = 9;
@@ -199,14 +206,7 @@ classid = uppercase letter*;
 id = lowercase letter*;
 attrid = '_' lowercase letter*;
 
-number = digit (digit | '_')*;
-hex_number = ('0x' | '0X') hexdigit+;
-bin_number = ('0b' | '0B') bindigit+;
-oct_number = ('0o' | '0O') octdigit+;
-bytenum = digit (digit | '_')* 'u8';
-hex_bytenum = ('0x' | '0X') hexdigit+ 'u8';
-bin_bytenum = ('0b' | '0B') bindigit+ 'u8';
-oct_bytenum = ('0o' | '0O') octdigit+ 'u8';
+integer = (number | hex_number | bin_number | oct_number) (('u' prec) | ('i' prec) |);
 float = digit* '.' digit+ | (digit+ | digit* '.' digit+) ('E'|'e') ('+'|'-'|) digit+;
 string = '"' str_body '"' | '"' '"' '"' long_str_body lsend1 | ''' ''' ''' long_sstr_body ''' ''' ''';
 start_string = '"' str_body '{' | '"' '"' '"' long_str_body lsend2;
@@ -640,14 +640,7 @@ expr_single~nopar~nobra {-> expr}
        | {true} kwtrue annotations_o {-> New expr.true(kwtrue, annotations_o.annotations)}
        | {false} kwfalse annotations_o {-> New expr.false(kwfalse, annotations_o.annotations)}
        | {null} kwnull annotations_o {-> New expr.null(kwnull, annotations_o.annotations)}
-       | {int} number annotations_o {-> New expr.dec_int(number, annotations_o.annotations)}
-       | {hex_int} hex_number annotations_o {-> New expr.hex_int(hex_number, annotations_o.annotations)}
-       | {bin_int} bin_number annotations_o {-> New expr.bin_int(bin_number, annotations_o.annotations)}
-       | {oct_int} oct_number annotations_o {-> New expr.oct_int(oct_number, annotations_o.annotations)}
-       | {byte} bytenum annotations_o {-> New expr.dec_byte(bytenum, annotations_o.annotations)}
-       | {hex_byte} hex_bytenum annotations_o {-> New expr.hex_byte(hex_bytenum, annotations_o.annotations)}
-       | {bin_byte} bin_bytenum annotations_o {-> New expr.bin_byte(bin_bytenum, annotations_o.annotations)}
-       | {oct_byte} oct_bytenum annotations_o {-> New expr.oct_byte(oct_bytenum, annotations_o.annotations)}
+       | {integer} integer annotations_o {-> New expr.integer(integer, annotations_o.annotations)}
        | {float} float annotations_o {-> New expr.float(float, annotations_o.annotations)}
        | {char} char annotations_o {-> New expr.char(char, annotations_o.annotations)}
        | {string} string annotations_o {-> New expr.string(string, annotations_o.annotations)}
@@ -1011,14 +1004,7 @@ expr     = {block} expr* kwend?
        | {true} kwtrue annotations?
        | {false} kwfalse annotations?
        | {null} kwnull annotations?
-       | {dec_int} number annotations?
-       | {hex_int} hex_number annotations?
-       | {bin_int} bin_number annotations?
-       | {oct_int} oct_number annotations?
-       | {dec_byte} bytenum annotations?
-       | {hex_byte} hex_bytenum annotations?
-       | {bin_byte} bin_bytenum annotations?
-       | {oct_byte} oct_bytenum annotations?
+       | {integer} integer annotations?
        | {float} float annotations?
        | {char} char annotations?
        | {string} string annotations?
index 5e24989..06a18a2 100644 (file)
@@ -965,43 +965,8 @@ abstract class TokenLiteral
        end
 end
 
-# A literal decimal integer
-class TNumber
-       super TokenLiteral
-end
-
-# A literal hexadecimal integer
-class THexNumber
-       super TokenLiteral
-end
-
-# A literal binary integer
-class TBinNumber
-       super TokenLiteral
-end
-
-# A literal octal integer
-class TOctNumber
-       super TokenLiteral
-end
-
-# A literal decimal byte
-class TBytenum
-       super TokenLiteral
-end
-
-# A literal hexadecimal byte
-class THexBytenum
-       super TokenLiteral
-end
-
-# A literal binary byte
-class TBinBytenum
-       super TokenLiteral
-end
-
-# A literal octal byte
-class TOctBytenum
+# A literal integer
+class TInteger
        super TokenLiteral
 end
 
@@ -2508,77 +2473,11 @@ class ANullExpr
 end
 
 # An integer literal
-class AIntExpr
+class AIntegerExpr
        super AExpr
-end
-
-# An integer literal in decimal format
-class ADecIntExpr
-       super AIntExpr
-
-       # The decimal token
-       var n_number: TNumber is writable, noinit
-end
-
-# An integer literal in hexadecimal format
-class AHexIntExpr
-       super AIntExpr
-
-       # The hexadecimal token
-       var n_hex_number: THexNumber is writable, noinit
-end
-
-# An integer literal in binary format
-class ABinIntExpr
-       super AIntExpr
-
-       # The binary token
-       var n_bin_number: TBinNumber is writable, noinit
-end
-
-# An integer literal in octal format
-class AOctIntExpr
-       super AIntExpr
-
-       # The octal token
-       var n_oct_number: TOctNumber is writable, noinit
-end
-
-# An byte literal
-class AByteExpr
-       super AExpr
-end
-
-# An byte literal in decimal format
-class ADecByteExpr
-       super AByteExpr
-
-       # The decimal token
-       var n_bytenum: TBytenum is writable, noinit
-end
-
-# An byte literal in hexadecimal format
-class AHexByteExpr
-       super AByteExpr
-
-       # The hexadecimal token
-       var n_hex_bytenum: THexBytenum is writable, noinit
-end
-
-# An byte literal in binary format
-class ABinByteExpr
-       super AByteExpr
-
-       # The binary token
-       var n_bin_bytenum: TBinBytenum is writable, noinit
-end
-
-# An byte literal in octal format
-class AOctByteExpr
-       super AByteExpr
 
-       # The octal token
-       var n_oct_bytenum: TOctBytenum is writable, noinit
+       # The integer token
+       var n_integer: TInteger is writable, noinit
 end
 
 # A float literal