parser: add AHexIntExpr
authorJean Privat <jean@pryen.org>
Tue, 15 Apr 2014 13:50:49 +0000 (09:50 -0400)
committerJean Privat <jean@pryen.org>
Tue, 15 Apr 2014 18:32:32 +0000 (14:32 -0400)
Signed-off-by: Jean Privat <jean@pryen.org>

src/literal.nit
src/parser/nit.sablecc3xx
src/parser/parser_abs.nit
src/parser/parser_nodes.nit

index 92f137b..0395299 100644 (file)
@@ -74,6 +74,13 @@ redef class ADecIntExpr
        end
 end
 
+redef class AHexIntExpr
+       redef fun accept_literal(v)
+       do
+               self.value = self.n_hex_number.text.substring_from(2).to_hex
+       end
+end
+
 redef class AFloatExpr
        # The value of the literal float once computed.
        var value: nullable Float
index 1304b65..a6251b6 100644 (file)
@@ -27,6 +27,7 @@ all = [0 .. 0xFF];
 lowercase = ['a' .. 'z'];
 uppercase = ['A' .. 'Z'];
 digit = ['0' .. '9'];
+hexdigit = ['0'..'9'] | ['a'..'f'] | ['A'..'F'];
 letter = lowercase | uppercase | digit | '_';
 
 tab = 9;
@@ -183,6 +184,7 @@ id = lowercase letter*;
 attrid = '_' lowercase letter*;
 
 number = digit+;
+hex_number = ('0x' | '0X') hexdigit+;
 float = digit* '.' digit+;
 string = '"' str_body '"' | '"' '"' '"' long_str_body lsend1 | ''' ''' ''' long_sstr_body ''' ''' ''';
 start_string = '"' str_body '{' | '"' '"' '"' long_str_body lsend2;
@@ -561,7 +563,8 @@ expr_atom~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.int(number, 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)}
        | {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)}
@@ -851,7 +854,8 @@ expr        = {block} expr* kwend?
        | {true} kwtrue annotations?
        | {false} kwfalse annotations?
        | {null} kwnull annotations?
-       | {int} number annotations?
+       | {dec_int} number annotations?
+       | {hex_int} hex_number annotations?
        | {float} float annotations?
        | {char} char annotations?
        | {string} string annotations?
index 2493164..9d4cf4b 100644 (file)
@@ -265,6 +265,9 @@ end
 class TNumber
        super Token
 end
+class THexNumber
+       super Token
+end
 class TFloat
        super Token
 end
@@ -1004,6 +1007,11 @@ class ADecIntExpr
     readable var _n_number: TNumber
     readable var _n_annotations: nullable AAnnotations = null
 end
+class AHexIntExpr
+       super AExpr
+    readable var _n_hex_number: THexNumber
+    readable var _n_annotations: nullable AAnnotations = null
+end
 class AFloatExpr
        super AExpr
     readable var _n_float: TFloat
index c9db2fa..6f60b77 100644 (file)
@@ -548,6 +548,9 @@ end
 class TNumber
        super TokenLiteral
 end
+class THexNumber
+       super TokenLiteral
+end
 class TFloat
        super TokenLiteral
 end
@@ -1548,6 +1551,11 @@ class ADecIntExpr
        super AIntExpr
        readable writable var _n_number: TNumber
 end
+# An integer literal in hexadecimal format
+class AHexIntExpr
+       super AIntExpr
+       readable writable var _n_hex_number: THexNumber
+end
 # A float literal
 class AFloatExpr
        super AExpr