Use object as type instead of String [message #1779350] |
Fri, 05 January 2018 11:43  |
Eclipse User |
|
|
|
Hello,
my grammar looks like:
Eq:
'eq' value=STRING | NUMBER |NULL;
NUMBER:
'-'? INT ('.' INT)?;
terminal NULL:
'null';
Currently the interface Eq constains a method `String getValue`, how can i change this to`Object getValue`?
[Updated on: Fri, 05 January 2018 12:32] by Moderator
|
|
|
|
|
|
Re: Use object as type instead of String [message #1779371 is a reply to message #1779367] |
Fri, 05 January 2018 13:06   |
Eclipse User |
|
|
|
Christian Dietrich wrote on Fri, 05 January 2018 17:51that sounds like a parse error?!?
Why should this be a parse error?
Christian Dietrich wrote on Fri, 05 January 2018 17:51
the question is your semantic?
The semantic is like:
eq(attribute, "a") or eq(attribute, 1) or eq(attribute, null)
Christian Dietrich wrote on Fri, 05 January 2018 17:51
wouldnt it be better to have a StringLiteral, a NumberLiteral, and Null as separate types?
Do you mean something like this:
Instead of
Eq:
'eq' '(' attribute=FIELD_VALUE ',' value=STRING | INT | NULL')';
this:
Eq:
EqString | EqInt ...
EqString:
'eq' '(' attribute=FIELD_VALUE ',' value=STRING')';
EqInt:
'eq' '(' attribute=FIELD_VALUE ',' value=INT')';
|
|
|
Re: Use object as type instead of String [message #1779372 is a reply to message #1779367] |
Fri, 05 January 2018 13:07   |
Eclipse User |
|
|
|
Christian Dietrich wrote on Fri, 05 January 2018 17:51that sounds like a parse error?!?
Why should this be a parse error?
Christian Dietrich wrote on Fri, 05 January 2018 17:51
the question is your semantic?
The semantic is like:
eq(attribute, "a") or eq(attribute, 1) or eq(attribute, null)
Christian Dietrich wrote on Fri, 05 January 2018 17:51
wouldnt it be better to have a StringLiteral, a NumberLiteral, and Null as separate types?
Do you mean something like this:
Instead of
Eq:
'eq' '(' attribute=FIELD_VALUE ',' value=STRING | INT | NULL')';
this:
Eq:
EqString | EqInt ...
EqString:
'eq' '(' attribute=FIELD_VALUE ',' value=STRING')';
EqInt:
'eq' '(' attribute=FIELD_VALUE ',' value=INT')';
|
|
|
Re: Use object as type instead of String [message #1779373 is a reply to message #1779367] |
Fri, 05 January 2018 13:07   |
Eclipse User |
|
|
|
Christian Dietrich wrote on Fri, 05 January 2018 17:51that sounds like a parse error?!?
Why should this be a parse error?
Christian Dietrich wrote on Fri, 05 January 2018 17:51
the question is your semantic?
The semantic is like:
eq(attribute, "a") or eq(attribute, 1) or eq(attribute, null)
Christian Dietrich wrote on Fri, 05 January 2018 17:51
wouldnt it be better to have a StringLiteral, a NumberLiteral, and Null as separate types?
Do you mean something like this:
Instead of
Eq:
'eq' '(' attribute=FIELD_VALUE ',' value=STRING | INT | NULL')';
this:
Eq:
EqString | EqInt ...
EqString:
'eq' '(' attribute=FIELD_VALUE ',' value=STRING')';
EqInt:
'eq' '(' attribute=FIELD_VALUE ',' value=INT')';
|
|
|
|
Re: Use object as type instead of String [message #1779375 is a reply to message #1779367] |
Fri, 05 January 2018 13:08   |
Eclipse User |
|
|
|
Christian Dietrich wrote on Fri, 05 January 2018 17:51that sounds like a parse error?!?
Why should this be a parse error?
Christian Dietrich wrote on Fri, 05 January 2018 17:51
the question is your semantic?
The semantic is like:
eq(attribute, "a") or eq(attribute, 1) or eq(attribute, null)
Christian Dietrich wrote on Fri, 05 January 2018 17:51
wouldnt it be better to have a StringLiteral, a NumberLiteral, and Null as separate types?
Do you mean something like this:
Instead of
Eq:
'eq' '(' attribute=FIELD_VALUE ',' value=STRING | INT | NULL')';
this:
Eq:
EqString | EqInt ...
EqString:
'eq' '(' attribute=FIELD_VALUE ',' value=STRING')';
EqInt:
'eq' '(' attribute=FIELD_VALUE ',' value=INT')';
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Re: Use object as type instead of String [message #1779482 is a reply to message #1779475] |
Mon, 08 January 2018 09:00  |
Eclipse User |
|
|
|
Christian Dietrich wrote on Mon, 08 January 2018 12:48no i meant
Literal:
(StringOrNumberLiteral | BooleanValue | NullValue);
StringOrNumberLiteral:
(StringLiteral | NumberValue);
StringLiteral:
value = STRING;
NumberValue:
value = DOUBLE;
BooleanValue:
value = BOOLEAN;
NullValue:
value = NULL;
Mhm ok this works, but with this solution i have a lots of cast, because the Literal class has no getValue(). Just the subclasses has a getValue
StringLiteral literal = (StringLiteral) eq.getLiteral();
assertThat(literal.getValue()).isEqualTo("4711");
|
|
|
Powered by
FUDForum. Page generated in 0.08174 seconds