Skip to content

Commit

Permalink
Merge pull request #339 from wanbing/dev_wanbing
Browse files Browse the repository at this point in the history
dsl support negative value
  • Loading branch information
wanbing authored Sep 1, 2023
2 parents 7eb06cd + 09a1f5c commit 248f73b
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 3 deletions.
1 change: 1 addition & 0 deletions dart2dsl/lib/fairdsl/fair_ast_check_gen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ class AstNodeMapGenerator extends GeneratorForAnnotation<AstNodeCheck> {
'DeclaredSimpleIdentifier':'DeclaredSimpleIdentifier',
'ConstructorDeclarationImpl':'ConstructorDeclarationImpl',
'InterpolationStringImpl':'InterpolationStringImpl',
'PrefixExpressionImpl': 'visitPrefixExpression'
};
if (!(rootExpression?.isProgram??false)) {
return null;
Expand Down
5 changes: 5 additions & 0 deletions dart2dsl/lib/fairdsl/fair_ast_gen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -411,6 +411,11 @@ class CustomAstVisitor extends SimpleAstVisitor<Map> {
return _buildVariableExpression(expression);
}

@override
Map? visitPrefixExpression(PrefixExpression node){
return _buildPrefixExpression(_visitNode(node.operand), node.operator.toString(), true);
}

///根节点
Map? _buildAstRoot(List<Map> body) {
if (body.isNotEmpty) {
Expand Down
4 changes: 2 additions & 2 deletions dart2dsl/lib/fairdsl/fair_ast_node.dart
Original file line number Diff line number Diff line change
Expand Up @@ -481,7 +481,7 @@ class NamedExpression extends AstNode {

class PrefixExpression extends AstNode {
///操作的变量名称
String? argument;
Expression? argument;

///操作符
String? operator;
Expand All @@ -495,7 +495,7 @@ class PrefixExpression extends AstNode {
static PrefixExpression? fromAst(Map? ast) {
if (ast != null &&
ast['type'] == astNodeNameValue(AstNodeName.PrefixExpression)) {
return PrefixExpression(Identifier.fromAst(ast['argument'])?.name,
return PrefixExpression(Expression.fromAst(ast['argument']),
ast['operator'], ast['prefix'] as bool,
ast: ast);
}
Expand Down
3 changes: 2 additions & 1 deletion dart2dsl/lib/fairdsl/fair_check_node_map.dart
Original file line number Diff line number Diff line change
Expand Up @@ -56,5 +56,6 @@ final checkNode = {
'ExtendsClauseImpl': 'visitExtendsClause',
'ImplementsClauseImpl': 'visitImplementsClause',
'WithClauseImpl': 'visitWithClause',
'PropertyAccessImpl': 'visitPropertyAccess'
'PropertyAccessImpl': 'visitPropertyAccess',
'PrefixExpressionImpl': 'visitPrefixExpression'
};
20 changes: 20 additions & 0 deletions dart2dsl/lib/fairdsl/fair_dsl_gen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -426,6 +426,26 @@ dynamic _buildValueExpression(
} else if (valueExpression?.isVariableExpression==true) {
var expression = valueExpression?.asVariableExpression.expression??'';
naPaValue = '\$(' + expression + ')';
} else if (valueExpression?.isPrefixExpression == true) {
var argument = _buildValueExpression(
valueExpression?.asPrefixExpression.argument, fairDslContex);
if (valueExpression?.asPrefixExpression.prefix ?? true) {
if (argument is num) {
if (valueExpression?.asPrefixExpression.operator == '-') {
naPaValue = -argument;
} else {
naPaValue = argument;
}
} else {
naPaValue = '${valueExpression?.asPrefixExpression.prefix}$argument';
}
} else {
if (argument is num) {
naPaValue = argument;
} else {
naPaValue = '$argument${valueExpression?.asPrefixExpression.prefix}';
}
}
} else {
naPaValue = _buildWidgetDsl(valueExpression, fairDslContex);
}
Expand Down

0 comments on commit 248f73b

Please sign in to comment.