just/src/delimiter.rs
Casey Rodarmor aa506fa5bd
Allow ignore line endings inside delimiters (#717)
Modify the lexer to keep track of opening `({[` and closing `]})` delimiters.
When the lexer would emit an eol or indent outside of a recipe when there
is at least one open delimiter, emit a whitespace token instead.

This allows expressions to be split on multiple lines, like so:

    x := if 'a' == 'b' {
      'x'
    } else {
      'y'
    }

This does not work inside of recipe body interpolations, although this
restriction might relaxed in the future.
2020-10-27 23:51:17 -07:00

25 lines
414 B
Rust

#[derive(PartialEq, Eq, Debug, Copy, Clone)]
pub(crate) enum Delimiter {
Brace,
Bracket,
Paren,
}
impl Delimiter {
pub(crate) fn open(self) -> char {
match self {
Self::Brace => '{',
Self::Bracket => '[',
Self::Paren => '(',
}
}
pub(crate) fn close(self) -> char {
match self {
Self::Brace => '}',
Self::Bracket => ']',
Self::Paren => ')',
}
}
}