feat: update expressions.

master
DebuggerX 4 years ago
parent 87e9eafe73
commit 760e574728

@ -122,6 +122,10 @@ class ExpressionEvaluator {
return left / right(); return left / right();
case '%': case '%':
return left % right(); return left % right();
case 'in':
return (right() as List).contains(left);
case 'notIn':
return !(right() as List).contains(left);
} }
throw ArgumentError( throw ArgumentError(
'Unknown operator ${expression.operator} in expression'); 'Unknown operator ${expression.operator} in expression');

@ -123,7 +123,9 @@ class ExpressionParser {
'-': 9, '-': 9,
'*': 10, '*': 10,
'/': 10, '/': 10,
'%': 10 '%': 10,
'in': 11,
'notIn': 11,
}; };
// This function is responsible for gobbling an individual expression, // This function is responsible for gobbling an individual expression,

@ -2,6 +2,19 @@ import 'dart:io';
import 'parse_arguments.dart'; import 'parse_arguments.dart';
import 'expressions/expressions.dart'; import 'expressions/expressions.dart';
const FLAVORS = [
'test',
'tw',
'cn',
];
final _ctx = {
'debug': 'debug',
'release': 'release',
'profile': 'profile',
'default': 'default',
};
String? exp; String? exp;
late String mode; late String mode;
late String flavor; late String flavor;
@ -19,6 +32,13 @@ void main(List<String> arguments) {
mode = args.mode; mode = args.mode;
flavor = args.flavor; flavor = args.flavor;
_ctx.addEntries(FLAVORS.map((e) => MapEntry(e, e)));
_ctx.addAll({
'mode': mode,
'flavor': flavor,
});
var rootDir = Directory('./'); var rootDir = Directory('./');
rootDir.listSync().forEach(walkPath); rootDir.listSync().forEach(walkPath);
} }
@ -67,8 +87,7 @@ void walkPath(FileSystemEntity path) {
state = STATE.none; state = STATE.none;
tmp.clear(); tmp.clear();
} else { } else {
if (evaluator.eval( if (evaluator.eval(Expression.parse(exp!), _ctx)) {
Expression.parse(exp!), {'mode': mode, 'flavor': flavor})) {
// //
tmp.clear(); tmp.clear();
state = STATE.caching; state = STATE.caching;
@ -90,7 +109,6 @@ void walkPath(FileSystemEntity path) {
if (modified) { if (modified) {
file!.renameSync(path.path + '.bak'); file!.renameSync(path.path + '.bak');
File(path.path).writeAsStringSync(sb.toString(), flush: true); File(path.path).writeAsStringSync(sb.toString(), flush: true);
print(sb.toString());
} }
} catch (e) { } catch (e) {
if (!(e is FileSystemException)) { if (!(e is FileSystemException)) {

@ -6,6 +6,12 @@ SCRIPT_DIR=$(dirname "$SCRIPT_ABS")
# shellcheck disable=SC2005 # shellcheck disable=SC2005
DART_EXE=$(command -v dart) DART_EXE=$(command -v dart)
JUST_REPLACE=0
for i in "$@"
do
[ "$i" == "--replace" ] && JUST_REPLACE=1
done
if [[ ! -x "$DART_EXE" ]]; then if [[ ! -x "$DART_EXE" ]]; then
echo "Can't find dart executable file !" echo "Can't find dart executable file !"
return 1 return 1
@ -30,23 +36,26 @@ fi
${DART_EXE} "$SCRIPT_DIR"/bin/pre_script.dart "$@" ${DART_EXE} "$SCRIPT_DIR"/bin/pre_script.dart "$@"
flutter "$@" if [[ "$JUST_REPLACE" == 0 ]]; then
${DART_EXE} "$SCRIPT_DIR"/bin/after_script.dart "$@" flutter "$@"
if [[ -f "./.hooks/after_script.dart" ]]; then ${DART_EXE} "$SCRIPT_DIR"/bin/after_script.dart "$@"
${DART_EXE} ./.hooks/after_script.dart "$@"
fi
if [[ -f "./after_script.dart" ]]; then if [[ -f "./.hooks/after_script.dart" ]]; then
${DART_EXE} ./after_script.dart "$@" ${DART_EXE} ./.hooks/after_script.dart "$@"
fi fi
if [[ -f "./.hooks/after_script.sh" ]]; then if [[ -f "./after_script.dart" ]]; then
./.hooks/after_script.sh "$@" ${DART_EXE} ./after_script.dart "$@"
fi fi
if [[ -f "./after_script.sh" ]]; then if [[ -f "./.hooks/after_script.sh" ]]; then
./after_script.sh "$@" ./.hooks/after_script.sh "$@"
fi fi
if [[ -f "./after_script.sh" ]]; then
./after_script.sh "$@"
fi
fi

Loading…
Cancel
Save