-
Notifications
You must be signed in to change notification settings - Fork 323
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Space-precedence does not apply to value-level operators (#10597)
In a sequence of value-level operators, whitespace does not affect relative precedence. Functional operators still follow the space-precedence rules. The "functional" operators are: `>> << |> |>> <| <<| : .`, application, and any operator containing `<-` or `->`. All other operators are considered value-level operators. Asymmetric whitespace can still be used to form *operator sections* of value-level operators, e.g. `+2 * 3` is still equivalent to `x -> (x+2) * 3`. Precedence of application is unchanged, so `f x+y` is still equivalent to `f (x + y)` and `f x+y * z` is still equivalent to `(f (x + y)) * z`. Any attempt to use spacing to override value-level operator precedence will be caught by the new enso linter. Mixed spacing (for clarity) in value-operator expressions is allowed, as long as it is consistent with the precedences of the operators. Closes #10366. # Important Notes Precedence warnings: - The parser emits a warning if the whitespace in an expression is inconsistent with its effective precedence. - A new enso linter can be run with `./run libraries lint`. It parses all `.enso` files in `distribution/lib` and `test`, and reports any errors or warnings. It can also be run on individual files: `cargo run --release --bin check_syntax -- file1 file2...` (the result may be easier to read than the `./run` output). - The linter is also run as part of `./run lint`, so it is checked in CI. Additional language change: - The exponentiation operator (`^`) now has higher precedence than the multiplication class (`*`, `/`, `%`). This change did not affect any current enso files. Library changes: - The libraries have been updated. The new warnings were used to identify all affected code; the changes themselves have not been programmatically verified (in many cases their equivalence relies on the commutativity of string concatenation). (cherry picked from commit e5b85bf)
- Loading branch information
1 parent
78c31e8
commit 7f52a82
Showing
43 changed files
with
958 additions
and
382 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -74,6 +74,7 @@ | |
<edition>.yaml: | ||
enso.bundle.template: | ||
launcher-manifest.yaml: | ||
lib: | ||
engine/: | ||
runner/: | ||
src/: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,4 +5,5 @@ use crate::prelude::*; | |
// === Export === | ||
// ============== | ||
|
||
pub mod enso_linter; | ||
pub mod parser; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
use super::*; | ||
|
||
use ide_ci::programs::cargo; | ||
use ide_ci::programs::Cargo; | ||
|
||
use crate::paths::generated::RepoRoot; | ||
|
||
const LINTER_CRATE_NAME: &str = "enso-parser-debug"; | ||
const LINTER_BIN_NAME: &str = "check_syntax"; | ||
const ENSO_EXTENSION: &str = ".enso"; | ||
|
||
pub fn cargo_run_linter_cmd(repo_root: &Path) -> Result<Command> { | ||
let mut ret = Cargo.cmd()?; | ||
ret.current_dir(repo_root) | ||
.apply(&cargo::Command::Run) | ||
.apply(&cargo::Options::Package(LINTER_CRATE_NAME.into())) | ||
.apply(&cargo::RunOption::Bin(LINTER_BIN_NAME.into())) | ||
.apply(&cargo::RunOption::Release); | ||
Ok(ret) | ||
} | ||
|
||
fn collect_source_paths(repo_root: &RepoRoot) -> Result<Vec<PathBuf>> { | ||
let glob_pattern = format!("**/*{ENSO_EXTENSION}"); | ||
let source_roots = [&repo_root.distribution.lib.path, &repo_root.test.path]; | ||
let glob_paths: Vec<_> = source_roots | ||
.into_iter() | ||
.map(|path| glob::glob(path.join(&glob_pattern).as_str())) | ||
.collect::<std::result::Result<_, _>>()?; | ||
Ok(glob_paths.into_iter().flatten().collect::<std::result::Result<_, _>>()?) | ||
} | ||
|
||
pub async fn lint_all(repo_root: RepoRoot) -> Result<()> { | ||
let sources = collect_source_paths(&repo_root)?; | ||
cargo_run_linter_cmd(&repo_root)?.arg("--").args(sources).run_ok().await?; | ||
Ok(()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.