elan-language / LanguageAndIDE

Apache License 2.0
3 stars 0 forks source link

Support dot chaining of functon calls and/or properties #670

Closed richardpawson closed 2 months ago

richardpawson commented 3 months ago

This is the proposed new model in EBNF like representation, using the actual parse node names:

ExprNode:
    Term
  | BinaryExpression
  | NewInstance
  | EmptyOfTypeNode
  | CopyWith
  | IfExpr
  | Lambda
  | FunctionRef // to be added when #638 is implemented

Term:
    TermSimple
  | TermChained

BinaryExpression:
  Term BinaryOperation ExprNode // would prefer RHS to be Term, but that caused many failures

TermSimple:
    ReferenceNode //note that this is not the same as the current SymbolNode, which is to be renamed to PunctuationNode
  | LiteralValueNode // Must be after symbol so that `true`/``false` do not prompt completion of an identifier starting `n`
  | lmmutableListNode
  | ArrayList node
  | DictionaryNode
  | ImmutableDictionaryNode
  | TupleNode
  | UnaryExpression  // Must be after symbol so that `not` does not prompt completion of an identifier starting `n`
  | BracketedExpression

TermChained:  
    TermSimple (DOT symbol)+  // + because must be at least one dot-extension 
  | (PROPERTY | GLOBAL | LIBRARY) (DOT symbol )+    

ReferenceNode:  // Having a single node for symbol should make auto-completions easier to implement
    THIS // sorts out current issues with 'this' (see #707) implemented as KeywordNode to get rendering
  | IdentifierNode IndexNode? // indexNode covers: single-index, double-index, and range
  | MethodCallNode IndexNode? // compiler enforces that method must be a function (or system method if inside a proc)
richardpawson commented 2 months ago

Passing to Stef. All work on this so far is in branch dotChainProgressively

1) Several existing parse nodes have been renamed - but all tests are passing

2) There is a new parallel hierarchy with root ExprNode2 that is eventually to replace ExprNode. ExprNode2 is tested to parse all existing tests for ExprNode and new ones which involve more chaining.

3) ExprNode2 is dependent on both existing parse nodes and new ones, the latter either intended ultimately to replace existing (e.g. Term2, MethodCall2) or are brand new. Of the latter, many are just implementations of AbstractAlternatives and so have no impact on the AST model. Others that do impact the AST are:

ReferenceNode TermChained which are key, and DotBefore DotAfter which are simple.

4) There is a lot of scope for clean up of other (e.g. of varRefNode varRefCompound procRef and anything else that previously used 'qualifiers' and which should now use the new new constructs - but I think the first stage is to get the new structure for expressions working.