19f7ad09a7
Add conditional expressions of the form: foo := if lhs == rhs { then } else { otherwise } `lhs`, `rhs`, `then`, and `otherwise` are all arbitrary expressions, and can recursively include other conditionals. Conditionals short-circuit, so the branch not taken isn't evaluated. It is also possible to test for inequality with `==`.
72 lines
1.4 KiB
Rust
72 lines
1.4 KiB
Rust
use crate::common::*;
|
|
|
|
#[derive(Debug, PartialEq, Clone, Copy, Ord, PartialOrd, Eq)]
|
|
pub(crate) enum TokenKind {
|
|
Asterisk,
|
|
At,
|
|
Backtick,
|
|
BangEquals,
|
|
BraceL,
|
|
BraceR,
|
|
BracketL,
|
|
BracketR,
|
|
Colon,
|
|
ColonEquals,
|
|
Comma,
|
|
Comment,
|
|
Dedent,
|
|
Eof,
|
|
Eol,
|
|
Equals,
|
|
EqualsEquals,
|
|
Identifier,
|
|
Indent,
|
|
InterpolationEnd,
|
|
InterpolationStart,
|
|
ParenL,
|
|
ParenR,
|
|
Plus,
|
|
StringCooked,
|
|
StringRaw,
|
|
Text,
|
|
Unspecified,
|
|
Whitespace,
|
|
}
|
|
|
|
impl Display for TokenKind {
|
|
fn fmt(&self, f: &mut Formatter) -> Result<(), fmt::Error> {
|
|
use TokenKind::*;
|
|
write!(f, "{}", match *self {
|
|
Asterisk => "'*'",
|
|
At => "'@'",
|
|
Backtick => "backtick",
|
|
BangEquals => "'!='",
|
|
BraceL => "'{'",
|
|
BraceR => "'}'",
|
|
BracketL => "'['",
|
|
BracketR => "']'",
|
|
Colon => "':'",
|
|
ColonEquals => "':='",
|
|
Comma => "','",
|
|
Comment => "comment",
|
|
Dedent => "dedent",
|
|
Eof => "end of file",
|
|
Eol => "end of line",
|
|
Equals => "'='",
|
|
EqualsEquals => "'=='",
|
|
Identifier => "identifier",
|
|
Indent => "indent",
|
|
InterpolationEnd => "'}}'",
|
|
InterpolationStart => "'{{'",
|
|
ParenL => "'('",
|
|
ParenR => "')'",
|
|
Plus => "'+'",
|
|
StringCooked => "cooked string",
|
|
StringRaw => "raw string",
|
|
Text => "command text",
|
|
Whitespace => "whitespace",
|
|
Unspecified => "unspecified",
|
|
})
|
|
}
|
|
}
|