Skip to content

Commit

Permalink
WIP: Refactor and improve file loading.
Browse files Browse the repository at this point in the history
  • Loading branch information
kaj committed Jul 21, 2022
1 parent a168e69 commit d72de09
Show file tree
Hide file tree
Showing 26 changed files with 571 additions and 455 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ project adheres to
now holds a `Name` rather than just a `String` for the variable name.
Also, both now holds a `SourcePos`.
* `Error::error` now takes an `Into<String>` argument (PR #151).
* The module `input` contains types types with `Context<L>`, `Loader`,
`FsLoader`, and `FsContext`, replacing the old `FileContext` and
`FsFileContext`. Also, the types `SourceKind` and `SourceName` are moved
from top-level into the `input` module (PR #150).

### Improvements

Expand All @@ -41,6 +45,9 @@ project adheres to
error reporting improvements (PR #148).
* Allow interpolation in css min and max function arguments.
* The url for `@use` and `@forward` must be quoted.
* Improve detection of import loops (PR #150).
* When loading files, Don't apply suffix / index-adding rules if the file
name already has a suffix (PR #150).
* Some `@` rules are now forbidden in some places as they should (PR #145).
* The css `var(...)` function is now parsed as a proper function, and not
as a special string (PR #147).
Expand All @@ -53,6 +60,7 @@ project adheres to
* Somtimes a trailing comma in argument lists is preserved (PR #147).
* Simplified `main` of the command-line by returning a `Result` (PR #151).
* Update sass-spec test suite to 2022-07-18.
* Use `lazy-regex` in spectest.
* Some cleanups.

Thanks to @fasterthanlime (again) for reporting the problem with
Expand Down
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ required-features = ["spectest"]

[features]
commandline = ["clap"]
spectest = ["yaml-rust", "deunicode", "hrx-get", "regex"]
spectest = ["yaml-rust", "deunicode", "hrx-get", "lazy-regex"]
unimplemented_args = []

[dependencies]
Expand All @@ -41,7 +41,7 @@ tracing = "0.1.34"
clap = { version = "3.0.0", features = ["derive", "wrap_help"], optional = true }
deunicode = { version = "1.0", optional = true }
hrx-get = { version = "0.2.0", optional = true }
regex = { version = "1.1.0", optional = true }
lazy-regex = { version = "2.3.0", optional = true }
yaml-rust = { version = "0.4", optional = true }

[badges]
Expand Down
27 changes: 20 additions & 7 deletions src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@ pub enum Error {
/// This error will be wrapped in a BadCall, giving the pos of the call.
BadArguments(ArgsError, SourcePos),
/// Tried to import file at pos while already importing it at pos.
ImportLoop(SourcePos, SourcePos),
///
/// The bool is true for a used module and false for an import.
ImportLoop(bool, SourcePos, Option<SourcePos>),
/// A range error
BadRange(RangeError),
/// Error parsing sass data.
Expand Down Expand Up @@ -61,12 +63,23 @@ impl fmt::Debug for Error {
write!(out, "${}: {}", name, problem)
}
Error::ParseError(ref err) => err.fmt(out),
Error::ImportLoop(ref pos, ref oldpos) => {
writeln!(out, "This file is already being loaded.")?;
pos.show_detail(out, '^', " new load")?;
writeln!(out)?;
oldpos.show_detail(out, '=', " original load")?;
pos.show_files(out)
Error::ImportLoop(ref module, ref pos, ref oldpos) => {
if *module {
writeln!(
out,
"Module loop: this module is already being loaded."
)?;
} else {
writeln!(out, "This file is already being loaded.")?;
}
if let Some(oldpos) = oldpos {
pos.show_detail(out, '^', " new load")?;
writeln!(out)?;
oldpos.show_detail(out, '=', " original load")?;
pos.show_files(out)
} else {
pos.show(out)
}
}
Error::BadCall(ref msg, ref callpos, ref declpos) => {
writeln!(out, "{}", msg)?;
Expand Down
210 changes: 0 additions & 210 deletions src/file_context.rs

This file was deleted.

Loading

0 comments on commit d72de09

Please sign in to comment.