use std::error; use std::ffi::OsStr; use std::fmt; use std::fs::{self, File, OpenOptions}; use std::io::{self, Read, Seek, SeekFrom, Write}; use std::mem; use std::ops::Deref; #[cfg(target_os = "wasi")] use std::os::fd::{AsFd, AsRawFd, BorrowedFd, RawFd}; #[cfg(unix)] // we don't use std::os::fd because that's not available on rust 1.63. use std::os::unix::io::{AsFd, AsRawFd, BorrowedFd, RawFd}; #[cfg(windows)] use std::os::windows::io::{AsHandle, AsRawHandle, BorrowedHandle, RawHandle}; use std::path::{Path, PathBuf};
/// Create a new temporary file. Also see [`tempfile_in`]. /// /// The file will be created in the location returned by [`env::temp_dir()`]. /// /// # Security /// /// This variant is secure/reliable in the presence of a pathological temporary file cleaner. /// /// # Resource Leaking /// /// The temporary file will be automatically removed by the OS when the last handle to it is closed. /// This doesn't rely on Rust destructors being run, so will (almost) never fail to clean up the temporary file. /// /// # Errors /// /// If the file can not be created, `Err` is returned. /// /// # Examples /// /// ``` /// use tempfile::tempfile; /// use std::io::Write; /// /// // Create a file inside of `env::temp_dir()`. /// let mut file = tempfile()?; /// /// writeln!(file, "Brian was here. Briefly.")?; /// # Ok::<(), std::io::Error>(()) /// ``` pubfn tempfile() -> io::Result<File> {
tempfile_in(env::temp_dir())
}
/// Create a new temporary file in the specified directory. Also see [`tempfile`]. /// /// # Security /// /// This variant is secure/reliable in the presence of a pathological temporary file cleaner. /// If the temporary file isn't created in [`env::temp_dir()`] then temporary file cleaners aren't an issue. /// /// # Resource Leaking /// /// The temporary file will be automatically removed by the OS when the last handle to it is closed. /// This doesn't rely on Rust destructors being run, so will (almost) never fail to clean up the temporary file. /// /// # Errors /// /// If the file can not be created, `Err` is returned. /// /// # Examples /// /// ``` /// use tempfile::tempfile_in; /// use std::io::Write; /// /// // Create a file inside of the current working directory /// let mut file = tempfile_in("./")?; /// /// writeln!(file, "Brian was here. Briefly.")?; /// # Ok::<(), std::io::Error>(()) /// ``` pubfn tempfile_in<P: AsRef<Path>>(dir: P) -> io::Result<File> {
imp::create(dir.as_ref())
}
/// Error returned when persisting a temporary file path fails. #[derive(Debug)] pubstruct PathPersistError { /// The underlying IO error. pub error: io::Error, /// The temporary file path that couldn't be persisted. pub path: TempPath,
}
/// A path to a named temporary file without an open file handle. /// /// This is useful when the temporary file needs to be used by a child process, /// for example. /// /// When dropped, the temporary file is deleted unless `disable_cleanup(true)` was called on the /// builder that constructed this temporary file and/or was called on either this `TempPath` or the /// `NamedTempFile` from which this `TempPath` was constructed. pubstruct TempPath {
path: Box<Path>,
disable_cleanup: bool,
}
impl TempPath { /// Close and remove the temporary file. /// /// Use this if you want to detect errors in deleting the file. /// /// # Errors /// /// If the file cannot be deleted, `Err` is returned. /// /// # Examples /// /// ```no_run /// use tempfile::NamedTempFile; /// /// let file = NamedTempFile::new()?; /// /// // Close the file, but keep the path to it around. /// let path = file.into_temp_path(); /// /// // By closing the `TempPath` explicitly, we can check that it has /// // been deleted successfully. If we don't close it explicitly, the /// // file will still be deleted when `file` goes out of scope, but we /// // won't know whether deleting the file succeeded. /// path.close()?; /// # Ok::<(), std::io::Error>(()) /// ``` pubfn close(mutself) -> io::Result<()> { let result = fs::remove_file(&self.path).with_err_path(|| &* style='color:red'>self.path); self.path = PathBuf::new().into_boxed_path();
mem::forget(self);
result
}
/// Persist the temporary file at the target path. /// /// If a file exists at the target path, persist will atomically replace it. /// If this method fails, it will return `self` in the resulting /// [`PathPersistError`]. /// /// Note: Temporary files cannot be persisted across filesystems. Also /// neither the file contents nor the containing directory are /// synchronized, so the update may not yet have reached the disk when /// `persist` returns. /// /// # Security /// /// Only use this method if you're positive that a temporary file cleaner /// won't have deleted your file. Otherwise, you might end up persisting an /// attacker controlled file. /// /// # Errors /// /// If the file cannot be moved to the new location, `Err` is returned. /// /// # Examples /// /// ```no_run /// use std::io::Write; /// use tempfile::NamedTempFile; /// /// let mut file = NamedTempFile::new()?; /// writeln!(file, "Brian was here. Briefly.")?; /// /// let path = file.into_temp_path(); /// path.persist("./saved_file.txt")?; /// # Ok::<(), std::io::Error>(()) /// ``` /// /// [`PathPersistError`]: struct.PathPersistError.html pubfn persist<P: AsRef<Path>>(mutself, new_path: P) -> Result<(), PathPersistError> { match imp::persist(&self.path, new_path.as_ref(), true) {
Ok(_) => { // Don't drop `self`. We don't want to try deleting the old // temporary file path. (It'll fail, but the failure is never // seen.) self.path = PathBuf::new().into_boxed_path();
mem::forget(self);
Ok(())
}
Err(e) => Err(PathPersistError {
error: e,
path: self,
}),
}
}
/// Persist the temporary file at the target path if and only if no file exists there. /// /// If a file exists at the target path, fail. If this method fails, it will /// return `self` in the resulting [`PathPersistError`]. /// /// Note: Temporary files cannot be persisted across filesystems. Also Note: /// This method is not atomic. It can leave the original link to the /// temporary file behind. /// /// # Security /// /// Only use this method if you're positive that a temporary file cleaner /// won't have deleted your file. Otherwise, you might end up persisting an /// attacker controlled file. /// /// # Errors /// /// If the file cannot be moved to the new location or a file already exists /// there, `Err` is returned. /// /// # Examples /// /// ```no_run /// use tempfile::NamedTempFile; /// use std::io::Write; /// /// let mut file = NamedTempFile::new()?; /// writeln!(file, "Brian was here. Briefly.")?; /// /// let path = file.into_temp_path(); /// path.persist_noclobber("./saved_file.txt")?; /// # Ok::<(), std::io::Error>(()) /// ``` /// /// [`PathPersistError`]: struct.PathPersistError.html pubfn persist_noclobber<P: AsRef<Path>>( mutself,
new_path: P,
) -> Result<(), PathPersistError> { match imp::persist(&self.path, new_path.as_ref(), false) {
Ok(_) => { // Don't drop `self`. We don't want to try deleting the old // temporary file path. (It'll fail, but the failure is never // seen.) self.path = PathBuf::new().into_boxed_path();
mem::forget(self);
Ok(())
}
Err(e) => Err(PathPersistError {
error: e,
path: self,
}),
}
}
/// Keep the temporary file from being deleted. This function will turn the /// temporary file into a non-temporary file without moving it. /// /// # Errors /// /// On some platforms (e.g., Windows), we need to mark the file as /// non-temporary. This operation could fail. /// /// # Examples /// /// ```no_run /// use std::io::Write; /// use tempfile::NamedTempFile; /// /// let mut file = NamedTempFile::new()?; /// writeln!(file, "Brian was here. Briefly.")?; /// /// let path = file.into_temp_path(); /// let path = path.keep()?; /// # Ok::<(), std::io::Error>(()) /// ``` /// /// [`PathPersistError`]: struct.PathPersistError.html pubfn keep(mutself) -> Result<PathBuf, PathPersistError> { match imp::keep(&self.path) {
Ok(_) => { self.disable_cleanup(true);
Ok(mem::replace(
&mutself.path, // Replace with an empty boxed path buf, this doesn't allocate.
PathBuf::new().into_boxed_path(),
)
.into_path_buf())
}
Err(e) => Err(PathPersistError {
error: e,
path: self,
}),
}
}
/// Disable cleanup of the temporary file. If `disable_cleanup` is `true`, the temporary file /// will not be deleted when this `TempPath` is dropped. This method is equivalent to calling /// [`Builder::disable_cleanup`] when creating the original `NamedTempFile`, which see for /// relevant warnings. /// /// **NOTE:** this method is primarily useful for testing/debugging. If you want to simply turn /// a temporary file-path into a non-temporary file-path, prefer [`TempPath::keep`]. pubfn disable_cleanup(&mutself, disable_cleanup: bool) { self.disable_cleanup = disable_cleanup
}
/// Create a new TempPath from an existing path. This can be done even if no file exists at the /// given path. /// /// This is mostly useful for interacting with libraries and external components that provide /// files to be consumed or expect a path with no existing file to be given. /// /// When passed a relative path, this function first tries to make it absolute (relative to the /// current directory). If this fails, this function uses the relative path as-is. /// /// **DEPRECATED:** Use [`TempPath::try_from_path`] instead to handle the case where looking up /// the current directory fails. #[deprecated = "use TempPath::try_from_path"] pubfn from_path(path: impl Into<PathBuf>) -> Self { letmut path = path.into(); // Best effort to resolve a relative path. If we fail, we keep the path as-is to // preserve backwards compatibility. // // Ignore empty paths entirely. There's nothing we can do about them. if path != Path::new("") && !path.is_absolute() { iflet Ok(cur_dir) = std::env::current_dir() {
path = cur_dir.join(path);
}
} Self {
path: path.into_boxed_path(),
disable_cleanup: false,
}
}
/// Create a new TempPath from an existing path. This can be done even if no file exists at the /// given path. /// /// This is mostly useful for interacting with libraries and external components that provide /// files to be consumed or expect a path with no existing file to be given. /// /// Relative paths are resolved relative to the current working directory. If the passed path is /// empty or if the current working directory cannot be determined, this function returns an /// error. /// /// **NOTE:** this function does not check if the target path exists. pubfn try_from_path(path: impl Into<PathBuf>) -> io::Result<Self> { letmut path = path.into(); if !path.is_absolute() { if path == Path::new("") { return Err(io::Error::new(
io::ErrorKind::InvalidInput, "cannot construct a TempPath from an empty path",
));
} letmut cwd = std::env::current_dir()?;
cwd.push(path);
path = cwd;
};
/// A named temporary file. /// /// The default constructor, [`NamedTempFile::new()`], creates files in /// the location returned by [`env::temp_dir()`], but `NamedTempFile` /// can be configured to manage a temporary file in any location /// by constructing with [`NamedTempFile::new_in()`]. /// /// # Security /// /// Most operating systems employ temporary file cleaners to delete old /// temporary files. Unfortunately these temporary file cleaners don't always /// reliably _detect_ whether the temporary file is still being used. /// /// Specifically, the following sequence of events can happen: /// /// 1. A user creates a temporary file with `NamedTempFile::new()`. /// 2. Time passes. /// 3. The temporary file cleaner deletes (unlinks) the temporary file from the /// filesystem. /// 4. Some other program creates a new file to replace this deleted temporary /// file. /// 5. The user tries to re-open the temporary file (in the same program or in a /// different program) by path. Unfortunately, they'll end up opening the /// file created by the other program, not the original file. /// /// ## Operating System Specific Concerns /// /// The behavior of temporary files and temporary file cleaners differ by /// operating system. /// /// ### Windows /// /// On Windows, temporary files are, by default, created in per-user temporary /// file directories so only an application running as the same user would be /// able to interfere (which they could do anyways). However, an application /// running as the same user can still _accidentally_ re-create deleted /// temporary files if the number of random bytes in the temporary file name is /// too small. /// /// ### MacOS /// /// Like on Windows, temporary files are created in per-user temporary file /// directories by default so calling `NamedTempFile::new()` should be /// relatively safe. /// /// ### Linux /// /// Unfortunately, most _Linux_ distributions don't create per-user temporary /// file directories. Worse, systemd's tmpfiles daemon (a common temporary file /// cleaner) will happily remove open temporary files if they haven't been /// modified within the last 10 days. /// /// # Resource Leaking /// /// If the program exits before the `NamedTempFile` destructor is /// run, the temporary file will not be deleted. This can happen /// if the process exits using [`std::process::exit()`], a segfault occurs, /// receiving an interrupt signal like `SIGINT` that is not handled, or by using /// a statically declared `NamedTempFile` instance (like with [`lazy_static`]). /// /// Use the [`tempfile()`] function unless you need a named file path. /// /// [`tempfile()`]: fn.tempfile.html /// [`NamedTempFile::new()`]: #method.new /// [`NamedTempFile::new_in()`]: #method.new_in /// [`std::process::exit()`]: http://doc.rust-lang.org/std/process/fn.exit.html /// [`lazy_static`]: https://github.com/rust-lang-nursery/lazy-static.rs/issues/62 pubstruct NamedTempFile<F = File> {
path: TempPath,
file: F,
}
/// Error returned when persisting a temporary file fails. pubstruct PersistError<F = File> { /// The underlying IO error. pub error: io::Error, /// The temporary file that couldn't be persisted. pub file: NamedTempFile<F>,
}
impl NamedTempFile<File> { /// Create a new named temporary file. /// /// See [`Builder`] for more configuration. /// /// # Security /// /// This will create a temporary file in the default temporary file /// directory (platform dependent). This has security implications on many /// platforms so please read the security section of this type's /// documentation. /// /// Reasons to use this method: /// /// 1. The file has a short lifetime and your temporary file cleaner is /// sane (doesn't delete recently accessed files). /// /// 2. You trust every user on your system (i.e. you are the only user). /// /// 3. You have disabled your system's temporary file cleaner or verified /// that your system doesn't have a temporary file cleaner. /// /// Reasons not to use this method: /// /// 1. You'll fix it later. No you won't. /// /// 2. You don't care about the security of the temporary file. If none of /// the "reasons to use this method" apply, referring to a temporary /// file by name may allow an attacker to create/overwrite your /// non-temporary files. There are exceptions but if you don't already /// know them, don't use this method. /// /// # Errors /// /// If the file can not be created, `Err` is returned. /// /// # Examples /// /// Create a named temporary file and write some data to it: /// /// ```no_run /// use std::io::Write; /// use tempfile::NamedTempFile; /// /// let mut file = NamedTempFile::new()?; /// /// writeln!(file, "Brian was here. Briefly.")?; /// # Ok::<(), std::io::Error>(()) /// ``` /// /// [`Builder`]: struct.Builder.html pubfn new() -> io::Result<NamedTempFile> {
Builder::new().tempfile()
}
/// Create a new named temporary file in the specified directory. /// /// This is equivalent to: /// /// ```ignore /// Builder::new().tempfile_in(dir) /// ``` /// /// See [`NamedTempFile::new()`] for details. /// /// [`NamedTempFile::new()`]: #method.new pubfn new_in<P: AsRef<Path>>(dir: P) -> io::Result<NamedTempFile> {
Builder::new().tempfile_in(dir)
}
/// Create a new named temporary file with the specified filename suffix. /// /// See [`NamedTempFile::new()`] for details. /// /// [`NamedTempFile::new()`]: #method.new pubfn with_suffix<S: AsRef<OsStr>>(suffix: S) -> io::Result<NamedTempFile> {
Builder::new().suffix(&suffix).tempfile()
} /// Create a new named temporary file with the specified filename suffix, /// in the specified directory. /// /// This is equivalent to: /// /// ```ignore /// Builder::new().suffix(&suffix).tempfile_in(directory) /// ``` /// /// See [`NamedTempFile::new()`] for details. /// /// [`NamedTempFile::new()`]: #method.new pubfn with_suffix_in<S: AsRef<OsStr>, P: AsRef<Path>>(
suffix: S,
dir: P,
) -> io::Result<NamedTempFile> {
Builder::new().suffix(&suffix).tempfile_in(dir)
}
/// Create a new named temporary file with the specified filename prefix. /// /// See [`NamedTempFile::new()`] for details. /// /// [`NamedTempFile::new()`]: #method.new pubfn with_prefix<S: AsRef<OsStr>>(prefix: S) -> io::Result<NamedTempFile> {
Builder::new().prefix(&prefix).tempfile()
} /// Create a new named temporary file with the specified filename prefix, /// in the specified directory. /// /// This is equivalent to: /// /// ```ignore /// Builder::new().prefix(&prefix).tempfile_in(directory) /// ``` /// /// See [`NamedTempFile::new()`] for details. /// /// [`NamedTempFile::new()`]: #method.new pubfn with_prefix_in<S: AsRef<OsStr>, P: AsRef<Path>>(
prefix: S,
dir: P,
) -> io::Result<NamedTempFile> {
Builder::new().prefix(&prefix).tempfile_in(dir)
}
}
impl<F> NamedTempFile<F> { /// Get the temporary file's path. /// /// # Security /// /// Referring to a temporary file's path may not be secure in all cases. /// Please read the security section on the top level documentation of this /// type for details. /// /// # Examples /// /// ```no_run /// use tempfile::NamedTempFile; /// /// let file = NamedTempFile::new()?; /// /// println!("{:?}", file.path()); /// # Ok::<(), std::io::Error>(()) /// ``` #[inline] pubfn path(&self) -> &Path {
&self.path
}
/// Close and remove the temporary file. /// /// Use this if you want to detect errors in deleting the file. /// /// # Errors /// /// If the file cannot be deleted, `Err` is returned. /// /// # Examples /// /// ```no_run /// use tempfile::NamedTempFile; /// /// let file = NamedTempFile::new()?; /// /// // By closing the `NamedTempFile` explicitly, we can check that it has /// // been deleted successfully. If we don't close it explicitly, /// // the file will still be deleted when `file` goes out /// // of scope, but we won't know whether deleting the file /// // succeeded. /// file.close()?; /// # Ok::<(), std::io::Error>(()) /// ``` pubfn close(self) -> io::Result<()> { let NamedTempFile { path, .. } = self;
path.close()
}
/// Persist the temporary file at the target path. /// /// If a file exists at the target path, persist will atomically replace it. /// If this method fails, it will return `self` in the resulting /// [`PersistError`]. /// /// **Note:** Temporary files cannot be persisted across filesystems. Also /// neither the file contents nor the containing directory are /// synchronized, so the update may not yet have reached the disk when /// `persist` returns. /// /// # Security /// /// This method persists the temporary file using its path and may not be /// secure in all cases. Please read the security section on the top /// level documentation of this type for details. /// /// # Errors /// /// If the file cannot be moved to the new location, `Err` is returned. /// /// # Examples /// /// ```no_run /// use std::io::Write; /// use tempfile::NamedTempFile; /// /// let file = NamedTempFile::new()?; /// /// let mut persisted_file = file.persist("./saved_file.txt")?; /// writeln!(persisted_file, "Brian was here. Briefly.")?; /// # Ok::<(), std::io::Error>(()) /// ``` /// /// [`PersistError`]: struct.PersistError.html pubfn persist<P: AsRef<Path>>(self, new_path: P) -> Result<F, PersistError<F>> { let NamedTempFile { path, file } = self; match path.persist(new_path) {
Ok(_) => Ok(file),
Err(err) => { let PathPersistError { error, path } = err;
Err(PersistError {
file: NamedTempFile { path, file },
error,
})
}
}
}
/// Persist the temporary file at the target path if and only if no file exists there. /// /// If a file exists at the target path, fail. If this method fails, it will /// return `self` in the resulting PersistError. /// /// **Note:** Temporary files cannot be persisted across filesystems. /// /// **Atomicity:** This method is not guaranteed to be atomic on all platforms, although it will /// generally be atomic on Windows and modern Linux filesystems. While it will never overwrite a /// file at the target path, it may leave the original link to the temporary file behind leaving /// you with two [hard links][hardlink] in your filesystem pointing at the same underlying file. /// This can happen if either (a) we lack permission to "unlink" the original filename; (b) this /// program crashes while persisting the temporary file; or (c) the filesystem is removed, /// unmounted, etc. while we're performing this operation. /// /// # Security /// /// This method persists the temporary file using its path and may not be /// secure in all cases. Please read the security section on the top /// level documentation of this type for details. /// /// # Errors /// /// If the file cannot be moved to the new location or a file already exists there, /// `Err` is returned. /// /// # Examples /// /// ```no_run /// use std::io::Write; /// use tempfile::NamedTempFile; /// /// let file = NamedTempFile::new()?; /// /// let mut persisted_file = file.persist_noclobber("./saved_file.txt")?; /// writeln!(persisted_file, "Brian was here. Briefly.")?; /// # Ok::<(), std::io::Error>(()) /// ``` /// /// [hardlink]: https://en.wikipedia.org/wiki/Hard_link pubfn persist_noclobber<P: AsRef<Path>>(self, new_path: P) -> Result<F, PersistError<F>> { let NamedTempFile { path, file } = self; match path.persist_noclobber(new_path) {
Ok(_) => Ok(file),
Err(err) => { let PathPersistError { error, path } = err;
Err(PersistError {
file: NamedTempFile { path, file },
error,
})
}
}
}
/// Keep the temporary file from being deleted. This function will turn the /// temporary file into a non-temporary file without moving it. /// /// # Errors /// /// On some platforms (e.g., Windows), we need to mark the file as /// non-temporary. This operation could fail. /// /// # Examples /// /// ```no_run /// use std::io::Write; /// use tempfile::NamedTempFile; /// /// let mut file = NamedTempFile::new()?; /// writeln!(file, "Brian was here. Briefly.")?; /// /// let (file, path) = file.keep()?; /// # Ok::<(), std::io::Error>(()) /// ``` /// /// [`PathPersistError`]: struct.PathPersistError.html pubfn keep(self) -> Result<(F, PathBuf), PersistError<F>> { let (file, path) = (self.file, self.path); match path.keep() {
Ok(path) => Ok((file, path)),
Err(PathPersistError { error, path }) => Err(PersistError {
file: NamedTempFile { path, file },
error,
}),
}
}
/// Disable cleanup of the temporary file. If `disable_cleanup` is `true`, the temporary file /// will not be deleted when this `TempPath` is dropped. This method is equivalent to calling /// [`Builder::disable_cleanup`] when creating the original `NamedTempFile`, which see for /// relevant warnings. /// /// **NOTE:** this method is primarily useful for testing/debugging. If you want to simply turn /// a temporary file into a non-temporary file, prefer [`NamedTempFile::keep`]. pubfn disable_cleanup(&mutself, disable_cleanup: bool) { self.path.disable_cleanup(disable_cleanup)
}
/// Get a reference to the underlying file. pubfn as_file(&self) -> &F {
&self.file
}
/// Get a mutable reference to the underlying file. pubfn as_file_mut(&mutself) -> &mut F {
&mutself.file
}
/// Turn this named temporary file into an "unnamed" temporary file as if you /// had constructed it with [`tempfile()`]. /// /// The underlying file will be removed from the filesystem but the returned [`File`] /// can still be read/written. pubfn into_file(self) -> F { self.file
}
/// Closes the file, leaving only the temporary file path. /// /// This is useful when another process must be able to open the temporary /// file. pubfn into_temp_path(self) -> TempPath { self.path
}
/// Converts the named temporary file into its constituent parts. /// /// Note: When the path is dropped, the underlying file will be removed from the filesystem but /// the returned [`File`] can still be read/written. pubfn into_parts(self) -> (F, TempPath) {
(self.file, self.path)
}
/// Creates a `NamedTempFile` from its constituent parts. /// /// This can be used with [`NamedTempFile::into_parts`] to reconstruct the /// `NamedTempFile`. pubfn from_parts(file: F, path: TempPath) -> Self { Self { file, path }
}
}
impl NamedTempFile<File> { /// Securely reopen the temporary file. /// /// This function is useful when you need multiple independent handles to /// the same file. It's perfectly fine to drop the original `NamedTempFile` /// while holding on to `File`s returned by this function; the `File`s will /// remain usable. However, they may not be nameable. /// /// # Errors /// /// If the file cannot be reopened, `Err` is returned. /// /// # Security /// /// Unlike `File::open(my_temp_file.path())`, `NamedTempFile::reopen()` /// guarantees that the re-opened file is the _same_ file, even in the /// presence of pathological temporary file cleaners. /// /// # Examples /// /// ```no_run /// use tempfile::NamedTempFile; /// /// let file = NamedTempFile::new()?; /// /// let another_handle = file.reopen()?; /// # Ok::<(), std::io::Error>(()) /// ``` pubfn reopen(&self) -> io::Result<File> {
imp::reopen(self.as_file(), NamedTempFile::path(self))
.with_err_path(|| NamedTempFile::path(self))
}
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.