Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix:double.infinity 生成异常 #353

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions dart2dsl/lib/fairdsl/fair_ast_gen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -413,6 +413,9 @@ class CustomAstVisitor extends SimpleAstVisitor<Map> {

@override
Map? visitPrefixExpression(PrefixExpression node){
if(node.operator.type == TokenType.MINUS && (node.operand is DoubleLiteral || node.operand is IntegerLiteral)){
return _buildNumericLiteral(num.parse(node.operand.toSource()) * -1);
}
return _buildPrefixExpression(_visitNode(node.operand), node.operator.toString(), true);
}

Expand Down
17 changes: 16 additions & 1 deletion dart2dsl/lib/fairdsl/fair_dsl_gen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
*/

import 'dart:convert';
import 'dart:io';

import 'package:fair_dart2dsl/fairdsl/fair_ast_logic_unit.dart';

Expand Down Expand Up @@ -320,6 +321,20 @@ dynamic _buildWidgetDsl(
return dslMap;
}

bool isDoubleProperty(PrefixedIdentifier? node) {
if (!(node is PrefixedIdentifier) || node.prefix != 'double') {
return false;
}

switch (node.identifier) {
case 'infinity':
return true;
default:
stdout.writeln('Fair 不支持该 常量 double ${node.identifier}');
return false;
}
}

dynamic _buildValueExpression(
Expression? valueExpression, FairDslContex? fairDslContex) {
var naPaValue;
Expand Down Expand Up @@ -349,7 +364,7 @@ dynamic _buildValueExpression(
naPaValue = valueExpression?.asBooleanLiteral.value;
} else if (valueExpression?.isPrefixedIdentifier==true) {
if (RegExp(r'^[a-z_]') // widget.** 参数类的特殊处理成#(),兼容1期
.hasMatch(valueExpression?.asPrefixedIdentifier.prefix??'') && ('widget' != valueExpression?.asPrefixedIdentifier.prefix)) {
.hasMatch(valueExpression?.asPrefixedIdentifier.prefix??'') && ('widget' != valueExpression?.asPrefixedIdentifier.prefix) && !isDoubleProperty(valueExpression?.asPrefixedIdentifier)) {
naPaValue = '\$(' +
(valueExpression?.asPrefixedIdentifier.prefix??'') +
'.' +
Expand Down
Loading