-
User Story
-
Resolution: Done
-
Not Evaluated
-
None
-
None
-
QDS Berlin - 2023 Week 27/28, QDS Berlin - 2023 Week 29/30
-
f018ea6d8 (qds/dev)
Start with parsing defined expressions from QML
This can be done test driven, starting with tests.
qtcreator/tests/auto/qml contains tests for qml
The implementation can go here the code can go here: qtcreator/src/libs/qmljs
Notes:
structure of if else statement
Program
StatementList
IfStatement
IdentifierExpression or BinaryExpression or FieldExpression or NotExpression
Block
StatementList (one item)
ExpressionStatement
CallExpression | FieldExpression
BinaryExpression (assignment is BinaryExpression)
LHS: FieldmemberExpression | IdentifierExpression | Literal
RHS: FieldmemberExpression | IdentifierExpression | Literal
[else]
FieldExpression is multiple IdentifierExpression delimited with ".
The else is part of AST::IfStatement
class IfStatement
ExpressionNode *expression; //ast allows inheritance this is e.g. IdentifierExpression or BinaryExpression or FieldExpression
Statement *ok; //normal statement - should be always Block since we expect {}
Statement *ko; //else statement can be 0 - should be always Block since we expect {}
structure of expression
IdentifierExpression || BinaryExpression || FieldExpression
BinaryExpression can consist of (IdentifierExpression || BinaryExpression || FieldExpression || NotExpression) - but there can be literals
literals: NumericLiteral and StringLiteral
Literals should not be on LHS
Operators are part of the BinaryExpression as token.
class BinaryExpression
{ ExpressionNode *left; int op; //I expect this to hold the operator as int/enum ExpressionNode *right; SourceLocation operatorToken; };
Thats it - afaik we do not expect anything else.
The first step would be to run a checker that checks an ast for this expected structure and feeds a simple intermediate representation.
We can always expect the if with blocks. The StatementLists and Expressions can have slightly different structure in each case.
algorithm proposal
1) parse signal handler code block using ast
2) Match structure
has if?
match the statement
match the condition-expression
has else?
match the statement
3) AST is now stored in MatchedStatement
If structure does not match the UI becomes readonly. User can reset "code" and start from scratch
If structure does match we can represent MatchedStatement in UI
4) UI changes are represented only in MatchedStatement until applied
5) Once changes are applied we write QML code reparse/rematch and compare
done
The ast is read-only and cannot represent an invalid state like if (a &&) ...
struct Hanlder
{ bool hasIf bool hasElse MatchedStatement ok atchedStatement ko //else statement MatchedCondition condition }struct MatchedStatement {
enum Type
//This should be sufficient to represent any supported statement
struct MatchedCondition
{ list<ConditionToken> tokens }struct ConditionToken {
enum Type
union
{ //If one these we require extra data Variable variable LiteralString string LiteralNumber number }}
struct MatchedFunction
{ //First item before "." is considered node string nodeId string functionName }struct Variable
{ //Only one level for now (.) string nodeId string propertyName }For Gerrit Dashboard: QDS-10257 | ||||||
---|---|---|---|---|---|---|
# | Subject | Branch | Project | Status | CR | V |
490499,9 | QmlDesigner: Implement Connection Editor Evaluator | qds/dev | qt-creator/qt-creator | Status: ABANDONED | -1 | 0 |
492899,24 | QmlDesigner: Implement Connection Editor Evaluator and Parser | qds/dev | qt-creator/qt-creator | Status: MERGED | +2 | 0 |
497469,2 | QmlDesigner: Implement Connection Editor Evaluator and Parser | qds/dev | qt-creator/qt-creator | Status: ABANDONED | -1 | 0 |