You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Currently an IntegerNode only has startOffset and endOffset.
So the only way to get its value is by parsing the Integer from the source between these offsets.
This is easy for 123 but less so for 0x123_456 for instance.
It'd be convenient if YARP would make it easier to get the integer value of an IntegerNode.
Some ideas:
YARP would provide a string (like for CallNode#name, StringNode#unescaped, etc) or so with the cleaned up number in textual form, so e.g. 0x123_456 would be 1193046 (so only digits and optional leading -). If we want to optimize serialized size we could make that optional when the source is already just digits and -, but not sure this is worth the complexity. Maybe the string type could handle either from source or from some bytes in the serialized form?
YARP would have a 64-bit signed integer value field in IntegerNode, if it fits in that, and otherwise maybe a variable-width binary integer or so, or again a cleaned up string. Probably simpler to just have a variable-width binary integer field (and that using a simple and efficient-to-decode encoding of the value). This would likely make it quite a bit more efficient to create the AST from the serialized form.
Currently any usage of YARP will need to parse the Integer after deserialization, for instance via Kernel#Integer(String). That works but is less convenient and adds some overhead.
For instance even the Ruby IntegerNode doesn't have a value method or so that would return the value of the literal.
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
Currently an IntegerNode only has
startOffsetandendOffset.So the only way to get its value is by parsing the Integer from the source between these offsets.
This is easy for
123but less so for0x123_456for instance.It'd be convenient if YARP would make it easier to get the integer value of an IntegerNode.
Some ideas:
string(like for CallNode#name, StringNode#unescaped, etc) or so with the cleaned up number in textual form, so e.g.0x123_456would be1193046(so only digits and optional leading-). If we want to optimize serialized size we could make that optional when the source is already just digits and-, but not sure this is worth the complexity. Maybe thestringtype could handle either from source or from some bytes in the serialized form?string. Probably simpler to just have a variable-width binary integer field (and that using a simple and efficient-to-decode encoding of the value). This would likely make it quite a bit more efficient to create the AST from the serialized form.Currently any usage of YARP will need to parse the Integer after deserialization, for instance via
Kernel#Integer(String). That works but is less convenient and adds some overhead.For instance even the Ruby
IntegerNodedoesn't have avaluemethod or so that would return the value of the literal.cc @andrykonchin as we looked at this today
All reactions