just/src/line.rs
Casey Rodarmor b2285ce0e0
Reform Parser (#509)
Just's first parser performed both parsing, i.e the transformation of a
token stream according to the language grammar, and a number of consistency
checks and analysis passes.

This made parsing and analysis quite complex, so this diff introduces a
new, much cleaner `Parser`, and moves existing analysis into a dedicated
`Analyzer`.
2019-11-07 10:55:15 -08:00

29 lines
679 B
Rust

use crate::common::*;
/// A single line in a recipe body, consisting of any number of
/// `Fragment`s.
#[derive(Debug, PartialEq)]
pub(crate) struct Line<'src> {
pub(crate) fragments: Vec<Fragment<'src>>,
}
impl<'src> Line<'src> {
pub(crate) fn is_empty(&self) -> bool {
self.fragments.is_empty()
}
pub(crate) fn is_continuation(&self) -> bool {
match self.fragments.last() {
Some(Fragment::Text { token }) => token.lexeme().ends_with('\\'),
_ => false,
}
}
pub(crate) fn is_shebang(&self) -> bool {
match self.fragments.first() {
Some(Fragment::Text { token }) => token.lexeme().starts_with("#!"),
_ => false,
}
}
}