Hi, Thanks for your comments. Nashorn Parser API was modeled after similar API provided by javac - for consistency sake and to leverage developer familiarity. For example, ContinueTree, MemberSelectTree of javac Tree API:
https://docs.oracle.com/javase/8/docs/jdk/api/javac/tree/com/sun/source/tree/ContinueTree.html https://docs.oracle.com/javase/8/docs/jdk/api/javac/tree/com/sun/source/tree/MemberSelectTree.html I agree that consistency should not result in API 'mistakes/gaps' being propagated here. BTW, labels are maintained as strings even internally. Member select property, Variable name , Function name etc. are all identifiers and so it is possible to make API return IdentifierTree objects. Will you please collect whatever you found and file a bug/enhancement for Nashorn parser API? Thanks, -Sundar On 5/12/2016 9:10 PM, Emilian Bold wrote: > Hello, > > It's really important for a Javascript editor to know the offsets of each > syntax tree node and of whatever the node contains (I'm not really saying > tokens but... constituent parts and keywords are the minimum). > > So it would be great to provide or document how offsets are to be computed > for the String fields from the Nashorn Tree API. > > (Ideally the API could also be changed to use an IdentifierTree or some > other Tree subclass which provides the start/endPosition.) > > A few examples: > > * MemberSelectTree has a String getIdentifier. Since I *assume* that the > MemberSelectTree.getEndPosition is right after the identifier, I have to > subtract the identifier length to get the identifier start offset. > > * VariableTree has a String getName(). It seems to me that > VariableTree.getStartPosition is the 'name' startPosition. This also means > you cannot really know where 'var' actually is -- it could be on another > line altogether; it's also odd to me that 'var' is outside the [start, end] > range for the VariableTree. > > * ContinueTree and BreakTree both have a String getLabel > > * LabeledStatementTree has a String getLabel > > * FunctionExpressionTree and FunctionDeclarationTree both have a String > getName but I'm not sure how the offset for that is computed. Also not sure > how the offset of the 'function' keyword would be computed. > > Could somebody explain this to me? I'll make a nice list for future > reference. > > --emi