2019-04-11 15:23:14 -07:00
|
|
|
use crate::common::*;
|
2017-11-18 03:36:02 -08:00
|
|
|
|
|
|
|
use CompilationErrorKind::*;
|
2018-12-08 14:29:41 -08:00
|
|
|
use TokenKind::*;
|
2017-11-18 03:36:02 -08:00
|
|
|
|
2019-04-15 22:40:02 -07:00
|
|
|
/// Just language lexer
|
|
|
|
///
|
2020-02-14 04:49:25 -08:00
|
|
|
/// The lexer proceeds character-by-character, as opposed to using regular
|
|
|
|
/// expressions to lex tokens or semi-tokens at a time. As a result, it is
|
|
|
|
/// verbose and straightforward. Just used to have a regex-based lexer, which
|
|
|
|
/// was slower and generally godawful. However, this should not be taken as a
|
|
|
|
/// slight against regular expressions, the lexer was just idiosyncratically
|
|
|
|
/// bad.
|
2019-11-13 19:32:50 -08:00
|
|
|
pub(crate) struct Lexer<'src> {
|
2019-04-15 22:40:02 -07:00
|
|
|
/// Source text
|
2020-02-10 20:07:06 -08:00
|
|
|
src: &'src str,
|
2019-04-15 22:40:02 -07:00
|
|
|
/// Char iterator
|
2020-02-10 20:07:06 -08:00
|
|
|
chars: Chars<'src>,
|
2019-04-15 22:40:02 -07:00
|
|
|
/// Tokens
|
2020-02-10 20:07:06 -08:00
|
|
|
tokens: Vec<Token<'src>>,
|
2019-04-15 22:40:02 -07:00
|
|
|
/// Current token start
|
2020-02-10 20:07:06 -08:00
|
|
|
token_start: Position,
|
2019-04-15 22:40:02 -07:00
|
|
|
/// Current token end
|
2020-02-10 20:07:06 -08:00
|
|
|
token_end: Position,
|
2019-11-07 10:55:15 -08:00
|
|
|
/// Next character to be lexed
|
2020-02-10 20:07:06 -08:00
|
|
|
next: Option<char>,
|
2019-12-11 20:25:16 -08:00
|
|
|
/// Next indent will start a recipe body
|
|
|
|
recipe_body_pending: bool,
|
|
|
|
/// Inside recipe body
|
2020-02-10 20:07:06 -08:00
|
|
|
recipe_body: bool,
|
2019-12-11 20:25:16 -08:00
|
|
|
/// Indentation stack
|
2020-02-10 20:07:06 -08:00
|
|
|
indentation: Vec<&'src str>,
|
2019-12-11 20:25:16 -08:00
|
|
|
/// Current interpolation start token
|
|
|
|
interpolation_start: Option<Token<'src>>,
|
2017-11-18 03:36:02 -08:00
|
|
|
}
|
|
|
|
|
2019-11-13 19:32:50 -08:00
|
|
|
impl<'src> Lexer<'src> {
|
2019-04-15 22:40:02 -07:00
|
|
|
/// Lex `text`
|
2019-11-07 10:55:15 -08:00
|
|
|
pub(crate) fn lex(src: &str) -> CompilationResult<Vec<Token>> {
|
|
|
|
Lexer::new(src).tokenize()
|
2019-04-15 22:40:02 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/// Create a new Lexer to lex `text`
|
2019-11-13 19:32:50 -08:00
|
|
|
fn new(src: &'src str) -> Lexer<'src> {
|
2019-11-07 10:55:15 -08:00
|
|
|
let mut chars = src.chars();
|
2019-04-15 22:40:02 -07:00
|
|
|
let next = chars.next();
|
|
|
|
|
|
|
|
let start = Position {
|
|
|
|
offset: 0,
|
2017-11-18 03:36:02 -08:00
|
|
|
column: 0,
|
2020-02-10 20:07:06 -08:00
|
|
|
line: 0,
|
2017-11-18 03:36:02 -08:00
|
|
|
};
|
|
|
|
|
2019-04-15 22:40:02 -07:00
|
|
|
Lexer {
|
2019-12-11 20:25:16 -08:00
|
|
|
indentation: vec![""],
|
2019-04-15 22:40:02 -07:00
|
|
|
tokens: Vec::new(),
|
|
|
|
token_start: start,
|
|
|
|
token_end: start,
|
2019-12-11 20:25:16 -08:00
|
|
|
recipe_body_pending: false,
|
|
|
|
recipe_body: false,
|
|
|
|
interpolation_start: None,
|
2019-04-15 22:40:02 -07:00
|
|
|
chars,
|
|
|
|
next,
|
2019-11-07 10:55:15 -08:00
|
|
|
src,
|
2019-04-15 22:40:02 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-02-14 04:49:25 -08:00
|
|
|
/// Advance over the character in `self.next`, updating `self.token_end`
|
|
|
|
/// accordingly.
|
2019-11-13 19:32:50 -08:00
|
|
|
fn advance(&mut self) -> CompilationResult<'src, ()> {
|
2019-04-15 22:40:02 -07:00
|
|
|
match self.next {
|
|
|
|
Some(c) => {
|
|
|
|
let len_utf8 = c.len_utf8();
|
|
|
|
|
|
|
|
self.token_end.offset += len_utf8;
|
2020-01-15 02:16:13 -08:00
|
|
|
self.token_end.column += len_utf8;
|
2019-04-15 22:40:02 -07:00
|
|
|
|
2020-01-15 02:16:13 -08:00
|
|
|
if c == '\n' {
|
|
|
|
self.token_end.column = 0;
|
|
|
|
self.token_end.line += 1;
|
2019-04-15 22:40:02 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
self.next = self.chars.next();
|
|
|
|
|
|
|
|
Ok(())
|
2020-02-10 20:07:06 -08:00
|
|
|
},
|
2019-04-15 22:40:02 -07:00
|
|
|
None => Err(self.internal_error("Lexer advanced past end of text")),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Lexeme of in-progress token
|
2019-11-13 19:32:50 -08:00
|
|
|
fn lexeme(&self) -> &'src str {
|
2019-11-07 10:55:15 -08:00
|
|
|
&self.src[self.token_start.offset..self.token_end.offset]
|
2019-04-15 22:40:02 -07:00
|
|
|
}
|
|
|
|
|
2019-04-18 13:12:38 -07:00
|
|
|
/// Length of current token
|
|
|
|
fn current_token_length(&self) -> usize {
|
|
|
|
self.token_end.offset - self.token_start.offset
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Is next character c?
|
|
|
|
fn next_is(&self, c: char) -> bool {
|
|
|
|
self.next == Some(c)
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Is next character ' ' or '\t'?
|
|
|
|
fn next_is_whitespace(&self) -> bool {
|
|
|
|
self.next_is(' ') || self.next_is('\t')
|
|
|
|
}
|
|
|
|
|
2019-04-15 22:40:02 -07:00
|
|
|
/// Un-lexed text
|
2019-11-13 19:32:50 -08:00
|
|
|
fn rest(&self) -> &'src str {
|
2019-11-07 10:55:15 -08:00
|
|
|
&self.src[self.token_end.offset..]
|
2019-04-15 22:40:02 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/// Check if unlexed text begins with prefix
|
|
|
|
fn rest_starts_with(&self, prefix: &str) -> bool {
|
|
|
|
self.rest().starts_with(prefix)
|
|
|
|
}
|
|
|
|
|
2019-04-18 13:12:38 -07:00
|
|
|
/// Does rest start with "\n" or "\r\n"?
|
|
|
|
fn at_eol(&self) -> bool {
|
|
|
|
self.next_is('\n') || self.rest_starts_with("\r\n")
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Are we at end-of-line or end-of-file?
|
|
|
|
fn at_eol_or_eof(&self) -> bool {
|
|
|
|
self.at_eol() || self.rest().is_empty()
|
2019-04-15 22:40:02 -07:00
|
|
|
}
|
|
|
|
|
2019-12-11 20:25:16 -08:00
|
|
|
/// Get current indentation
|
|
|
|
fn indentation(&self) -> &'src str {
|
|
|
|
self.indentation.last().cloned().unwrap()
|
2019-04-15 22:40:02 -07:00
|
|
|
}
|
|
|
|
|
2019-12-11 20:25:16 -08:00
|
|
|
/// Are we currently indented
|
|
|
|
fn indented(&self) -> bool {
|
|
|
|
!self.indentation().is_empty()
|
2017-11-18 03:36:02 -08:00
|
|
|
}
|
|
|
|
|
2020-02-14 04:49:25 -08:00
|
|
|
/// Create a new token with `kind` whose lexeme is between `self.token_start`
|
|
|
|
/// and `self.token_end`
|
2019-04-15 22:40:02 -07:00
|
|
|
fn token(&mut self, kind: TokenKind) {
|
|
|
|
self.tokens.push(Token {
|
|
|
|
offset: self.token_start.offset,
|
|
|
|
column: self.token_start.column,
|
|
|
|
line: self.token_start.line,
|
2019-11-07 10:55:15 -08:00
|
|
|
src: self.src,
|
2019-04-15 22:40:02 -07:00
|
|
|
length: self.token_end.offset - self.token_start.offset,
|
|
|
|
kind,
|
|
|
|
});
|
|
|
|
|
|
|
|
// Set `token_start` to point after the lexed token
|
|
|
|
self.token_start = self.token_end;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Create an internal error with `message`
|
2019-11-13 19:32:50 -08:00
|
|
|
fn internal_error(&self, message: impl Into<String>) -> CompilationError<'src> {
|
2019-11-13 19:53:14 -08:00
|
|
|
// Use `self.token_end` as the location of the error
|
2019-11-13 19:32:50 -08:00
|
|
|
let token = Token {
|
2020-02-10 20:07:06 -08:00
|
|
|
src: self.src,
|
2019-04-15 22:40:02 -07:00
|
|
|
offset: self.token_end.offset,
|
2020-02-10 20:07:06 -08:00
|
|
|
line: self.token_end.line,
|
2019-04-15 22:40:02 -07:00
|
|
|
column: self.token_end.column,
|
2019-11-13 19:32:50 -08:00
|
|
|
length: 0,
|
2020-02-10 20:07:06 -08:00
|
|
|
kind: Unspecified,
|
2019-11-13 19:32:50 -08:00
|
|
|
};
|
|
|
|
CompilationError {
|
2019-04-15 22:40:02 -07:00
|
|
|
kind: CompilationErrorKind::Internal {
|
|
|
|
message: message.into(),
|
|
|
|
},
|
2019-11-13 19:32:50 -08:00
|
|
|
token,
|
2019-04-15 22:40:02 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Create a compilation error with `kind`
|
2019-11-13 19:32:50 -08:00
|
|
|
fn error(&self, kind: CompilationErrorKind<'src>) -> CompilationError<'src> {
|
2019-04-15 22:40:02 -07:00
|
|
|
// Use the in-progress token span as the location of the error.
|
|
|
|
|
2020-02-14 04:49:25 -08:00
|
|
|
// The width of the error site to highlight depends on the kind of error:
|
2019-11-13 19:32:50 -08:00
|
|
|
let length = match kind {
|
2019-04-15 22:40:02 -07:00
|
|
|
// highlight ' or "
|
|
|
|
UnterminatedString => 1,
|
|
|
|
// highlight `
|
|
|
|
UnterminatedBacktick => 1,
|
|
|
|
// highlight the full token
|
|
|
|
_ => self.lexeme().len(),
|
|
|
|
};
|
|
|
|
|
2019-11-13 19:32:50 -08:00
|
|
|
let token = Token {
|
|
|
|
kind: Unspecified,
|
2019-11-07 10:55:15 -08:00
|
|
|
src: self.src,
|
2019-04-15 22:40:02 -07:00
|
|
|
offset: self.token_start.offset,
|
|
|
|
line: self.token_start.line,
|
|
|
|
column: self.token_start.column,
|
2019-11-13 19:32:50 -08:00
|
|
|
length,
|
|
|
|
};
|
|
|
|
|
|
|
|
CompilationError { token, kind }
|
2017-11-18 03:36:02 -08:00
|
|
|
}
|
|
|
|
|
2020-01-15 02:16:13 -08:00
|
|
|
fn unterminated_interpolation_error(interpolation_start: Token<'src>) -> CompilationError<'src> {
|
2019-04-15 22:40:02 -07:00
|
|
|
CompilationError {
|
2019-11-13 19:32:50 -08:00
|
|
|
token: interpolation_start,
|
2020-02-10 20:07:06 -08:00
|
|
|
kind: UnterminatedInterpolation,
|
2017-11-18 03:36:02 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
Reform positional argument parsing (#523)
This diff makes positional argument parsing much cleaner, along with
adding a bunch of tests. Just's positional argument parsing is rather,
complex, so hopefully this reform allows it to both be correct and stay
correct.
User-visible changes:
- `just ..` is now accepted, with the same effect as `just ../`
- `just .` is also accepted, with the same effect as `just`
- It is now an error to pass arguments or overrides to subcommands
that do not accept them, namely `--dump`, `--edit`, `--list`,
`--show`, and `--summary`. It is also an error to pass arguments to
`--evaluate`, although `--evaluate` does of course still accept
overrides.
(This is a breaking change, but hopefully worth it, as it will allow us
to add arguments to subcommands which did not previously take
them, if we so desire.)
- Subcommands which do not accept arguments may now accept a
single search-directory argument, so `just --list ../` and
`just --dump foo/` are now accepted, with the former starting the
search for the justfile to list in the parent directory, and the latter
starting the search for the justfile to dump in `foo`.
2019-11-10 18:02:36 -08:00
|
|
|
/// True if `text` could be an identifier
|
|
|
|
pub(crate) fn is_identifier(text: &str) -> bool {
|
|
|
|
if !text
|
|
|
|
.chars()
|
|
|
|
.next()
|
2019-11-12 14:11:53 -08:00
|
|
|
.map(Self::is_identifier_start)
|
Reform positional argument parsing (#523)
This diff makes positional argument parsing much cleaner, along with
adding a bunch of tests. Just's positional argument parsing is rather,
complex, so hopefully this reform allows it to both be correct and stay
correct.
User-visible changes:
- `just ..` is now accepted, with the same effect as `just ../`
- `just .` is also accepted, with the same effect as `just`
- It is now an error to pass arguments or overrides to subcommands
that do not accept them, namely `--dump`, `--edit`, `--list`,
`--show`, and `--summary`. It is also an error to pass arguments to
`--evaluate`, although `--evaluate` does of course still accept
overrides.
(This is a breaking change, but hopefully worth it, as it will allow us
to add arguments to subcommands which did not previously take
them, if we so desire.)
- Subcommands which do not accept arguments may now accept a
single search-directory argument, so `just --list ../` and
`just --dump foo/` are now accepted, with the former starting the
search for the justfile to list in the parent directory, and the latter
starting the search for the justfile to dump in `foo`.
2019-11-10 18:02:36 -08:00
|
|
|
.unwrap_or(false)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
for c in text.chars().skip(1) {
|
|
|
|
if !Self::is_identifier_continue(c) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
true
|
|
|
|
}
|
|
|
|
|
|
|
|
/// True if `c` can be the first character of an identifier
|
|
|
|
fn is_identifier_start(c: char) -> bool {
|
|
|
|
match c {
|
|
|
|
'a'..='z' | 'A'..='Z' | '_' => true,
|
|
|
|
_ => false,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/// True if `c` can be a continuation character of an idenitifier
|
|
|
|
fn is_identifier_continue(c: char) -> bool {
|
|
|
|
if Self::is_identifier_start(c) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
match c {
|
|
|
|
'0'..='9' | '-' => true,
|
|
|
|
_ => false,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-04-15 22:40:02 -07:00
|
|
|
/// Consume the text and produce a series of tokens
|
2019-11-13 19:32:50 -08:00
|
|
|
fn tokenize(mut self) -> CompilationResult<'src, Vec<Token<'src>>> {
|
2019-04-15 22:40:02 -07:00
|
|
|
loop {
|
|
|
|
if self.token_start.column == 0 {
|
|
|
|
self.lex_line_start()?;
|
|
|
|
}
|
|
|
|
|
|
|
|
match self.next {
|
2019-12-11 20:25:16 -08:00
|
|
|
Some(first) => {
|
|
|
|
if let Some(interpolation_start) = self.interpolation_start {
|
|
|
|
self.lex_interpolation(interpolation_start, first)?
|
|
|
|
} else if self.recipe_body {
|
|
|
|
self.lex_body()?
|
|
|
|
} else {
|
|
|
|
self.lex_normal(first)?
|
|
|
|
};
|
2020-02-10 20:07:06 -08:00
|
|
|
},
|
2019-04-15 22:40:02 -07:00
|
|
|
None => break,
|
|
|
|
}
|
2017-11-18 03:36:02 -08:00
|
|
|
}
|
|
|
|
|
2019-12-11 20:25:16 -08:00
|
|
|
if let Some(interpolation_start) = self.interpolation_start {
|
2020-01-15 02:16:13 -08:00
|
|
|
return Err(Self::unterminated_interpolation_error(interpolation_start));
|
2019-04-15 22:40:02 -07:00
|
|
|
}
|
|
|
|
|
2019-12-11 20:25:16 -08:00
|
|
|
while self.indented() {
|
|
|
|
self.lex_dedent();
|
2019-04-15 22:40:02 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
self.token(Eof);
|
|
|
|
|
2019-12-10 13:24:30 -08:00
|
|
|
assert_eq!(self.token_start.offset, self.token_end.offset);
|
|
|
|
assert_eq!(self.token_start.offset, self.src.len());
|
2019-12-11 20:25:16 -08:00
|
|
|
assert_eq!(self.indentation.len(), 1);
|
2019-12-10 13:24:30 -08:00
|
|
|
|
2019-04-15 22:40:02 -07:00
|
|
|
Ok(self.tokens)
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Handle blank lines and indentation
|
2019-11-13 19:32:50 -08:00
|
|
|
fn lex_line_start(&mut self) -> CompilationResult<'src, ()> {
|
2019-12-11 20:25:16 -08:00
|
|
|
enum Indentation<'src> {
|
|
|
|
// Line only contains whitespace
|
|
|
|
Blank,
|
|
|
|
// Indentation continues
|
|
|
|
Continue,
|
|
|
|
// Indentation decreases
|
|
|
|
Decrease,
|
|
|
|
// Indentation isn't consistent
|
|
|
|
Inconsistent,
|
|
|
|
// Indentation increases
|
|
|
|
Increase,
|
|
|
|
// Indentation mixes spaces and tabs
|
|
|
|
Mixed { whitespace: &'src str },
|
|
|
|
}
|
|
|
|
|
|
|
|
use Indentation::*;
|
|
|
|
|
2019-04-15 22:40:02 -07:00
|
|
|
let nonblank_index = self
|
|
|
|
.rest()
|
|
|
|
.char_indices()
|
|
|
|
.skip_while(|&(_, c)| c == ' ' || c == '\t')
|
|
|
|
.map(|(i, _)| i)
|
|
|
|
.next()
|
|
|
|
.unwrap_or_else(|| self.rest().len());
|
|
|
|
|
|
|
|
let rest = &self.rest()[nonblank_index..];
|
|
|
|
|
2019-12-11 20:25:16 -08:00
|
|
|
let whitespace = &self.rest()[..nonblank_index];
|
|
|
|
|
|
|
|
let body_whitespace = &whitespace[..whitespace
|
|
|
|
.char_indices()
|
|
|
|
.take(self.indentation().chars().count())
|
|
|
|
.map(|(i, _c)| i)
|
|
|
|
.next()
|
|
|
|
.unwrap_or(0)];
|
|
|
|
|
|
|
|
let spaces = whitespace.chars().any(|c| c == ' ');
|
|
|
|
let tabs = whitespace.chars().any(|c| c == '\t');
|
|
|
|
|
|
|
|
let body_spaces = body_whitespace.chars().any(|c| c == ' ');
|
|
|
|
let body_tabs = body_whitespace.chars().any(|c| c == '\t');
|
|
|
|
|
|
|
|
#[allow(clippy::if_same_then_else)]
|
|
|
|
let indentation = if rest.starts_with('\n') || rest.starts_with("\r\n") || rest.is_empty() {
|
|
|
|
Blank
|
|
|
|
} else if whitespace == self.indentation() {
|
|
|
|
Continue
|
|
|
|
} else if self.indentation.contains(&whitespace) {
|
|
|
|
Decrease
|
|
|
|
} else if self.recipe_body && whitespace.starts_with(self.indentation()) {
|
|
|
|
Continue
|
|
|
|
} else if self.recipe_body && body_spaces && body_tabs {
|
|
|
|
Mixed {
|
|
|
|
whitespace: body_whitespace,
|
2019-04-15 22:40:02 -07:00
|
|
|
}
|
2019-12-11 20:25:16 -08:00
|
|
|
} else if !self.recipe_body && spaces && tabs {
|
|
|
|
Mixed { whitespace }
|
|
|
|
} else if whitespace.len() < self.indentation().len() {
|
|
|
|
Inconsistent
|
|
|
|
} else if self.recipe_body
|
|
|
|
&& body_whitespace.len() >= self.indentation().len()
|
|
|
|
&& !body_whitespace.starts_with(self.indentation())
|
|
|
|
{
|
|
|
|
Inconsistent
|
|
|
|
} else if whitespace.len() >= self.indentation().len()
|
|
|
|
&& !whitespace.starts_with(self.indentation())
|
|
|
|
{
|
|
|
|
Inconsistent
|
|
|
|
} else {
|
|
|
|
Increase
|
|
|
|
};
|
2019-04-15 22:40:02 -07:00
|
|
|
|
2019-12-11 20:25:16 -08:00
|
|
|
match indentation {
|
|
|
|
Blank => {
|
|
|
|
if !whitespace.is_empty() {
|
|
|
|
while self.next_is_whitespace() {
|
|
|
|
self.advance()?;
|
|
|
|
}
|
2019-04-15 22:40:02 -07:00
|
|
|
|
2019-12-11 20:25:16 -08:00
|
|
|
self.token(Whitespace);
|
|
|
|
};
|
2019-04-15 22:40:02 -07:00
|
|
|
|
2019-12-11 20:25:16 -08:00
|
|
|
Ok(())
|
2020-02-10 20:07:06 -08:00
|
|
|
},
|
2019-12-11 20:25:16 -08:00
|
|
|
Continue => {
|
|
|
|
if !self.indentation().is_empty() {
|
|
|
|
for _ in self.indentation().chars() {
|
|
|
|
self.advance()?;
|
|
|
|
}
|
2019-04-15 22:40:02 -07:00
|
|
|
|
2019-12-11 20:25:16 -08:00
|
|
|
self.token(Whitespace);
|
|
|
|
}
|
2019-04-15 22:40:02 -07:00
|
|
|
|
2019-12-11 20:25:16 -08:00
|
|
|
Ok(())
|
2020-02-10 20:07:06 -08:00
|
|
|
},
|
2019-12-11 20:25:16 -08:00
|
|
|
Decrease => {
|
|
|
|
while self.indentation() != whitespace {
|
|
|
|
self.lex_dedent();
|
2017-11-18 03:36:02 -08:00
|
|
|
}
|
2019-04-15 22:40:02 -07:00
|
|
|
|
2019-12-11 20:25:16 -08:00
|
|
|
if !whitespace.is_empty() {
|
|
|
|
while self.next_is_whitespace() {
|
|
|
|
self.advance()?;
|
|
|
|
}
|
|
|
|
|
|
|
|
self.token(Whitespace);
|
|
|
|
}
|
2019-04-15 22:40:02 -07:00
|
|
|
|
2019-12-11 20:25:16 -08:00
|
|
|
Ok(())
|
2020-02-10 20:07:06 -08:00
|
|
|
},
|
2019-12-11 20:25:16 -08:00
|
|
|
Mixed { whitespace } => {
|
|
|
|
for _ in whitespace.chars() {
|
2019-04-18 13:12:38 -07:00
|
|
|
self.advance()?;
|
|
|
|
}
|
2019-12-11 20:25:16 -08:00
|
|
|
|
|
|
|
Err(self.error(MixedLeadingWhitespace { whitespace }))
|
2020-02-10 20:07:06 -08:00
|
|
|
},
|
2019-12-11 20:25:16 -08:00
|
|
|
Inconsistent => {
|
|
|
|
for _ in whitespace.chars() {
|
|
|
|
self.advance()?;
|
|
|
|
}
|
2019-04-15 22:40:02 -07:00
|
|
|
|
2019-12-11 20:25:16 -08:00
|
|
|
Err(self.error(InconsistentLeadingWhitespace {
|
|
|
|
expected: self.indentation(),
|
2020-02-10 20:07:06 -08:00
|
|
|
found: whitespace,
|
2019-12-11 20:25:16 -08:00
|
|
|
}))
|
2020-02-10 20:07:06 -08:00
|
|
|
},
|
2019-12-11 20:25:16 -08:00
|
|
|
Increase => {
|
|
|
|
while self.next_is_whitespace() {
|
|
|
|
self.advance()?;
|
|
|
|
}
|
2019-04-15 22:40:02 -07:00
|
|
|
|
2019-12-11 20:25:16 -08:00
|
|
|
let indentation = self.lexeme();
|
2019-04-15 22:40:02 -07:00
|
|
|
|
2019-12-11 20:25:16 -08:00
|
|
|
self.indentation.push(indentation);
|
2019-04-15 22:40:02 -07:00
|
|
|
|
2019-12-11 20:25:16 -08:00
|
|
|
self.token(Indent);
|
2019-04-15 22:40:02 -07:00
|
|
|
|
2019-12-11 20:25:16 -08:00
|
|
|
if self.recipe_body_pending {
|
|
|
|
self.recipe_body = true;
|
|
|
|
}
|
2019-04-15 22:40:02 -07:00
|
|
|
|
2019-12-11 20:25:16 -08:00
|
|
|
Ok(())
|
2020-02-10 20:07:06 -08:00
|
|
|
},
|
2019-04-15 22:40:02 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-12-11 20:25:16 -08:00
|
|
|
/// Lex token beginning with `start` outside of a recipe body
|
2019-11-13 19:32:50 -08:00
|
|
|
fn lex_normal(&mut self, start: char) -> CompilationResult<'src, ()> {
|
2019-04-15 22:40:02 -07:00
|
|
|
match start {
|
2020-06-13 01:49:13 -07:00
|
|
|
'*' => self.lex_single(Asterisk),
|
2019-04-15 22:40:02 -07:00
|
|
|
'@' => self.lex_single(At),
|
2019-11-10 23:17:47 -08:00
|
|
|
'[' => self.lex_single(BracketL),
|
|
|
|
']' => self.lex_single(BracketR),
|
2019-04-15 22:40:02 -07:00
|
|
|
'=' => self.lex_single(Equals),
|
|
|
|
',' => self.lex_single(Comma),
|
2019-04-18 11:48:02 -07:00
|
|
|
':' => self.lex_colon(),
|
2019-04-15 22:40:02 -07:00
|
|
|
'(' => self.lex_single(ParenL),
|
|
|
|
')' => self.lex_single(ParenR),
|
|
|
|
'{' => self.lex_brace_l(),
|
|
|
|
'}' => self.lex_brace_r(),
|
|
|
|
'+' => self.lex_single(Plus),
|
|
|
|
'\n' => self.lex_single(Eol),
|
|
|
|
'\r' => self.lex_cr_lf(),
|
|
|
|
'#' => self.lex_comment(),
|
|
|
|
'`' => self.lex_backtick(),
|
|
|
|
' ' | '\t' => self.lex_whitespace(),
|
|
|
|
'\'' => self.lex_raw_string(),
|
|
|
|
'"' => self.lex_cooked_string(),
|
2020-02-10 20:07:06 -08:00
|
|
|
_ =>
|
Reform positional argument parsing (#523)
This diff makes positional argument parsing much cleaner, along with
adding a bunch of tests. Just's positional argument parsing is rather,
complex, so hopefully this reform allows it to both be correct and stay
correct.
User-visible changes:
- `just ..` is now accepted, with the same effect as `just ../`
- `just .` is also accepted, with the same effect as `just`
- It is now an error to pass arguments or overrides to subcommands
that do not accept them, namely `--dump`, `--edit`, `--list`,
`--show`, and `--summary`. It is also an error to pass arguments to
`--evaluate`, although `--evaluate` does of course still accept
overrides.
(This is a breaking change, but hopefully worth it, as it will allow us
to add arguments to subcommands which did not previously take
them, if we so desire.)
- Subcommands which do not accept arguments may now accept a
single search-directory argument, so `just --list ../` and
`just --dump foo/` are now accepted, with the former starting the
search for the justfile to list in the parent directory, and the latter
starting the search for the justfile to dump in `foo`.
2019-11-10 18:02:36 -08:00
|
|
|
if Self::is_identifier_start(start) {
|
|
|
|
self.lex_identifier()
|
|
|
|
} else {
|
|
|
|
self.advance()?;
|
|
|
|
Err(self.error(UnknownStartOfToken))
|
2020-02-10 20:07:06 -08:00
|
|
|
},
|
2019-04-15 22:40:02 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-12-11 20:25:16 -08:00
|
|
|
/// Lex token beginning with `start` inside an interpolation
|
2019-04-15 22:40:02 -07:00
|
|
|
fn lex_interpolation(
|
|
|
|
&mut self,
|
2019-11-13 19:32:50 -08:00
|
|
|
interpolation_start: Token<'src>,
|
2019-04-15 22:40:02 -07:00
|
|
|
start: char,
|
2019-11-13 19:32:50 -08:00
|
|
|
) -> CompilationResult<'src, ()> {
|
2019-04-15 22:40:02 -07:00
|
|
|
// Check for end of interpolation
|
|
|
|
if self.rest_starts_with("}}") {
|
2019-12-11 20:25:16 -08:00
|
|
|
// end current interpolation
|
|
|
|
self.interpolation_start = None;
|
2019-04-15 22:40:02 -07:00
|
|
|
// Emit interpolation end token
|
|
|
|
self.lex_double(InterpolationEnd)
|
2019-04-18 13:12:38 -07:00
|
|
|
} else if self.at_eol_or_eof() {
|
2020-02-10 20:07:06 -08:00
|
|
|
// Return unterminated interpolation error that highlights the opening
|
|
|
|
// {{
|
2020-01-15 02:16:13 -08:00
|
|
|
Err(Self::unterminated_interpolation_error(interpolation_start))
|
2019-04-15 22:40:02 -07:00
|
|
|
} else {
|
2019-12-11 20:25:16 -08:00
|
|
|
// Otherwise lex as per normal
|
2019-04-15 22:40:02 -07:00
|
|
|
self.lex_normal(start)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-12-11 20:25:16 -08:00
|
|
|
/// Lex token while in recipe body
|
|
|
|
fn lex_body(&mut self) -> CompilationResult<'src, ()> {
|
2019-04-15 22:40:02 -07:00
|
|
|
enum Terminator {
|
|
|
|
Newline,
|
|
|
|
NewlineCarriageReturn,
|
|
|
|
Interpolation,
|
|
|
|
EndOfFile,
|
|
|
|
}
|
|
|
|
|
|
|
|
use Terminator::*;
|
|
|
|
|
|
|
|
let terminator = loop {
|
|
|
|
if let Some('\n') = self.next {
|
|
|
|
break Newline;
|
|
|
|
}
|
|
|
|
|
|
|
|
if self.rest_starts_with("\r\n") {
|
|
|
|
break NewlineCarriageReturn;
|
|
|
|
}
|
|
|
|
|
|
|
|
if self.rest_starts_with("{{") {
|
|
|
|
break Interpolation;
|
|
|
|
}
|
|
|
|
|
|
|
|
if self.next.is_none() {
|
|
|
|
break EndOfFile;
|
|
|
|
}
|
|
|
|
|
|
|
|
self.advance()?;
|
|
|
|
};
|
|
|
|
|
|
|
|
// emit text token containing text so far
|
|
|
|
if self.current_token_length() > 0 {
|
|
|
|
self.token(Text);
|
|
|
|
}
|
|
|
|
|
|
|
|
match terminator {
|
2019-12-11 20:25:16 -08:00
|
|
|
Newline => self.lex_single(Eol),
|
|
|
|
NewlineCarriageReturn => self.lex_double(Eol),
|
2019-04-15 22:40:02 -07:00
|
|
|
Interpolation => {
|
2019-11-13 19:32:50 -08:00
|
|
|
self.lex_double(InterpolationStart)?;
|
2019-12-11 20:25:16 -08:00
|
|
|
self.interpolation_start = Some(self.tokens[self.tokens.len() - 1]);
|
2019-11-13 19:32:50 -08:00
|
|
|
Ok(())
|
2020-02-10 20:07:06 -08:00
|
|
|
},
|
2019-12-11 20:25:16 -08:00
|
|
|
EndOfFile => Ok(()),
|
2019-04-15 22:40:02 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-12-11 20:25:16 -08:00
|
|
|
fn lex_dedent(&mut self) {
|
|
|
|
assert_eq!(self.current_token_length(), 0);
|
|
|
|
self.token(Dedent);
|
|
|
|
self.indentation.pop();
|
|
|
|
self.recipe_body_pending = false;
|
|
|
|
self.recipe_body = false;
|
2019-04-15 22:40:02 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/// Lex a single character token
|
2019-11-13 19:32:50 -08:00
|
|
|
fn lex_single(&mut self, kind: TokenKind) -> CompilationResult<'src, ()> {
|
2019-04-15 22:40:02 -07:00
|
|
|
self.advance()?;
|
|
|
|
self.token(kind);
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Lex a double character token
|
2019-11-13 19:32:50 -08:00
|
|
|
fn lex_double(&mut self, kind: TokenKind) -> CompilationResult<'src, ()> {
|
2019-04-15 22:40:02 -07:00
|
|
|
self.advance()?;
|
|
|
|
self.advance()?;
|
|
|
|
self.token(kind);
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
|
2019-04-18 11:48:02 -07:00
|
|
|
/// Lex a token starting with ':'
|
2019-11-13 19:32:50 -08:00
|
|
|
fn lex_colon(&mut self) -> CompilationResult<'src, ()> {
|
2019-04-18 11:48:02 -07:00
|
|
|
self.advance()?;
|
|
|
|
|
2019-04-18 13:12:38 -07:00
|
|
|
if self.next_is('=') {
|
2019-04-18 11:48:02 -07:00
|
|
|
self.advance()?;
|
|
|
|
self.token(ColonEquals);
|
|
|
|
} else {
|
|
|
|
self.token(Colon);
|
2019-12-11 20:25:16 -08:00
|
|
|
self.recipe_body_pending = true;
|
2019-04-18 11:48:02 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
|
2019-04-15 22:40:02 -07:00
|
|
|
/// Lex a token starting with '{'
|
2019-11-13 19:32:50 -08:00
|
|
|
fn lex_brace_l(&mut self) -> CompilationResult<'src, ()> {
|
2019-04-15 22:40:02 -07:00
|
|
|
if !self.rest_starts_with("{{") {
|
|
|
|
self.advance()?;
|
|
|
|
|
|
|
|
return Err(self.error(UnknownStartOfToken));
|
|
|
|
}
|
|
|
|
|
|
|
|
self.lex_double(InterpolationStart)
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Lex a token starting with '}'
|
2019-11-13 19:32:50 -08:00
|
|
|
fn lex_brace_r(&mut self) -> CompilationResult<'src, ()> {
|
2019-04-15 22:40:02 -07:00
|
|
|
if !self.rest_starts_with("}}") {
|
|
|
|
self.advance()?;
|
|
|
|
|
|
|
|
return Err(self.error(UnknownStartOfToken));
|
|
|
|
}
|
|
|
|
|
|
|
|
self.lex_double(InterpolationEnd)
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Lex a carriage return and line feed
|
2019-11-13 19:32:50 -08:00
|
|
|
fn lex_cr_lf(&mut self) -> CompilationResult<'src, ()> {
|
2019-04-15 22:40:02 -07:00
|
|
|
if !self.rest_starts_with("\r\n") {
|
|
|
|
// advance over \r
|
|
|
|
self.advance()?;
|
|
|
|
|
|
|
|
return Err(self.error(UnpairedCarriageReturn));
|
2017-11-18 03:36:02 -08:00
|
|
|
}
|
2019-04-15 22:40:02 -07:00
|
|
|
|
|
|
|
self.lex_double(Eol)
|
|
|
|
}
|
|
|
|
|
Reform positional argument parsing (#523)
This diff makes positional argument parsing much cleaner, along with
adding a bunch of tests. Just's positional argument parsing is rather,
complex, so hopefully this reform allows it to both be correct and stay
correct.
User-visible changes:
- `just ..` is now accepted, with the same effect as `just ../`
- `just .` is also accepted, with the same effect as `just`
- It is now an error to pass arguments or overrides to subcommands
that do not accept them, namely `--dump`, `--edit`, `--list`,
`--show`, and `--summary`. It is also an error to pass arguments to
`--evaluate`, although `--evaluate` does of course still accept
overrides.
(This is a breaking change, but hopefully worth it, as it will allow us
to add arguments to subcommands which did not previously take
them, if we so desire.)
- Subcommands which do not accept arguments may now accept a
single search-directory argument, so `just --list ../` and
`just --dump foo/` are now accepted, with the former starting the
search for the justfile to list in the parent directory, and the latter
starting the search for the justfile to dump in `foo`.
2019-11-10 18:02:36 -08:00
|
|
|
/// Lex name: [a-zA-Z_][a-zA-Z0-9_]*
|
2019-11-13 19:32:50 -08:00
|
|
|
fn lex_identifier(&mut self) -> CompilationResult<'src, ()> {
|
Reform positional argument parsing (#523)
This diff makes positional argument parsing much cleaner, along with
adding a bunch of tests. Just's positional argument parsing is rather,
complex, so hopefully this reform allows it to both be correct and stay
correct.
User-visible changes:
- `just ..` is now accepted, with the same effect as `just ../`
- `just .` is also accepted, with the same effect as `just`
- It is now an error to pass arguments or overrides to subcommands
that do not accept them, namely `--dump`, `--edit`, `--list`,
`--show`, and `--summary`. It is also an error to pass arguments to
`--evaluate`, although `--evaluate` does of course still accept
overrides.
(This is a breaking change, but hopefully worth it, as it will allow us
to add arguments to subcommands which did not previously take
them, if we so desire.)
- Subcommands which do not accept arguments may now accept a
single search-directory argument, so `just --list ../` and
`just --dump foo/` are now accepted, with the former starting the
search for the justfile to list in the parent directory, and the latter
starting the search for the justfile to dump in `foo`.
2019-11-10 18:02:36 -08:00
|
|
|
// advance over initial character
|
|
|
|
self.advance()?;
|
|
|
|
|
|
|
|
while let Some(c) = self.next {
|
|
|
|
if !Self::is_identifier_continue(c) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2019-04-15 22:40:02 -07:00
|
|
|
self.advance()?;
|
2017-11-18 03:36:02 -08:00
|
|
|
}
|
|
|
|
|
2019-11-07 10:55:15 -08:00
|
|
|
self.token(Identifier);
|
2019-04-15 22:40:02 -07:00
|
|
|
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Lex comment: #[^\r\n]
|
2019-11-13 19:32:50 -08:00
|
|
|
fn lex_comment(&mut self) -> CompilationResult<'src, ()> {
|
2019-04-15 22:40:02 -07:00
|
|
|
// advance over #
|
|
|
|
self.advance()?;
|
|
|
|
|
2019-04-18 13:12:38 -07:00
|
|
|
while !self.at_eol_or_eof() {
|
2019-04-15 22:40:02 -07:00
|
|
|
self.advance()?;
|
|
|
|
}
|
|
|
|
|
|
|
|
self.token(Comment);
|
|
|
|
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Lex backtick: `[^\r\n]*`
|
2019-11-13 19:32:50 -08:00
|
|
|
fn lex_backtick(&mut self) -> CompilationResult<'src, ()> {
|
2019-04-18 13:12:38 -07:00
|
|
|
// advance over initial `
|
2019-04-15 22:40:02 -07:00
|
|
|
self.advance()?;
|
|
|
|
|
2019-04-18 13:12:38 -07:00
|
|
|
while !self.next_is('`') {
|
|
|
|
if self.at_eol_or_eof() {
|
2019-04-15 22:40:02 -07:00
|
|
|
return Err(self.error(UnterminatedBacktick));
|
2017-11-18 03:36:02 -08:00
|
|
|
}
|
|
|
|
|
2019-04-15 22:40:02 -07:00
|
|
|
self.advance()?;
|
|
|
|
}
|
2017-11-18 03:36:02 -08:00
|
|
|
|
2019-04-18 13:12:38 -07:00
|
|
|
self.advance()?;
|
2019-04-15 22:40:02 -07:00
|
|
|
self.token(Backtick);
|
2017-11-18 03:36:02 -08:00
|
|
|
|
2019-04-15 22:40:02 -07:00
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Lex whitespace: [ \t]+
|
2019-11-13 19:32:50 -08:00
|
|
|
fn lex_whitespace(&mut self) -> CompilationResult<'src, ()> {
|
2019-04-18 13:12:38 -07:00
|
|
|
while self.next_is_whitespace() {
|
2019-04-15 22:40:02 -07:00
|
|
|
self.advance()?
|
|
|
|
}
|
|
|
|
|
|
|
|
self.token(Whitespace);
|
|
|
|
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Lex raw string: '[^']*'
|
2019-11-13 19:32:50 -08:00
|
|
|
fn lex_raw_string(&mut self) -> CompilationResult<'src, ()> {
|
2019-04-15 22:40:02 -07:00
|
|
|
// advance over opening '
|
|
|
|
self.advance()?;
|
|
|
|
|
|
|
|
loop {
|
|
|
|
match self.next {
|
|
|
|
Some('\'') => break,
|
|
|
|
None => return Err(self.error(UnterminatedString)),
|
2020-07-16 21:37:33 -07:00
|
|
|
Some(_) => {},
|
2017-11-18 03:36:02 -08:00
|
|
|
}
|
|
|
|
|
2019-04-15 22:40:02 -07:00
|
|
|
self.advance()?;
|
|
|
|
}
|
|
|
|
|
|
|
|
// advance over closing '
|
|
|
|
self.advance()?;
|
|
|
|
|
|
|
|
self.token(StringRaw);
|
|
|
|
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Lex cooked string: "[^"\n\r]*" (also processes escape sequences)
|
2019-11-13 19:32:50 -08:00
|
|
|
fn lex_cooked_string(&mut self) -> CompilationResult<'src, ()> {
|
2019-04-15 22:40:02 -07:00
|
|
|
// advance over opening "
|
|
|
|
self.advance()?;
|
|
|
|
|
|
|
|
let mut escape = false;
|
|
|
|
|
|
|
|
loop {
|
|
|
|
match self.next {
|
|
|
|
Some('\r') | Some('\n') | None => return Err(self.error(UnterminatedString)),
|
|
|
|
Some('"') if !escape => break,
|
|
|
|
Some('\\') if !escape => escape = true,
|
|
|
|
_ => escape = false,
|
2017-11-18 03:36:02 -08:00
|
|
|
}
|
|
|
|
|
2019-04-15 22:40:02 -07:00
|
|
|
self.advance()?;
|
2017-11-18 03:36:02 -08:00
|
|
|
}
|
|
|
|
|
2019-04-15 22:40:02 -07:00
|
|
|
// advance over closing "
|
|
|
|
self.advance()?;
|
|
|
|
|
|
|
|
self.token(StringCooked);
|
|
|
|
|
|
|
|
Ok(())
|
2017-11-18 03:36:02 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[cfg(test)]
|
2019-04-15 22:40:02 -07:00
|
|
|
mod tests {
|
2017-11-18 03:36:02 -08:00
|
|
|
use super::*;
|
|
|
|
|
2019-10-17 20:04:54 -07:00
|
|
|
use pretty_assertions::assert_eq;
|
2019-04-19 02:17:43 -07:00
|
|
|
|
2019-10-17 20:04:54 -07:00
|
|
|
macro_rules! test {
|
|
|
|
{
|
|
|
|
name: $name:ident,
|
|
|
|
text: $text:expr,
|
|
|
|
tokens: ($($kind:ident $(: $lexeme:literal)?),* $(,)?)$(,)?
|
|
|
|
} => {
|
2017-11-18 03:36:02 -08:00
|
|
|
#[test]
|
|
|
|
fn $name() {
|
2019-10-17 20:04:54 -07:00
|
|
|
let kinds: &[TokenKind] = &[$($kind,)* Eof];
|
2017-11-18 03:36:02 -08:00
|
|
|
|
2019-10-17 20:04:54 -07:00
|
|
|
let lexemes: &[&str] = &[$(lexeme!($kind $(, $lexeme)?),)* ""];
|
2017-11-18 03:36:02 -08:00
|
|
|
|
2019-10-17 20:04:54 -07:00
|
|
|
test($text, kinds, lexemes);
|
2017-11-18 03:36:02 -08:00
|
|
|
}
|
2019-10-17 20:04:54 -07:00
|
|
|
}
|
2019-04-15 22:40:02 -07:00
|
|
|
}
|
|
|
|
|
2019-10-17 20:04:54 -07:00
|
|
|
macro_rules! lexeme {
|
|
|
|
{
|
|
|
|
$kind:ident, $lexeme:literal
|
|
|
|
} => {
|
|
|
|
$lexeme
|
|
|
|
};
|
|
|
|
{
|
|
|
|
$kind:ident
|
|
|
|
} => {
|
|
|
|
default_lexeme($kind)
|
|
|
|
}
|
2019-04-15 22:40:02 -07:00
|
|
|
}
|
|
|
|
|
2019-10-17 20:04:54 -07:00
|
|
|
fn test(text: &str, want_kinds: &[TokenKind], want_lexemes: &[&str]) {
|
|
|
|
let text = testing::unindent(text);
|
2019-04-15 22:40:02 -07:00
|
|
|
|
2019-10-17 20:04:54 -07:00
|
|
|
let have = Lexer::lex(&text).unwrap();
|
2019-04-15 22:40:02 -07:00
|
|
|
|
2019-10-17 20:04:54 -07:00
|
|
|
let have_kinds = have
|
|
|
|
.iter()
|
|
|
|
.map(|token| token.kind)
|
|
|
|
.collect::<Vec<TokenKind>>();
|
2019-04-15 22:40:02 -07:00
|
|
|
|
2019-10-17 20:04:54 -07:00
|
|
|
let have_lexemes = have
|
|
|
|
.iter()
|
|
|
|
.map(|token| token.lexeme())
|
|
|
|
.collect::<Vec<&str>>();
|
2019-04-15 22:40:02 -07:00
|
|
|
|
2019-10-17 20:04:54 -07:00
|
|
|
assert_eq!(have_kinds, want_kinds, "Token kind mismatch");
|
|
|
|
assert_eq!(have_lexemes, want_lexemes, "Token lexeme mismatch");
|
2019-04-15 22:40:02 -07:00
|
|
|
|
2019-10-17 20:04:54 -07:00
|
|
|
let mut roundtrip = String::new();
|
2019-04-15 22:40:02 -07:00
|
|
|
|
2019-10-17 20:04:54 -07:00
|
|
|
for lexeme in have_lexemes {
|
|
|
|
roundtrip.push_str(lexeme);
|
|
|
|
}
|
2019-04-15 22:40:02 -07:00
|
|
|
|
2019-10-17 20:04:54 -07:00
|
|
|
assert_eq!(roundtrip, text, "Roundtrip mismatch");
|
2019-04-15 22:40:02 -07:00
|
|
|
|
2019-10-17 20:04:54 -07:00
|
|
|
let mut offset = 0;
|
|
|
|
let mut line = 0;
|
|
|
|
let mut column = 0;
|
2019-04-15 22:40:02 -07:00
|
|
|
|
2019-10-17 20:04:54 -07:00
|
|
|
for token in have {
|
|
|
|
assert_eq!(token.offset, offset);
|
|
|
|
assert_eq!(token.line, line);
|
|
|
|
assert_eq!(token.lexeme().len(), token.length);
|
|
|
|
assert_eq!(token.column, column);
|
2019-04-15 22:40:02 -07:00
|
|
|
|
2019-10-17 20:04:54 -07:00
|
|
|
for c in token.lexeme().chars() {
|
|
|
|
if c == '\n' {
|
|
|
|
line += 1;
|
|
|
|
column = 0;
|
|
|
|
} else {
|
|
|
|
column += c.len_utf8();
|
|
|
|
}
|
|
|
|
}
|
2019-04-15 22:40:02 -07:00
|
|
|
|
2019-10-17 20:04:54 -07:00
|
|
|
offset += token.length;
|
|
|
|
}
|
2017-11-18 03:36:02 -08:00
|
|
|
}
|
|
|
|
|
2019-10-17 20:04:54 -07:00
|
|
|
fn default_lexeme(kind: TokenKind) -> &'static str {
|
|
|
|
match kind {
|
|
|
|
// Fixed lexemes
|
2020-06-13 01:49:13 -07:00
|
|
|
Asterisk => "*",
|
2019-10-17 20:04:54 -07:00
|
|
|
At => "@",
|
2019-11-10 23:17:47 -08:00
|
|
|
BracketL => "[",
|
|
|
|
BracketR => "]",
|
2019-10-17 20:04:54 -07:00
|
|
|
Colon => ":",
|
|
|
|
ColonEquals => ":=",
|
|
|
|
Comma => ",",
|
|
|
|
Eol => "\n",
|
|
|
|
Equals => "=",
|
|
|
|
Indent => " ",
|
|
|
|
InterpolationEnd => "}}",
|
|
|
|
InterpolationStart => "{{",
|
|
|
|
ParenL => "(",
|
|
|
|
ParenR => ")",
|
|
|
|
Plus => "+",
|
|
|
|
Whitespace => " ",
|
|
|
|
|
|
|
|
// Empty lexemes
|
2019-11-07 10:55:15 -08:00
|
|
|
Dedent | Eof => "",
|
2019-10-17 20:04:54 -07:00
|
|
|
|
|
|
|
// Variable lexemes
|
2020-02-10 20:07:06 -08:00
|
|
|
Text | StringCooked | StringRaw | Identifier | Comment | Backtick | Unspecified =>
|
|
|
|
panic!("Token {:?} has no default lexeme", kind),
|
2019-10-17 20:04:54 -07:00
|
|
|
}
|
2017-11-18 03:36:02 -08:00
|
|
|
}
|
|
|
|
|
2019-11-07 10:55:15 -08:00
|
|
|
macro_rules! error {
|
|
|
|
(
|
|
|
|
name: $name:ident,
|
|
|
|
input: $input:expr,
|
|
|
|
offset: $offset:expr,
|
|
|
|
line: $line:expr,
|
|
|
|
column: $column:expr,
|
|
|
|
width: $width:expr,
|
|
|
|
kind: $kind:expr,
|
|
|
|
) => {
|
|
|
|
#[test]
|
|
|
|
fn $name() {
|
|
|
|
error($input, $offset, $line, $column, $width, $kind);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
fn error(
|
|
|
|
src: &str,
|
|
|
|
offset: usize,
|
|
|
|
line: usize,
|
|
|
|
column: usize,
|
2019-11-13 19:32:50 -08:00
|
|
|
length: usize,
|
2019-11-07 10:55:15 -08:00
|
|
|
kind: CompilationErrorKind,
|
|
|
|
) {
|
|
|
|
match Lexer::lex(src) {
|
2019-11-13 19:32:50 -08:00
|
|
|
Ok(_) => panic!("Lexing succeeded but expected"),
|
|
|
|
Err(have) => {
|
|
|
|
let want = CompilationError {
|
|
|
|
token: Token {
|
|
|
|
kind: have.token.kind,
|
|
|
|
src,
|
|
|
|
offset,
|
|
|
|
line,
|
|
|
|
column,
|
|
|
|
length,
|
|
|
|
},
|
|
|
|
kind,
|
|
|
|
};
|
|
|
|
assert_eq!(have, want);
|
2020-02-10 20:07:06 -08:00
|
|
|
},
|
2019-11-07 10:55:15 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-10-17 20:04:54 -07:00
|
|
|
test! {
|
|
|
|
name: name_new,
|
|
|
|
text: "foo",
|
2019-11-07 10:55:15 -08:00
|
|
|
tokens: (Identifier:"foo"),
|
2019-10-17 20:04:54 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
test! {
|
|
|
|
name: comment,
|
|
|
|
text: "# hello",
|
|
|
|
tokens: (Comment:"# hello"),
|
|
|
|
}
|
|
|
|
|
|
|
|
test! {
|
|
|
|
name: backtick,
|
|
|
|
text: "`echo`",
|
|
|
|
tokens: (Backtick:"`echo`"),
|
|
|
|
}
|
|
|
|
|
|
|
|
test! {
|
|
|
|
name: raw_string,
|
|
|
|
text: "'hello'",
|
|
|
|
tokens: (StringRaw:"'hello'"),
|
|
|
|
}
|
|
|
|
|
|
|
|
test! {
|
|
|
|
name: cooked_string,
|
|
|
|
text: "\"hello\"",
|
|
|
|
tokens: (StringCooked:"\"hello\""),
|
|
|
|
}
|
|
|
|
|
|
|
|
test! {
|
|
|
|
name: export_concatination,
|
|
|
|
text: "export foo = 'foo' + 'bar'",
|
|
|
|
tokens: (
|
2019-11-07 10:55:15 -08:00
|
|
|
Identifier:"export",
|
2019-10-17 20:04:54 -07:00
|
|
|
Whitespace,
|
2019-11-07 10:55:15 -08:00
|
|
|
Identifier:"foo",
|
2019-10-17 20:04:54 -07:00
|
|
|
Whitespace,
|
|
|
|
Equals,
|
|
|
|
Whitespace,
|
|
|
|
StringRaw:"'foo'",
|
|
|
|
Whitespace,
|
|
|
|
Plus,
|
|
|
|
Whitespace,
|
|
|
|
StringRaw:"'bar'",
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
test! {
|
|
|
|
name: export_complex,
|
|
|
|
text: "export foo = ('foo' + 'bar') + `baz`",
|
|
|
|
tokens: (
|
2019-11-07 10:55:15 -08:00
|
|
|
Identifier:"export",
|
2019-10-17 20:04:54 -07:00
|
|
|
Whitespace,
|
2019-11-07 10:55:15 -08:00
|
|
|
Identifier:"foo",
|
2019-10-17 20:04:54 -07:00
|
|
|
Whitespace,
|
|
|
|
Equals,
|
|
|
|
Whitespace,
|
|
|
|
ParenL,
|
|
|
|
StringRaw:"'foo'",
|
|
|
|
Whitespace,
|
|
|
|
Plus,
|
|
|
|
Whitespace,
|
|
|
|
StringRaw:"'bar'",
|
|
|
|
ParenR,
|
|
|
|
Whitespace,
|
|
|
|
Plus,
|
|
|
|
Whitespace,
|
|
|
|
Backtick:"`baz`",
|
|
|
|
),
|
|
|
|
}
|
|
|
|
|
|
|
|
test! {
|
|
|
|
name: eol_linefeed,
|
|
|
|
text: "\n",
|
|
|
|
tokens: (Eol),
|
|
|
|
}
|
|
|
|
|
|
|
|
test! {
|
|
|
|
name: eol_carriage_return_linefeed,
|
|
|
|
text: "\r\n",
|
|
|
|
tokens: (Eol:"\r\n"),
|
|
|
|
}
|
|
|
|
|
|
|
|
test! {
|
|
|
|
name: indented_line,
|
|
|
|
text: "foo:\n a",
|
2019-11-07 10:55:15 -08:00
|
|
|
tokens: (Identifier:"foo", Colon, Eol, Indent:" ", Text:"a", Dedent),
|
2019-10-17 20:04:54 -07:00
|
|
|
}
|
|
|
|
|
2019-12-11 20:25:16 -08:00
|
|
|
test! {
|
|
|
|
name: indented_normal,
|
|
|
|
text: "
|
|
|
|
a
|
|
|
|
b
|
|
|
|
c
|
|
|
|
",
|
|
|
|
tokens: (
|
|
|
|
Identifier:"a",
|
|
|
|
Eol,
|
|
|
|
Indent:" ",
|
|
|
|
Identifier:"b",
|
|
|
|
Eol,
|
|
|
|
Whitespace:" ",
|
|
|
|
Identifier:"c",
|
|
|
|
Eol,
|
|
|
|
Dedent,
|
|
|
|
),
|
|
|
|
}
|
|
|
|
|
|
|
|
test! {
|
|
|
|
name: indented_normal_nonempty_blank,
|
|
|
|
text: "a\n b\n\t\t\n c\n",
|
|
|
|
tokens: (
|
|
|
|
Identifier:"a",
|
|
|
|
Eol,
|
|
|
|
Indent:" ",
|
|
|
|
Identifier:"b",
|
|
|
|
Eol,
|
|
|
|
Whitespace:"\t\t",
|
|
|
|
Eol,
|
|
|
|
Whitespace:" ",
|
|
|
|
Identifier:"c",
|
|
|
|
Eol,
|
|
|
|
Dedent,
|
|
|
|
),
|
|
|
|
}
|
|
|
|
|
|
|
|
test! {
|
|
|
|
name: indented_normal_multiple,
|
|
|
|
text: "
|
|
|
|
a
|
|
|
|
b
|
|
|
|
c
|
|
|
|
",
|
|
|
|
tokens: (
|
|
|
|
Identifier:"a",
|
|
|
|
Eol,
|
|
|
|
Indent:" ",
|
|
|
|
Identifier:"b",
|
|
|
|
Eol,
|
|
|
|
Indent:" ",
|
|
|
|
Identifier:"c",
|
|
|
|
Eol,
|
|
|
|
Dedent,
|
|
|
|
Dedent,
|
|
|
|
),
|
|
|
|
}
|
|
|
|
|
|
|
|
test! {
|
|
|
|
name: indent_indent_dedent_indent,
|
|
|
|
text: "
|
|
|
|
a
|
|
|
|
b
|
|
|
|
c
|
|
|
|
d
|
|
|
|
e
|
|
|
|
",
|
|
|
|
tokens: (
|
|
|
|
Identifier:"a",
|
|
|
|
Eol,
|
|
|
|
Indent:" ",
|
|
|
|
Identifier:"b",
|
|
|
|
Eol,
|
|
|
|
Indent:" ",
|
|
|
|
Identifier:"c",
|
|
|
|
Eol,
|
|
|
|
Dedent,
|
|
|
|
Whitespace:" ",
|
|
|
|
Identifier:"d",
|
|
|
|
Eol,
|
|
|
|
Indent:" ",
|
|
|
|
Identifier:"e",
|
|
|
|
Eol,
|
|
|
|
Dedent,
|
|
|
|
Dedent,
|
|
|
|
),
|
|
|
|
}
|
|
|
|
|
|
|
|
test! {
|
|
|
|
name: indent_recipe_dedent_indent,
|
|
|
|
text: "
|
|
|
|
a
|
|
|
|
b:
|
|
|
|
c
|
|
|
|
d
|
|
|
|
e
|
|
|
|
",
|
|
|
|
tokens: (
|
|
|
|
Identifier:"a",
|
|
|
|
Eol,
|
|
|
|
Indent:" ",
|
|
|
|
Identifier:"b",
|
|
|
|
Colon,
|
|
|
|
Eol,
|
|
|
|
Indent:" ",
|
|
|
|
Text:"c",
|
|
|
|
Eol,
|
|
|
|
Dedent,
|
|
|
|
Whitespace:" ",
|
|
|
|
Identifier:"d",
|
|
|
|
Eol,
|
|
|
|
Indent:" ",
|
|
|
|
Identifier:"e",
|
|
|
|
Eol,
|
|
|
|
Dedent,
|
|
|
|
Dedent,
|
|
|
|
),
|
|
|
|
}
|
|
|
|
|
2019-10-17 20:04:54 -07:00
|
|
|
test! {
|
|
|
|
name: indented_block,
|
|
|
|
text: "
|
|
|
|
foo:
|
|
|
|
a
|
|
|
|
b
|
|
|
|
c
|
|
|
|
",
|
|
|
|
tokens: (
|
2019-11-07 10:55:15 -08:00
|
|
|
Identifier:"foo",
|
2019-10-17 20:04:54 -07:00
|
|
|
Colon,
|
|
|
|
Eol,
|
|
|
|
Indent,
|
|
|
|
Text:"a",
|
|
|
|
Eol,
|
|
|
|
Whitespace:" ",
|
|
|
|
Text:"b",
|
|
|
|
Eol,
|
|
|
|
Whitespace:" ",
|
|
|
|
Text:"c",
|
|
|
|
Eol,
|
|
|
|
Dedent,
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
test! {
|
|
|
|
name: indented_block_followed_by_item,
|
|
|
|
text: "
|
|
|
|
foo:
|
|
|
|
a
|
|
|
|
b:
|
|
|
|
",
|
|
|
|
tokens: (
|
2019-11-07 10:55:15 -08:00
|
|
|
Identifier:"foo",
|
2019-10-17 20:04:54 -07:00
|
|
|
Colon,
|
|
|
|
Eol,
|
|
|
|
Indent,
|
|
|
|
Text:"a",
|
|
|
|
Eol,
|
|
|
|
Dedent,
|
2019-11-07 10:55:15 -08:00
|
|
|
Identifier:"b",
|
2019-10-17 20:04:54 -07:00
|
|
|
Colon,
|
|
|
|
Eol,
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
test! {
|
|
|
|
name: indented_block_followed_by_blank,
|
|
|
|
text: "
|
|
|
|
foo:
|
|
|
|
a
|
|
|
|
|
|
|
|
b:
|
|
|
|
",
|
|
|
|
tokens: (
|
2019-11-07 10:55:15 -08:00
|
|
|
Identifier:"foo",
|
2019-10-17 20:04:54 -07:00
|
|
|
Colon,
|
|
|
|
Eol,
|
|
|
|
Indent:" ",
|
|
|
|
Text:"a",
|
|
|
|
Eol,
|
|
|
|
Eol,
|
|
|
|
Dedent,
|
2019-11-07 10:55:15 -08:00
|
|
|
Identifier:"b",
|
2019-10-17 20:04:54 -07:00
|
|
|
Colon,
|
|
|
|
Eol,
|
|
|
|
),
|
|
|
|
}
|
|
|
|
|
|
|
|
test! {
|
|
|
|
name: indented_line_containing_unpaired_carriage_return,
|
|
|
|
text: "foo:\n \r \n",
|
|
|
|
tokens: (
|
2019-11-07 10:55:15 -08:00
|
|
|
Identifier:"foo",
|
2019-10-17 20:04:54 -07:00
|
|
|
Colon,
|
|
|
|
Eol,
|
|
|
|
Indent:" ",
|
|
|
|
Text:"\r ",
|
|
|
|
Eol,
|
|
|
|
Dedent,
|
|
|
|
),
|
|
|
|
}
|
|
|
|
|
|
|
|
test! {
|
|
|
|
name: indented_blocks,
|
|
|
|
text: "
|
|
|
|
b: a
|
|
|
|
@mv a b
|
|
|
|
|
|
|
|
a:
|
|
|
|
@touch F
|
|
|
|
@touch a
|
|
|
|
|
|
|
|
d: c
|
|
|
|
@rm c
|
|
|
|
|
|
|
|
c: b
|
|
|
|
@mv b c
|
|
|
|
",
|
|
|
|
tokens: (
|
2019-11-07 10:55:15 -08:00
|
|
|
Identifier:"b",
|
2019-10-17 20:04:54 -07:00
|
|
|
Colon,
|
|
|
|
Whitespace,
|
2019-11-07 10:55:15 -08:00
|
|
|
Identifier:"a",
|
2019-10-17 20:04:54 -07:00
|
|
|
Eol,
|
|
|
|
Indent,
|
|
|
|
Text:"@mv a b",
|
|
|
|
Eol,
|
|
|
|
Eol,
|
|
|
|
Dedent,
|
2019-11-07 10:55:15 -08:00
|
|
|
Identifier:"a",
|
2019-10-17 20:04:54 -07:00
|
|
|
Colon,
|
|
|
|
Eol,
|
|
|
|
Indent,
|
|
|
|
Text:"@touch F",
|
|
|
|
Eol,
|
|
|
|
Whitespace:" ",
|
|
|
|
Text:"@touch a",
|
|
|
|
Eol,
|
|
|
|
Eol,
|
|
|
|
Dedent,
|
2019-11-07 10:55:15 -08:00
|
|
|
Identifier:"d",
|
2019-10-17 20:04:54 -07:00
|
|
|
Colon,
|
|
|
|
Whitespace,
|
2019-11-07 10:55:15 -08:00
|
|
|
Identifier:"c",
|
2019-10-17 20:04:54 -07:00
|
|
|
Eol,
|
|
|
|
Indent,
|
|
|
|
Text:"@rm c",
|
|
|
|
Eol,
|
|
|
|
Eol,
|
|
|
|
Dedent,
|
2019-11-07 10:55:15 -08:00
|
|
|
Identifier:"c",
|
2019-10-17 20:04:54 -07:00
|
|
|
Colon,
|
|
|
|
Whitespace,
|
2019-11-07 10:55:15 -08:00
|
|
|
Identifier:"b",
|
2019-10-17 20:04:54 -07:00
|
|
|
Eol,
|
|
|
|
Indent,
|
|
|
|
Text:"@mv b c",
|
|
|
|
Eol,
|
|
|
|
Dedent
|
|
|
|
),
|
|
|
|
}
|
|
|
|
|
|
|
|
test! {
|
|
|
|
name: interpolation_empty,
|
|
|
|
text: "hello:\n echo {{}}",
|
|
|
|
tokens: (
|
2019-11-07 10:55:15 -08:00
|
|
|
Identifier:"hello",
|
2019-10-17 20:04:54 -07:00
|
|
|
Colon,
|
|
|
|
Eol,
|
|
|
|
Indent:" ",
|
|
|
|
Text:"echo ",
|
|
|
|
InterpolationStart,
|
|
|
|
InterpolationEnd,
|
|
|
|
Dedent,
|
|
|
|
),
|
|
|
|
}
|
|
|
|
|
|
|
|
test! {
|
|
|
|
name: interpolation_expression,
|
|
|
|
text: "hello:\n echo {{`echo hello` + `echo goodbye`}}",
|
|
|
|
tokens: (
|
2019-11-07 10:55:15 -08:00
|
|
|
Identifier:"hello",
|
2019-10-17 20:04:54 -07:00
|
|
|
Colon,
|
|
|
|
Eol,
|
|
|
|
Indent:" ",
|
|
|
|
Text:"echo ",
|
|
|
|
InterpolationStart,
|
|
|
|
Backtick:"`echo hello`",
|
|
|
|
Whitespace,
|
|
|
|
Plus,
|
|
|
|
Whitespace,
|
|
|
|
Backtick:"`echo goodbye`",
|
|
|
|
InterpolationEnd,
|
|
|
|
Dedent,
|
|
|
|
),
|
|
|
|
}
|
|
|
|
|
|
|
|
test! {
|
|
|
|
name: tokenize_names,
|
|
|
|
text: "
|
|
|
|
foo
|
|
|
|
bar-bob
|
|
|
|
b-bob_asdfAAAA
|
|
|
|
test123
|
|
|
|
",
|
|
|
|
tokens: (
|
2019-11-07 10:55:15 -08:00
|
|
|
Identifier:"foo",
|
2019-10-17 20:04:54 -07:00
|
|
|
Eol,
|
2019-11-07 10:55:15 -08:00
|
|
|
Identifier:"bar-bob",
|
2019-10-17 20:04:54 -07:00
|
|
|
Eol,
|
2019-11-07 10:55:15 -08:00
|
|
|
Identifier:"b-bob_asdfAAAA",
|
2019-10-17 20:04:54 -07:00
|
|
|
Eol,
|
2019-11-07 10:55:15 -08:00
|
|
|
Identifier:"test123",
|
2019-10-17 20:04:54 -07:00
|
|
|
Eol,
|
|
|
|
),
|
|
|
|
}
|
|
|
|
|
|
|
|
test! {
|
|
|
|
name: tokenize_indented_line,
|
|
|
|
text: "foo:\n a",
|
|
|
|
tokens: (
|
2019-11-07 10:55:15 -08:00
|
|
|
Identifier:"foo",
|
2019-10-17 20:04:54 -07:00
|
|
|
Colon,
|
|
|
|
Eol,
|
|
|
|
Indent:" ",
|
|
|
|
Text:"a",
|
|
|
|
Dedent,
|
|
|
|
),
|
|
|
|
}
|
|
|
|
|
|
|
|
test! {
|
|
|
|
name: tokenize_indented_block,
|
|
|
|
text: "
|
|
|
|
foo:
|
|
|
|
a
|
|
|
|
b
|
|
|
|
c
|
|
|
|
",
|
|
|
|
tokens: (
|
2019-11-07 10:55:15 -08:00
|
|
|
Identifier:"foo",
|
2019-10-17 20:04:54 -07:00
|
|
|
Colon,
|
|
|
|
Eol,
|
|
|
|
Indent,
|
|
|
|
Text:"a",
|
|
|
|
Eol,
|
|
|
|
Whitespace:" ",
|
|
|
|
Text:"b",
|
|
|
|
Eol,
|
|
|
|
Whitespace:" ",
|
|
|
|
Text:"c",
|
|
|
|
Eol,
|
|
|
|
Dedent,
|
|
|
|
),
|
|
|
|
}
|
|
|
|
|
|
|
|
test! {
|
|
|
|
name: tokenize_strings,
|
|
|
|
text: r#"a = "'a'" + '"b"' + "'c'" + '"d"'#echo hello"#,
|
|
|
|
tokens: (
|
2019-11-07 10:55:15 -08:00
|
|
|
Identifier:"a",
|
2019-10-17 20:04:54 -07:00
|
|
|
Whitespace,
|
|
|
|
Equals,
|
|
|
|
Whitespace,
|
|
|
|
StringCooked:"\"'a'\"",
|
|
|
|
Whitespace,
|
|
|
|
Plus,
|
|
|
|
Whitespace,
|
|
|
|
StringRaw:"'\"b\"'",
|
|
|
|
Whitespace,
|
|
|
|
Plus,
|
|
|
|
Whitespace,
|
|
|
|
StringCooked:"\"'c'\"",
|
|
|
|
Whitespace,
|
|
|
|
Plus,
|
|
|
|
Whitespace,
|
|
|
|
StringRaw:"'\"d\"'",
|
|
|
|
Comment:"#echo hello",
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
test! {
|
|
|
|
name: tokenize_recipe_interpolation_eol,
|
|
|
|
text: "
|
|
|
|
foo: # some comment
|
|
|
|
{{hello}}
|
|
|
|
",
|
|
|
|
tokens: (
|
2019-11-07 10:55:15 -08:00
|
|
|
Identifier:"foo",
|
2019-10-17 20:04:54 -07:00
|
|
|
Colon,
|
|
|
|
Whitespace,
|
|
|
|
Comment:"# some comment",
|
|
|
|
Eol,
|
|
|
|
Indent:" ",
|
|
|
|
InterpolationStart,
|
2019-11-07 10:55:15 -08:00
|
|
|
Identifier:"hello",
|
2019-10-17 20:04:54 -07:00
|
|
|
InterpolationEnd,
|
|
|
|
Eol,
|
|
|
|
Dedent
|
|
|
|
),
|
|
|
|
}
|
|
|
|
|
|
|
|
test! {
|
|
|
|
name: tokenize_recipe_interpolation_eof,
|
|
|
|
text: "foo: # more comments
|
2017-11-18 03:36:02 -08:00
|
|
|
{{hello}}
|
|
|
|
# another comment
|
|
|
|
",
|
2019-10-17 20:04:54 -07:00
|
|
|
tokens: (
|
2019-11-07 10:55:15 -08:00
|
|
|
Identifier:"foo",
|
2019-10-17 20:04:54 -07:00
|
|
|
Colon,
|
|
|
|
Whitespace,
|
|
|
|
Comment:"# more comments",
|
|
|
|
Eol,
|
|
|
|
Indent:" ",
|
|
|
|
InterpolationStart,
|
2019-11-07 10:55:15 -08:00
|
|
|
Identifier:"hello",
|
2019-10-17 20:04:54 -07:00
|
|
|
InterpolationEnd,
|
|
|
|
Eol,
|
|
|
|
Dedent,
|
|
|
|
Comment:"# another comment",
|
|
|
|
Eol,
|
|
|
|
),
|
|
|
|
}
|
|
|
|
|
|
|
|
test! {
|
|
|
|
name: tokenize_recipe_complex_interpolation_expression,
|
|
|
|
text: "foo: #lol\n {{a + b + \"z\" + blarg}}",
|
|
|
|
tokens: (
|
2019-11-07 10:55:15 -08:00
|
|
|
Identifier:"foo",
|
2019-10-17 20:04:54 -07:00
|
|
|
Colon,
|
|
|
|
Whitespace:" ",
|
|
|
|
Comment:"#lol",
|
|
|
|
Eol,
|
|
|
|
Indent:" ",
|
|
|
|
InterpolationStart,
|
2019-11-07 10:55:15 -08:00
|
|
|
Identifier:"a",
|
2019-10-17 20:04:54 -07:00
|
|
|
Whitespace,
|
|
|
|
Plus,
|
|
|
|
Whitespace,
|
2019-11-07 10:55:15 -08:00
|
|
|
Identifier:"b",
|
2019-10-17 20:04:54 -07:00
|
|
|
Whitespace,
|
|
|
|
Plus,
|
|
|
|
Whitespace,
|
|
|
|
StringCooked:"\"z\"",
|
|
|
|
Whitespace,
|
|
|
|
Plus,
|
|
|
|
Whitespace,
|
2019-11-07 10:55:15 -08:00
|
|
|
Identifier:"blarg",
|
2019-10-17 20:04:54 -07:00
|
|
|
InterpolationEnd,
|
|
|
|
Dedent,
|
|
|
|
),
|
|
|
|
}
|
|
|
|
|
|
|
|
test! {
|
|
|
|
name: tokenize_recipe_multiple_interpolations,
|
|
|
|
text: "foo:,#ok\n {{a}}0{{b}}1{{c}}",
|
|
|
|
tokens: (
|
2019-11-07 10:55:15 -08:00
|
|
|
Identifier:"foo",
|
2019-10-17 20:04:54 -07:00
|
|
|
Colon,
|
|
|
|
Comma,
|
|
|
|
Comment:"#ok",
|
|
|
|
Eol,
|
|
|
|
Indent:" ",
|
|
|
|
InterpolationStart,
|
2019-11-07 10:55:15 -08:00
|
|
|
Identifier:"a",
|
2019-10-17 20:04:54 -07:00
|
|
|
InterpolationEnd,
|
|
|
|
Text:"0",
|
|
|
|
InterpolationStart,
|
2019-11-07 10:55:15 -08:00
|
|
|
Identifier:"b",
|
2019-10-17 20:04:54 -07:00
|
|
|
InterpolationEnd,
|
|
|
|
Text:"1",
|
|
|
|
InterpolationStart,
|
2019-11-07 10:55:15 -08:00
|
|
|
Identifier:"c",
|
2019-10-17 20:04:54 -07:00
|
|
|
InterpolationEnd,
|
|
|
|
Dedent,
|
|
|
|
|
|
|
|
),
|
|
|
|
}
|
|
|
|
|
|
|
|
test! {
|
|
|
|
name: tokenize_junk,
|
|
|
|
text: "
|
|
|
|
bob
|
|
|
|
|
|
|
|
hello blah blah blah : a b c #whatever
|
2017-11-18 03:36:02 -08:00
|
|
|
",
|
2019-10-17 20:04:54 -07:00
|
|
|
tokens: (
|
2019-11-07 10:55:15 -08:00
|
|
|
Identifier:"bob",
|
2019-10-17 20:04:54 -07:00
|
|
|
Eol,
|
|
|
|
Eol,
|
2019-11-07 10:55:15 -08:00
|
|
|
Identifier:"hello",
|
2019-10-17 20:04:54 -07:00
|
|
|
Whitespace,
|
2019-11-07 10:55:15 -08:00
|
|
|
Identifier:"blah",
|
2019-10-17 20:04:54 -07:00
|
|
|
Whitespace,
|
2019-11-07 10:55:15 -08:00
|
|
|
Identifier:"blah",
|
2019-10-17 20:04:54 -07:00
|
|
|
Whitespace,
|
2019-11-07 10:55:15 -08:00
|
|
|
Identifier:"blah",
|
2019-10-17 20:04:54 -07:00
|
|
|
Whitespace,
|
|
|
|
Colon,
|
|
|
|
Whitespace,
|
2019-11-07 10:55:15 -08:00
|
|
|
Identifier:"a",
|
2019-10-17 20:04:54 -07:00
|
|
|
Whitespace,
|
2019-11-07 10:55:15 -08:00
|
|
|
Identifier:"b",
|
2019-10-17 20:04:54 -07:00
|
|
|
Whitespace,
|
2019-11-07 10:55:15 -08:00
|
|
|
Identifier:"c",
|
2019-10-17 20:04:54 -07:00
|
|
|
Whitespace,
|
|
|
|
Comment:"#whatever",
|
|
|
|
Eol,
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
test! {
|
|
|
|
name: tokenize_empty_lines,
|
|
|
|
text: "
|
|
|
|
|
|
|
|
# this does something
|
|
|
|
hello:
|
|
|
|
asdf
|
|
|
|
bsdf
|
|
|
|
|
|
|
|
csdf
|
|
|
|
|
|
|
|
dsdf # whatever
|
|
|
|
|
|
|
|
# yolo
|
|
|
|
",
|
|
|
|
tokens: (
|
|
|
|
Eol,
|
|
|
|
Comment:"# this does something",
|
|
|
|
Eol,
|
2019-11-07 10:55:15 -08:00
|
|
|
Identifier:"hello",
|
2019-10-17 20:04:54 -07:00
|
|
|
Colon,
|
|
|
|
Eol,
|
|
|
|
Indent,
|
|
|
|
Text:"asdf",
|
|
|
|
Eol,
|
|
|
|
Whitespace:" ",
|
|
|
|
Text:"bsdf",
|
|
|
|
Eol,
|
|
|
|
Eol,
|
|
|
|
Whitespace:" ",
|
|
|
|
Text:"csdf",
|
|
|
|
Eol,
|
|
|
|
Eol,
|
|
|
|
Whitespace:" ",
|
|
|
|
Text:"dsdf # whatever",
|
|
|
|
Eol,
|
|
|
|
Eol,
|
|
|
|
Dedent,
|
|
|
|
Comment:"# yolo",
|
|
|
|
Eol,
|
|
|
|
),
|
|
|
|
}
|
|
|
|
|
|
|
|
test! {
|
|
|
|
name: tokenize_comment_before_variable,
|
|
|
|
text: "
|
|
|
|
#
|
|
|
|
A='1'
|
|
|
|
echo:
|
|
|
|
echo {{A}}
|
|
|
|
",
|
|
|
|
tokens: (
|
|
|
|
Comment:"#",
|
|
|
|
Eol,
|
2019-11-07 10:55:15 -08:00
|
|
|
Identifier:"A",
|
2019-10-17 20:04:54 -07:00
|
|
|
Equals,
|
|
|
|
StringRaw:"'1'",
|
|
|
|
Eol,
|
2019-11-07 10:55:15 -08:00
|
|
|
Identifier:"echo",
|
2019-10-17 20:04:54 -07:00
|
|
|
Colon,
|
|
|
|
Eol,
|
|
|
|
Indent,
|
|
|
|
Text:"echo ",
|
|
|
|
InterpolationStart,
|
2019-11-07 10:55:15 -08:00
|
|
|
Identifier:"A",
|
2019-10-17 20:04:54 -07:00
|
|
|
InterpolationEnd,
|
|
|
|
Eol,
|
|
|
|
Dedent,
|
|
|
|
),
|
|
|
|
}
|
|
|
|
|
|
|
|
test! {
|
|
|
|
name: tokenize_interpolation_backticks,
|
|
|
|
text: "hello:\n echo {{`echo hello` + `echo goodbye`}}",
|
|
|
|
tokens: (
|
2019-11-07 10:55:15 -08:00
|
|
|
Identifier:"hello",
|
2019-10-17 20:04:54 -07:00
|
|
|
Colon,
|
|
|
|
Eol,
|
|
|
|
Indent:" ",
|
|
|
|
Text:"echo ",
|
|
|
|
InterpolationStart,
|
|
|
|
Backtick:"`echo hello`",
|
|
|
|
Whitespace,
|
|
|
|
Plus,
|
|
|
|
Whitespace,
|
|
|
|
Backtick:"`echo goodbye`",
|
|
|
|
InterpolationEnd,
|
|
|
|
Dedent
|
|
|
|
),
|
|
|
|
}
|
|
|
|
|
|
|
|
test! {
|
|
|
|
name: tokenize_empty_interpolation,
|
|
|
|
text: "hello:\n echo {{}}",
|
|
|
|
tokens: (
|
2019-11-07 10:55:15 -08:00
|
|
|
Identifier:"hello",
|
2019-10-17 20:04:54 -07:00
|
|
|
Colon,
|
|
|
|
Eol,
|
|
|
|
Indent:" ",
|
|
|
|
Text:"echo ",
|
|
|
|
InterpolationStart,
|
|
|
|
InterpolationEnd,
|
|
|
|
Dedent,
|
|
|
|
),
|
|
|
|
}
|
|
|
|
|
|
|
|
test! {
|
|
|
|
name: tokenize_assignment_backticks,
|
|
|
|
text: "a = `echo hello` + `echo goodbye`",
|
|
|
|
tokens: (
|
2019-11-07 10:55:15 -08:00
|
|
|
Identifier:"a",
|
2019-10-17 20:04:54 -07:00
|
|
|
Whitespace,
|
|
|
|
Equals,
|
|
|
|
Whitespace,
|
|
|
|
Backtick:"`echo hello`",
|
|
|
|
Whitespace,
|
|
|
|
Plus,
|
|
|
|
Whitespace,
|
|
|
|
Backtick:"`echo goodbye`",
|
|
|
|
),
|
|
|
|
}
|
|
|
|
|
|
|
|
test! {
|
|
|
|
name: tokenize_multiple,
|
|
|
|
text: "
|
|
|
|
|
|
|
|
hello:
|
|
|
|
a
|
|
|
|
b
|
|
|
|
|
|
|
|
c
|
|
|
|
|
|
|
|
d
|
|
|
|
|
|
|
|
# hello
|
|
|
|
bob:
|
|
|
|
frank
|
|
|
|
\t
|
|
|
|
",
|
|
|
|
tokens: (
|
|
|
|
Eol,
|
2019-11-07 10:55:15 -08:00
|
|
|
Identifier:"hello",
|
2019-10-17 20:04:54 -07:00
|
|
|
Colon,
|
|
|
|
Eol,
|
|
|
|
Indent,
|
|
|
|
Text:"a",
|
|
|
|
Eol,
|
|
|
|
Whitespace:" ",
|
|
|
|
Text:"b",
|
|
|
|
Eol,
|
|
|
|
Eol,
|
|
|
|
Whitespace:" ",
|
|
|
|
Text:"c",
|
|
|
|
Eol,
|
|
|
|
Eol,
|
|
|
|
Whitespace:" ",
|
|
|
|
Text:"d",
|
|
|
|
Eol,
|
|
|
|
Eol,
|
|
|
|
Dedent,
|
|
|
|
Comment:"# hello",
|
|
|
|
Eol,
|
2019-11-07 10:55:15 -08:00
|
|
|
Identifier:"bob",
|
2019-10-17 20:04:54 -07:00
|
|
|
Colon,
|
|
|
|
Eol,
|
|
|
|
Indent:" ",
|
|
|
|
Text:"frank",
|
|
|
|
Eol,
|
|
|
|
Eol,
|
|
|
|
Dedent,
|
|
|
|
),
|
|
|
|
}
|
|
|
|
|
|
|
|
test! {
|
|
|
|
name: tokenize_comment,
|
|
|
|
text: "a:=#",
|
|
|
|
tokens: (
|
2019-11-07 10:55:15 -08:00
|
|
|
Identifier:"a",
|
2019-10-17 20:04:54 -07:00
|
|
|
ColonEquals,
|
|
|
|
Comment:"#",
|
|
|
|
),
|
|
|
|
}
|
|
|
|
|
|
|
|
test! {
|
|
|
|
name: tokenize_comment_with_bang,
|
|
|
|
text: "a:=#foo!",
|
|
|
|
tokens: (
|
2019-11-07 10:55:15 -08:00
|
|
|
Identifier:"a",
|
2019-10-17 20:04:54 -07:00
|
|
|
ColonEquals,
|
|
|
|
Comment:"#foo!",
|
|
|
|
),
|
|
|
|
}
|
|
|
|
|
|
|
|
test! {
|
|
|
|
name: tokenize_order,
|
|
|
|
text: "
|
|
|
|
b: a
|
|
|
|
@mv a b
|
|
|
|
|
|
|
|
a:
|
|
|
|
@touch F
|
|
|
|
@touch a
|
|
|
|
|
|
|
|
d: c
|
|
|
|
@rm c
|
|
|
|
|
|
|
|
c: b
|
|
|
|
@mv b c
|
|
|
|
",
|
|
|
|
tokens: (
|
2019-11-07 10:55:15 -08:00
|
|
|
Identifier:"b",
|
2019-10-17 20:04:54 -07:00
|
|
|
Colon,
|
|
|
|
Whitespace,
|
2019-11-07 10:55:15 -08:00
|
|
|
Identifier:"a",
|
2019-10-17 20:04:54 -07:00
|
|
|
Eol,
|
|
|
|
Indent,
|
|
|
|
Text:"@mv a b",
|
|
|
|
Eol,
|
|
|
|
Eol,
|
|
|
|
Dedent,
|
2019-11-07 10:55:15 -08:00
|
|
|
Identifier:"a",
|
2019-10-17 20:04:54 -07:00
|
|
|
Colon,
|
|
|
|
Eol,
|
|
|
|
Indent,
|
|
|
|
Text:"@touch F",
|
|
|
|
Eol,
|
|
|
|
Whitespace:" ",
|
|
|
|
Text:"@touch a",
|
|
|
|
Eol,
|
|
|
|
Eol,
|
|
|
|
Dedent,
|
2019-11-07 10:55:15 -08:00
|
|
|
Identifier:"d",
|
2019-10-17 20:04:54 -07:00
|
|
|
Colon,
|
|
|
|
Whitespace,
|
2019-11-07 10:55:15 -08:00
|
|
|
Identifier:"c",
|
2019-10-17 20:04:54 -07:00
|
|
|
Eol,
|
|
|
|
Indent,
|
|
|
|
Text:"@rm c",
|
|
|
|
Eol,
|
|
|
|
Eol,
|
|
|
|
Dedent,
|
2019-11-07 10:55:15 -08:00
|
|
|
Identifier:"c",
|
2019-10-17 20:04:54 -07:00
|
|
|
Colon,
|
|
|
|
Whitespace,
|
2019-11-07 10:55:15 -08:00
|
|
|
Identifier:"b",
|
2019-10-17 20:04:54 -07:00
|
|
|
Eol,
|
|
|
|
Indent,
|
|
|
|
Text:"@mv b c",
|
|
|
|
Eol,
|
|
|
|
Dedent,
|
|
|
|
),
|
|
|
|
}
|
|
|
|
|
|
|
|
test! {
|
|
|
|
name: tokenize_parens,
|
|
|
|
text: "((())) )abc(+",
|
|
|
|
tokens: (
|
|
|
|
ParenL,
|
|
|
|
ParenL,
|
|
|
|
ParenL,
|
|
|
|
ParenR,
|
|
|
|
ParenR,
|
|
|
|
ParenR,
|
|
|
|
Whitespace,
|
|
|
|
ParenR,
|
2019-11-07 10:55:15 -08:00
|
|
|
Identifier:"abc",
|
2019-10-17 20:04:54 -07:00
|
|
|
ParenL,
|
|
|
|
Plus,
|
|
|
|
),
|
|
|
|
}
|
|
|
|
|
|
|
|
test! {
|
|
|
|
name: crlf_newline,
|
|
|
|
text: "#\r\n#asdf\r\n",
|
|
|
|
tokens: (
|
|
|
|
Comment:"#",
|
|
|
|
Eol:"\r\n",
|
|
|
|
Comment:"#asdf",
|
|
|
|
Eol:"\r\n",
|
|
|
|
),
|
|
|
|
}
|
|
|
|
|
|
|
|
test! {
|
|
|
|
name: multiple_recipes,
|
|
|
|
text: "a:\n foo\nb:",
|
|
|
|
tokens: (
|
2019-11-07 10:55:15 -08:00
|
|
|
Identifier:"a",
|
2019-10-17 20:04:54 -07:00
|
|
|
Colon,
|
|
|
|
Eol,
|
|
|
|
Indent:" ",
|
|
|
|
Text:"foo",
|
|
|
|
Eol,
|
|
|
|
Dedent,
|
2019-11-07 10:55:15 -08:00
|
|
|
Identifier:"b",
|
2019-10-17 20:04:54 -07:00
|
|
|
Colon,
|
|
|
|
),
|
2019-04-11 23:58:08 -07:00
|
|
|
}
|
|
|
|
|
2019-11-10 23:17:47 -08:00
|
|
|
test! {
|
|
|
|
name: brackets,
|
|
|
|
text: "][",
|
|
|
|
tokens: (BracketR, BracketL),
|
|
|
|
}
|
|
|
|
|
2019-11-07 10:55:15 -08:00
|
|
|
error! {
|
2017-11-18 03:36:02 -08:00
|
|
|
name: tokenize_space_then_tab,
|
|
|
|
input: "a:
|
|
|
|
0
|
|
|
|
1
|
|
|
|
\t2
|
|
|
|
",
|
2019-04-15 22:40:02 -07:00
|
|
|
offset: 9,
|
2017-11-18 03:36:02 -08:00
|
|
|
line: 3,
|
|
|
|
column: 0,
|
2019-04-15 22:40:02 -07:00
|
|
|
width: 1,
|
2017-11-18 03:36:02 -08:00
|
|
|
kind: InconsistentLeadingWhitespace{expected: " ", found: "\t"},
|
|
|
|
}
|
|
|
|
|
2019-11-07 10:55:15 -08:00
|
|
|
error! {
|
2017-11-18 03:36:02 -08:00
|
|
|
name: tokenize_tabs_then_tab_space,
|
|
|
|
input: "a:
|
|
|
|
\t\t0
|
|
|
|
\t\t 1
|
|
|
|
\t 2
|
|
|
|
",
|
2019-04-15 22:40:02 -07:00
|
|
|
offset: 12,
|
2017-11-18 03:36:02 -08:00
|
|
|
line: 3,
|
|
|
|
column: 0,
|
2019-12-11 20:25:16 -08:00
|
|
|
width: 3,
|
|
|
|
kind: InconsistentLeadingWhitespace{expected: "\t\t", found: "\t "},
|
2017-11-18 03:36:02 -08:00
|
|
|
}
|
|
|
|
|
2019-11-07 10:55:15 -08:00
|
|
|
error! {
|
2019-04-15 22:40:02 -07:00
|
|
|
name: tokenize_unknown,
|
|
|
|
input: "~",
|
|
|
|
offset: 0,
|
2017-11-18 03:36:02 -08:00
|
|
|
line: 0,
|
|
|
|
column: 0,
|
2019-04-15 22:40:02 -07:00
|
|
|
width: 1,
|
2017-11-18 03:36:02 -08:00
|
|
|
kind: UnknownStartOfToken,
|
|
|
|
}
|
|
|
|
|
2019-11-07 10:55:15 -08:00
|
|
|
error! {
|
2019-04-15 22:40:02 -07:00
|
|
|
name: unterminated_string_with_escapes,
|
|
|
|
input: r#"a = "\n\t\r\"\\"#,
|
|
|
|
offset: 4,
|
2017-11-18 03:36:02 -08:00
|
|
|
line: 0,
|
2019-04-15 22:40:02 -07:00
|
|
|
column: 4,
|
|
|
|
width: 1,
|
2017-11-18 03:36:02 -08:00
|
|
|
kind: UnterminatedString,
|
|
|
|
}
|
|
|
|
|
2019-11-07 10:55:15 -08:00
|
|
|
error! {
|
2019-04-15 22:40:02 -07:00
|
|
|
name: unterminated_raw_string,
|
|
|
|
input: "r a='asdf",
|
|
|
|
offset: 4,
|
2017-11-18 03:36:02 -08:00
|
|
|
line: 0,
|
2019-04-15 22:40:02 -07:00
|
|
|
column: 4,
|
|
|
|
width: 1,
|
2017-11-18 03:36:02 -08:00
|
|
|
kind: UnterminatedString,
|
|
|
|
}
|
|
|
|
|
2019-11-07 10:55:15 -08:00
|
|
|
error! {
|
2019-04-15 22:40:02 -07:00
|
|
|
name: unterminated_interpolation,
|
|
|
|
input: "foo:\n echo {{
|
|
|
|
",
|
|
|
|
offset: 11,
|
|
|
|
line: 1,
|
|
|
|
column: 6,
|
|
|
|
width: 2,
|
|
|
|
kind: UnterminatedInterpolation,
|
|
|
|
}
|
|
|
|
|
2019-11-07 10:55:15 -08:00
|
|
|
error! {
|
2019-04-15 22:40:02 -07:00
|
|
|
name: unterminated_backtick,
|
|
|
|
input: "`echo",
|
|
|
|
offset: 0,
|
2017-11-18 03:36:02 -08:00
|
|
|
line: 0,
|
2019-04-15 22:40:02 -07:00
|
|
|
column: 0,
|
|
|
|
width: 1,
|
|
|
|
kind: UnterminatedBacktick,
|
2017-11-18 03:36:02 -08:00
|
|
|
}
|
|
|
|
|
2019-11-07 10:55:15 -08:00
|
|
|
error! {
|
2019-04-15 22:40:02 -07:00
|
|
|
name: unpaired_carriage_return,
|
|
|
|
input: "foo\rbar",
|
|
|
|
offset: 3,
|
|
|
|
line: 0,
|
|
|
|
column: 3,
|
|
|
|
width: 1,
|
|
|
|
kind: UnpairedCarriageReturn,
|
|
|
|
}
|
|
|
|
|
2019-11-07 10:55:15 -08:00
|
|
|
error! {
|
2019-04-15 22:40:02 -07:00
|
|
|
name: unknown_start_of_token_ampersand,
|
|
|
|
input: " \r\n&",
|
|
|
|
offset: 3,
|
2017-12-02 12:49:31 -08:00
|
|
|
line: 1,
|
2019-04-15 22:40:02 -07:00
|
|
|
column: 0,
|
|
|
|
width: 1,
|
|
|
|
kind: UnknownStartOfToken,
|
|
|
|
}
|
|
|
|
|
2019-11-07 10:55:15 -08:00
|
|
|
error! {
|
2019-04-15 22:40:02 -07:00
|
|
|
name: unknown_start_of_token_tilde,
|
|
|
|
input: "~",
|
|
|
|
offset: 0,
|
|
|
|
line: 0,
|
|
|
|
column: 0,
|
|
|
|
width: 1,
|
|
|
|
kind: UnknownStartOfToken,
|
|
|
|
}
|
|
|
|
|
Reform positional argument parsing (#523)
This diff makes positional argument parsing much cleaner, along with
adding a bunch of tests. Just's positional argument parsing is rather,
complex, so hopefully this reform allows it to both be correct and stay
correct.
User-visible changes:
- `just ..` is now accepted, with the same effect as `just ../`
- `just .` is also accepted, with the same effect as `just`
- It is now an error to pass arguments or overrides to subcommands
that do not accept them, namely `--dump`, `--edit`, `--list`,
`--show`, and `--summary`. It is also an error to pass arguments to
`--evaluate`, although `--evaluate` does of course still accept
overrides.
(This is a breaking change, but hopefully worth it, as it will allow us
to add arguments to subcommands which did not previously take
them, if we so desire.)
- Subcommands which do not accept arguments may now accept a
single search-directory argument, so `just --list ../` and
`just --dump foo/` are now accepted, with the former starting the
search for the justfile to list in the parent directory, and the latter
starting the search for the justfile to dump in `foo`.
2019-11-10 18:02:36 -08:00
|
|
|
error! {
|
|
|
|
name: invalid_name_start_dash,
|
|
|
|
input: "-foo",
|
|
|
|
offset: 0,
|
|
|
|
line: 0,
|
|
|
|
column: 0,
|
|
|
|
width: 1,
|
|
|
|
kind: UnknownStartOfToken,
|
|
|
|
}
|
|
|
|
|
|
|
|
error! {
|
|
|
|
name: invalid_name_start_digit,
|
|
|
|
input: "0foo",
|
|
|
|
offset: 0,
|
|
|
|
line: 0,
|
|
|
|
column: 0,
|
|
|
|
width: 1,
|
|
|
|
kind: UnknownStartOfToken,
|
|
|
|
}
|
|
|
|
|
2019-11-07 10:55:15 -08:00
|
|
|
error! {
|
2019-04-15 22:40:02 -07:00
|
|
|
name: unterminated_string,
|
|
|
|
input: r#"a = ""#,
|
|
|
|
offset: 4,
|
|
|
|
line: 0,
|
|
|
|
column: 4,
|
|
|
|
width: 1,
|
|
|
|
kind: UnterminatedString,
|
2017-12-02 12:49:31 -08:00
|
|
|
}
|
|
|
|
|
2019-11-07 10:55:15 -08:00
|
|
|
error! {
|
2019-12-11 20:25:16 -08:00
|
|
|
name: mixed_leading_whitespace_recipe,
|
2018-01-05 02:03:58 -08:00
|
|
|
input: "a:\n\t echo hello",
|
2019-04-15 22:40:02 -07:00
|
|
|
offset: 3,
|
2017-11-18 03:36:02 -08:00
|
|
|
line: 1,
|
|
|
|
column: 0,
|
2019-04-15 22:40:02 -07:00
|
|
|
width: 2,
|
2017-11-18 03:36:02 -08:00
|
|
|
kind: MixedLeadingWhitespace{whitespace: "\t "},
|
|
|
|
}
|
2019-04-15 22:40:02 -07:00
|
|
|
|
2019-12-11 20:25:16 -08:00
|
|
|
error! {
|
|
|
|
name: mixed_leading_whitespace_normal,
|
|
|
|
input: "a\n\t echo hello",
|
|
|
|
offset: 2,
|
|
|
|
line: 1,
|
|
|
|
column: 0,
|
|
|
|
width: 2,
|
|
|
|
kind: MixedLeadingWhitespace{whitespace: "\t "},
|
|
|
|
}
|
|
|
|
|
|
|
|
error! {
|
|
|
|
name: mixed_leading_whitespace_indent,
|
|
|
|
input: "a\n foo\n \tbar",
|
|
|
|
offset: 7,
|
|
|
|
line: 2,
|
|
|
|
column: 0,
|
|
|
|
width: 2,
|
|
|
|
kind: MixedLeadingWhitespace{whitespace: " \t"},
|
|
|
|
}
|
|
|
|
|
|
|
|
error! {
|
|
|
|
name: bad_dedent,
|
|
|
|
input: "a\n foo\n bar\n baz",
|
|
|
|
offset: 14,
|
|
|
|
line: 3,
|
|
|
|
column: 0,
|
|
|
|
width: 2,
|
|
|
|
kind: InconsistentLeadingWhitespace{expected: " ", found: " "},
|
|
|
|
}
|
|
|
|
|
2019-11-07 10:55:15 -08:00
|
|
|
error! {
|
2019-04-15 22:40:02 -07:00
|
|
|
name: unclosed_interpolation_delimiter,
|
|
|
|
input: "a:\n echo {{ foo",
|
|
|
|
offset: 9,
|
|
|
|
line: 1,
|
|
|
|
column: 6,
|
|
|
|
width: 2,
|
|
|
|
kind: UnterminatedInterpolation,
|
|
|
|
}
|
2017-11-18 03:36:02 -08:00
|
|
|
}
|