Skip to content

Commit

Permalink
Merge pull request #280 from moonbitlang/allow-empty-logic-operator
Browse files Browse the repository at this point in the history
feat: allow empty logic operator
  • Loading branch information
lijunchen authored Sep 10, 2024
2 parents e3e5132 + 92a2a66 commit bef1052
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 19 deletions.
22 changes: 11 additions & 11 deletions crates/moon/tests/test_cases/cond_comp.in/moon.test
Original file line number Diff line number Diff line change
@@ -1,54 +1,54 @@
$ moon build --dry-run --sort-input --nostd
moonc build-package ./src/lib/all.mbt ./src/lib/not_js.mbt -o ./target/wasm-gc/release/build/lib/lib.core -pkg username/hello/lib -pkg-sources username/hello/lib:./src/lib -target wasm-gc
moonc build-package ./src/lib/all.mbt ./src/lib/js_or_wasm.mbt ./src/lib/not_js.mbt -o ./target/wasm-gc/release/build/lib/lib.core -pkg username/hello/lib -pkg-sources username/hello/lib:./src/lib -target wasm-gc
moonc build-package ./src/main/main.mbt -o ./target/wasm-gc/release/build/main/main.core -pkg username/hello/main -is-main -i ./target/wasm-gc/release/build/lib/lib.mi:lib -pkg-sources username/hello/main:./src/main -target wasm-gc
moonc link-core ./target/wasm-gc/release/build/lib/lib.core ./target/wasm-gc/release/build/main/main.core -main username/hello/main -o ./target/wasm-gc/release/build/main/main.wasm -pkg-sources username/hello/lib:./src/lib -pkg-sources username/hello/main:./src/main -target wasm-gc

$ moon build --target wasm --dry-run --sort-input --nostd
moonc build-package ./src/lib/all.mbt ./src/lib/not_js.mbt -o ./target/wasm/release/build/lib/lib.core -pkg username/hello/lib -pkg-sources username/hello/lib:./src/lib -target wasm
moonc build-package ./src/lib/all.mbt ./src/lib/js_or_wasm.mbt ./src/lib/not_js.mbt -o ./target/wasm/release/build/lib/lib.core -pkg username/hello/lib -pkg-sources username/hello/lib:./src/lib -target wasm
moonc build-package ./src/main/main.mbt -o ./target/wasm/release/build/main/main.core -pkg username/hello/main -is-main -i ./target/wasm/release/build/lib/lib.mi:lib -pkg-sources username/hello/main:./src/main -target wasm
moonc link-core ./target/wasm/release/build/lib/lib.core ./target/wasm/release/build/main/main.core -main username/hello/main -o ./target/wasm/release/build/main/main.wasm -pkg-sources username/hello/lib:./src/lib -pkg-sources username/hello/main:./src/main -target wasm

$ moon build --target wasm-gc --dry-run --sort-input --nostd
moonc build-package ./src/lib/all.mbt ./src/lib/not_js.mbt -o ./target/wasm-gc/release/build/lib/lib.core -pkg username/hello/lib -pkg-sources username/hello/lib:./src/lib -target wasm-gc
moonc build-package ./src/lib/all.mbt ./src/lib/js_or_wasm.mbt ./src/lib/not_js.mbt -o ./target/wasm-gc/release/build/lib/lib.core -pkg username/hello/lib -pkg-sources username/hello/lib:./src/lib -target wasm-gc
moonc build-package ./src/main/main.mbt -o ./target/wasm-gc/release/build/main/main.core -pkg username/hello/main -is-main -i ./target/wasm-gc/release/build/lib/lib.mi:lib -pkg-sources username/hello/main:./src/main -target wasm-gc
moonc link-core ./target/wasm-gc/release/build/lib/lib.core ./target/wasm-gc/release/build/main/main.core -main username/hello/main -o ./target/wasm-gc/release/build/main/main.wasm -pkg-sources username/hello/lib:./src/lib -pkg-sources username/hello/main:./src/main -target wasm-gc

$ moon build --dry-run --target js --sort-input --nostd
moonc build-package ./src/lib/all.mbt ./src/lib/js_and_release.mbt ./src/lib/only_js.mbt -o ./target/js/release/build/lib/lib.core -pkg username/hello/lib -pkg-sources username/hello/lib:./src/lib -target js
moonc build-package ./src/lib/all.mbt ./src/lib/js_and_release.mbt ./src/lib/js_or_wasm.mbt ./src/lib/only_js.mbt -o ./target/js/release/build/lib/lib.core -pkg username/hello/lib -pkg-sources username/hello/lib:./src/lib -target js
moonc build-package ./src/main/main.mbt -o ./target/js/release/build/main/main.core -pkg username/hello/main -is-main -i ./target/js/release/build/lib/lib.mi:lib -pkg-sources username/hello/main:./src/main -target js
moonc link-core ./target/js/release/build/lib/lib.core ./target/js/release/build/main/main.core -main username/hello/main -o ./target/js/release/build/main/main.js -pkg-sources username/hello/lib:./src/lib -pkg-sources username/hello/main:./src/main -target js

$ moon build --dry-run --target wasm --sort-input --nostd --debug
moonc build-package ./src/lib/all.mbt ./src/lib/not_js.mbt ./src/lib/only_debug.mbt -o ./target/wasm/debug/build/lib/lib.core -pkg username/hello/lib -pkg-sources username/hello/lib:./src/lib -target wasm -g
moonc build-package ./src/lib/all.mbt ./src/lib/js_or_wasm.mbt ./src/lib/not_js.mbt ./src/lib/only_debug.mbt -o ./target/wasm/debug/build/lib/lib.core -pkg username/hello/lib -pkg-sources username/hello/lib:./src/lib -target wasm -g
moonc build-package ./src/main/main.mbt -o ./target/wasm/debug/build/main/main.core -pkg username/hello/main -is-main -i ./target/wasm/debug/build/lib/lib.mi:lib -pkg-sources username/hello/main:./src/main -target wasm -g
moonc link-core ./target/wasm/debug/build/lib/lib.core ./target/wasm/debug/build/main/main.core -main username/hello/main -o ./target/wasm/debug/build/main/main.wasm -pkg-sources username/hello/lib:./src/lib -pkg-sources username/hello/main:./src/main -target wasm -g

$ moon build --dry-run --target wasm-gc --sort-input --nostd --debug
moonc build-package ./src/lib/all.mbt ./src/lib/not_js.mbt ./src/lib/only_debug.mbt -o ./target/wasm-gc/debug/build/lib/lib.core -pkg username/hello/lib -pkg-sources username/hello/lib:./src/lib -target wasm-gc -g -source-map
moonc build-package ./src/lib/all.mbt ./src/lib/js_or_wasm.mbt ./src/lib/not_js.mbt ./src/lib/only_debug.mbt -o ./target/wasm-gc/debug/build/lib/lib.core -pkg username/hello/lib -pkg-sources username/hello/lib:./src/lib -target wasm-gc -g -source-map
moonc build-package ./src/main/main.mbt -o ./target/wasm-gc/debug/build/main/main.core -pkg username/hello/main -is-main -i ./target/wasm-gc/debug/build/lib/lib.mi:lib -pkg-sources username/hello/main:./src/main -target wasm-gc -g -source-map
moonc link-core ./target/wasm-gc/debug/build/lib/lib.core ./target/wasm-gc/debug/build/main/main.core -main username/hello/main -o ./target/wasm-gc/debug/build/main/main.wasm -pkg-sources username/hello/lib:./src/lib -pkg-sources username/hello/main:./src/main -target wasm-gc -g -source-map

$ moon build --dry-run --target js --sort-input --nostd --debug
moonc build-package ./src/lib/all.mbt ./src/lib/only_debug.mbt ./src/lib/only_js.mbt -o ./target/js/debug/build/lib/lib.core -pkg username/hello/lib -pkg-sources username/hello/lib:./src/lib -target js -g -source-map
moonc build-package ./src/lib/all.mbt ./src/lib/js_or_wasm.mbt ./src/lib/only_debug.mbt ./src/lib/only_js.mbt -o ./target/js/debug/build/lib/lib.core -pkg username/hello/lib -pkg-sources username/hello/lib:./src/lib -target js -g -source-map
moonc build-package ./src/main/main.mbt -o ./target/js/debug/build/main/main.core -pkg username/hello/main -is-main -i ./target/js/debug/build/lib/lib.mi:lib -pkg-sources username/hello/main:./src/main -target js -g -source-map
moonc link-core ./target/js/debug/build/lib/lib.core ./target/js/debug/build/main/main.core -main username/hello/main -o ./target/js/debug/build/main/main.js -pkg-sources username/hello/lib:./src/lib -pkg-sources username/hello/main:./src/main -target js -g -source-map

$ moon check --dry-run --target js --sort-input --nostd
moonc check ./src/lib/all.mbt ./src/lib/js_and_release.mbt ./src/lib/only_js.mbt -o ./target/js/release/check/lib/lib.mi -pkg username/hello/lib -pkg-sources username/hello/lib:./src/lib -target js
moonc check ./src/lib/all.mbt ./src/lib/js_and_release.mbt ./src/lib/js_or_wasm.mbt ./src/lib/only_js.mbt -o ./target/js/release/check/lib/lib.mi -pkg username/hello/lib -pkg-sources username/hello/lib:./src/lib -target js
moonc check ./src/main/main.mbt -o ./target/js/release/check/main/main.mi -pkg username/hello/main -is-main -i ./target/js/release/check/lib/lib.mi:lib -pkg-sources username/hello/main:./src/main -target js
moonc check ./src/lib/hello_test.mbt ./src/lib/js_only_test.mbt -o ./target/js/release/check/lib/lib.blackbox_test.mi -pkg username/hello/lib_blackbox_test -i ./target/js/release/check/lib/lib.mi:lib -pkg-sources username/hello/lib_blackbox_test:./src/lib -target js

$ moon test --dry-run --target js --sort-input --nostd
moon generate-test-driver --source-dir . --target-dir ./target/js/debug/test --package username/hello/lib --sort-input --target js --driver-kind blackbox
moonc build-package ./src/lib/all.mbt ./src/lib/only_debug.mbt ./src/lib/only_js.mbt -o ./target/js/debug/test/lib/lib.core -pkg username/hello/lib -pkg-sources username/hello/lib:./src/lib -target js -g
moonc build-package ./src/lib/all.mbt ./src/lib/js_or_wasm.mbt ./src/lib/only_debug.mbt ./src/lib/only_js.mbt -o ./target/js/debug/test/lib/lib.core -pkg username/hello/lib -pkg-sources username/hello/lib:./src/lib -target js -g
moonc build-package ./src/lib/hello_test.mbt ./src/lib/js_only_test.mbt ./target/js/debug/test/lib/__generated_driver_for_blackbox_test.mbt -o ./target/js/debug/test/lib/lib.blackbox_test.core -pkg username/hello/lib_blackbox_test -is-main -i ./target/js/debug/test/lib/lib.mi:lib -pkg-sources username/hello/lib_blackbox_test:./src/lib -target js -g
moonc link-core ./target/js/debug/test/lib/lib.core ./target/js/debug/test/lib/lib.blackbox_test.core -main username/hello/lib_blackbox_test -o ./target/js/debug/test/lib/lib.blackbox_test.js -test-mode -pkg-sources username/hello/lib:./src/lib -pkg-sources username/hello/lib_blackbox_test:./src/lib -exported_functions execute -js-format cjs -target js -g
moon generate-test-driver --source-dir . --target-dir ./target/js/debug/test --package username/hello/lib --sort-input --target js --driver-kind internal
moonc build-package ./src/lib/all.mbt ./src/lib/only_debug.mbt ./src/lib/only_js.mbt ./target/js/debug/test/lib/__generated_driver_for_internal_test.mbt -o ./target/js/debug/test/lib/lib.internal_test.core -pkg username/hello/lib -is-main -pkg-sources username/hello/lib:./src/lib -target js -g
moonc build-package ./src/lib/all.mbt ./src/lib/js_or_wasm.mbt ./src/lib/only_debug.mbt ./src/lib/only_js.mbt ./target/js/debug/test/lib/__generated_driver_for_internal_test.mbt -o ./target/js/debug/test/lib/lib.internal_test.core -pkg username/hello/lib -is-main -pkg-sources username/hello/lib:./src/lib -target js -g
moonc link-core ./target/js/debug/test/lib/lib.internal_test.core -main username/hello/lib -o ./target/js/debug/test/lib/lib.internal_test.js -test-mode -pkg-sources username/hello/lib:./src/lib -exported_functions execute -js-format cjs -target js -g

$ moon bundle --dry-run --target js --sort-input --nostd
moonc build-package ./src/lib/all.mbt ./src/lib/js_and_release.mbt ./src/lib/only_js.mbt -o ./target/js/release/bundle/lib/lib.core -pkg username/hello/lib -pkg-sources username/hello/lib:./lib -target js
moonc build-package ./src/lib/all.mbt ./src/lib/js_and_release.mbt ./src/lib/js_or_wasm.mbt ./src/lib/only_js.mbt -o ./target/js/release/bundle/lib/lib.core -pkg username/hello/lib -pkg-sources username/hello/lib:./lib -target js
moonc build-package ./src/main/main.mbt -o ./target/js/release/bundle/main/main.core -pkg username/hello/main -is-main -i ./target/js/release/bundle/lib/lib.mi:lib -pkg-sources username/hello/main:./main -target js
moonc bundle-core ./target/js/release/bundle/lib/lib.core ./target/js/release/bundle/main/main.core -o ./target/js/release/bundle/hello.core

Empty file.
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
{
"targets": {
"only_js.mbt": ["and", "js"],
"only_js.mbt": ["js"],
"not_js.mbt": ["not", "js"],
"only_debug.mbt": ["and", "debug"],
"js_and_release.mbt": ["and", ["or", "js"], ["or", "release"]],
"js_only_test.mbt": ["and", "js"]
"only_debug.mbt": ["debug"],
"js_and_release.mbt": ["and", ["js"], ["release"]],
"js_only_test.mbt": ["js"],
"js_and_wasm.mbt": ["js", "wasm"]
}
}
23 changes: 19 additions & 4 deletions crates/moonutil/src/cond_expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -228,11 +228,26 @@ fn parse_cond_expr(file: &Path, value: &StringOrArray) -> Result<CondExpr, Parse
let logic_op = parse_cond_logic_op(op).map_err(|e| ParseCondExprError {
file: file.to_path_buf(),
source: ParseCondExprErrorKind::ParseCondLogicOpError(e),
})?;
});

let sub_exprs: Result<Vec<CondExpr>, ParseCondExprError> =
iter.map(|x| parse_cond_expr(file, x)).collect();
Ok(CondExpr::Condition(logic_op, sub_exprs?))
match logic_op {
Ok(logic_op) => {
let sub_exprs: Result<Vec<CondExpr>, ParseCondExprError> =
iter.map(|x| parse_cond_expr(file, x)).collect();
Ok(CondExpr::Condition(logic_op, sub_exprs?))
}
Err(_) => {
let atom = parse_cond_target(op).map_err(|e| ParseCondExprError {
file: file.to_path_buf(),
source: ParseCondExprErrorKind::ParseCondAtomError(e),
})?;
let sub_exprs: Result<Vec<CondExpr>, ParseCondExprError> =
iter.map(|x| parse_cond_expr(file, x)).collect();
let mut sub_exprs = sub_exprs?;
sub_exprs.insert(0, atom);
Ok(CondExpr::Condition(LogicOp::Or, sub_exprs))
}
}
}
_ => Err(ParseCondExprError {
file: file.to_path_buf(),
Expand Down

0 comments on commit bef1052

Please sign in to comment.