@@ -8,30 +8,37 @@ private import internal.TreeSitter
8
8
/** A constant value. */
9
9
class ConstantValue extends TConstantValue {
10
10
/** Gets a textual representation of this constant value. */
11
- final string toString ( ) {
12
- result = this .getInt ( ) .toString ( )
11
+ final string toString ( ) { this .hasValueWithType ( result , _) }
12
+
13
+ /** Gets a string describing the type of this constant value. */
14
+ string getValueType ( ) { this .hasValueWithType ( _, result ) }
15
+
16
+ private predicate hasValueWithType ( string value , string type ) {
17
+ value = this .getInt ( ) .toString ( ) and type = "int"
13
18
or
14
- result = this .getFloat ( ) .toString ( )
19
+ value = this .getFloat ( ) .toString ( ) and type = "float"
15
20
or
16
21
exists ( int numerator , int denominator |
17
22
this .isRational ( numerator , denominator ) and
18
- result = numerator + "/" + denominator
23
+ value = numerator + "/" + denominator and
24
+ type = "rational"
19
25
)
20
26
or
21
27
exists ( float real , float imaginary |
22
28
this .isComplex ( real , imaginary ) and
23
- result = real + "+" + imaginary + "i"
29
+ value = real + "+" + imaginary + "i" and
30
+ type = "complex"
24
31
)
25
32
or
26
- result = this .getString ( )
33
+ value = this .getString ( ) and type = "string"
27
34
or
28
- result = ":" + this .getSymbol ( )
35
+ value = ":" + this .getSymbol ( ) and type = "symbol"
29
36
or
30
- result = this .getRegExp ( )
37
+ value = this .getRegExp ( ) and type = "regexp"
31
38
or
32
- result = this .getBoolean ( ) .toString ( )
39
+ value = this .getBoolean ( ) .toString ( ) and type = "boolean"
33
40
or
34
- this .isNil ( ) and result = "nil"
41
+ this .isNil ( ) and value = "nil" and type = "nil"
35
42
}
36
43
37
44
/** Gets the integer value, if this is an integer. */
0 commit comments