apply clippy lints from version 0.1.89
This commit is contained in:
parent
d9ae985282
commit
0ee456756a
|
@ -19,6 +19,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
||||||
- Boolean map (tag)
|
- Boolean map (tag)
|
||||||
- Member access (e.g. `.objective` to get objective name where int is stored)
|
- Member access (e.g. `.objective` to get objective name where int is stored)
|
||||||
- Return statement
|
- Return statement
|
||||||
|
- internal `print` function
|
||||||
- Example: barebones compiler
|
- Example: barebones compiler
|
||||||
|
|
||||||
### Changed
|
### Changed
|
||||||
|
|
|
@ -7,11 +7,11 @@ pub enum Error {
|
||||||
#[error(transparent)]
|
#[error(transparent)]
|
||||||
LexicalError(#[from] crate::lexical::Error),
|
LexicalError(#[from] crate::lexical::Error),
|
||||||
#[error(transparent)]
|
#[error(transparent)]
|
||||||
ParseError(#[from] crate::syntax::error::Error),
|
ParseError(#[from] Box<crate::syntax::error::Error>),
|
||||||
#[error(transparent)]
|
#[error(transparent)]
|
||||||
SemanticError(#[from] crate::semantic::error::Error),
|
SemanticError(#[from] crate::semantic::error::Error),
|
||||||
#[error(transparent)]
|
#[error(transparent)]
|
||||||
TranspileError(#[from] crate::transpile::TranspileError),
|
TranspileError(#[from] Box<crate::transpile::TranspileError>),
|
||||||
#[error("An error occurred: {0}")]
|
#[error("An error occurred: {0}")]
|
||||||
Other(String),
|
Other(String),
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,7 +12,7 @@ pub trait FileProvider {
|
||||||
/// # Errors
|
/// # Errors
|
||||||
/// - If an error occurs while reading the file.
|
/// - If an error occurs while reading the file.
|
||||||
/// - If the file does not exist.
|
/// - If the file does not exist.
|
||||||
fn read_bytes<P: AsRef<Path>>(&self, path: P) -> Result<Cow<[u8]>, Error>;
|
fn read_bytes<P: AsRef<Path>>(&self, path: P) -> Result<Cow<'_, [u8]>, Error>;
|
||||||
|
|
||||||
/// Reads the contents of the file at the given path.
|
/// Reads the contents of the file at the given path.
|
||||||
///
|
///
|
||||||
|
@ -20,7 +20,7 @@ pub trait FileProvider {
|
||||||
/// - If an error occurs while reading the file.
|
/// - If an error occurs while reading the file.
|
||||||
/// - If the file does not exist.
|
/// - If the file does not exist.
|
||||||
/// - If the file is not valid UTF-8.
|
/// - If the file is not valid UTF-8.
|
||||||
fn read_str<P: AsRef<Path>>(&self, path: P) -> Result<Cow<str>, Error> {
|
fn read_str<P: AsRef<Path>>(&self, path: P) -> Result<Cow<'_, str>, Error> {
|
||||||
let bytes = self.read_bytes(path)?;
|
let bytes = self.read_bytes(path)?;
|
||||||
let string = std::str::from_utf8(&bytes)
|
let string = std::str::from_utf8(&bytes)
|
||||||
.map_err(|err| {
|
.map_err(|err| {
|
||||||
|
@ -57,14 +57,14 @@ where
|
||||||
}
|
}
|
||||||
|
|
||||||
impl FileProvider for FsProvider {
|
impl FileProvider for FsProvider {
|
||||||
fn read_bytes<P: AsRef<Path>>(&self, path: P) -> Result<Cow<[u8]>, Error> {
|
fn read_bytes<P: AsRef<Path>>(&self, path: P) -> Result<Cow<'_, [u8]>, Error> {
|
||||||
let full_path = self.root.join(path);
|
let full_path = self.root.join(path);
|
||||||
std::fs::read(full_path)
|
std::fs::read(full_path)
|
||||||
.map(Cow::Owned)
|
.map(Cow::Owned)
|
||||||
.map_err(Error::from)
|
.map_err(Error::from)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn read_str<P: AsRef<Path>>(&self, path: P) -> Result<Cow<str>, Error> {
|
fn read_str<P: AsRef<Path>>(&self, path: P) -> Result<Cow<'_, str>, Error> {
|
||||||
let full_path = self.root.join(path);
|
let full_path = self.root.join(path);
|
||||||
std::fs::read_to_string(full_path)
|
std::fs::read_to_string(full_path)
|
||||||
.map(Cow::Owned)
|
.map(Cow::Owned)
|
||||||
|
@ -178,7 +178,7 @@ mod vfs {
|
||||||
use shulkerbox::virtual_fs::{VFile, VFolder};
|
use shulkerbox::virtual_fs::{VFile, VFolder};
|
||||||
|
|
||||||
impl FileProvider for VFolder {
|
impl FileProvider for VFolder {
|
||||||
fn read_bytes<P: AsRef<Path>>(&self, path: P) -> Result<Cow<[u8]>, Error> {
|
fn read_bytes<P: AsRef<Path>>(&self, path: P) -> Result<Cow<'_, [u8]>, Error> {
|
||||||
normalize_path_str(path).map_or_else(
|
normalize_path_str(path).map_or_else(
|
||||||
|| Err(Error::from(std::io::ErrorKind::InvalidData)),
|
|| Err(Error::from(std::io::ErrorKind::InvalidData)),
|
||||||
|path| {
|
|path| {
|
||||||
|
@ -189,7 +189,7 @@ mod vfs {
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn read_str<P: AsRef<Path>>(&self, path: P) -> Result<Cow<str>, Error> {
|
fn read_str<P: AsRef<Path>>(&self, path: P) -> Result<Cow<'_, str>, Error> {
|
||||||
normalize_path_str(path).map_or_else(
|
normalize_path_str(path).map_or_else(
|
||||||
|| Err(Error::from(std::io::ErrorKind::InvalidData)),
|
|| Err(Error::from(std::io::ErrorKind::InvalidData)),
|
||||||
|path| {
|
|path| {
|
||||||
|
|
|
@ -69,7 +69,7 @@ impl SourceFile {
|
||||||
|
|
||||||
/// Get the [`SourceIterator`] for the source file.
|
/// Get the [`SourceIterator`] for the source file.
|
||||||
#[must_use]
|
#[must_use]
|
||||||
pub fn iter<'a>(self: &'a Arc<Self>) -> SourceIterator<'a> {
|
pub fn iter(self: &Arc<Self>) -> SourceIterator<'_> {
|
||||||
SourceIterator {
|
SourceIterator {
|
||||||
source_file: self,
|
source_file: self,
|
||||||
iterator: self.content().char_indices().peekable(),
|
iterator: self.content().char_indices().peekable(),
|
||||||
|
|
|
@ -161,7 +161,7 @@ pub enum Token {
|
||||||
DocComment(DocComment),
|
DocComment(DocComment),
|
||||||
CommandLiteral(CommandLiteral),
|
CommandLiteral(CommandLiteral),
|
||||||
StringLiteral(StringLiteral),
|
StringLiteral(StringLiteral),
|
||||||
MacroStringLiteral(MacroStringLiteral),
|
MacroStringLiteral(Box<MacroStringLiteral>),
|
||||||
}
|
}
|
||||||
|
|
||||||
impl SourceElement for Token {
|
impl SourceElement for Token {
|
||||||
|
@ -325,7 +325,7 @@ pub struct StringLiteral {
|
||||||
impl StringLiteral {
|
impl StringLiteral {
|
||||||
/// Returns the string content without escapement characters, leading and trailing double quotes.
|
/// Returns the string content without escapement characters, leading and trailing double quotes.
|
||||||
#[must_use]
|
#[must_use]
|
||||||
pub fn str_content(&self) -> Cow<str> {
|
pub fn str_content(&self) -> Cow<'_, str> {
|
||||||
let string = self.span.str();
|
let string = self.span.str();
|
||||||
let string = &string[1..string.len() - 1];
|
let string = &string[1..string.len() - 1];
|
||||||
if string.contains('\\') {
|
if string.contains('\\') {
|
||||||
|
@ -740,7 +740,7 @@ impl Token {
|
||||||
handler.receive(error::Error::from(UnterminatedDelimitedComment {
|
handler.receive(error::Error::from(UnterminatedDelimitedComment {
|
||||||
span: Span::new(iter.source_file().clone(), start, start + 2).unwrap(),
|
span: Span::new(iter.source_file().clone(), start, start + 2).unwrap(),
|
||||||
}));
|
}));
|
||||||
return Err(TokenizeError::FatalLexicalError);
|
Err(TokenizeError::FatalLexicalError)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// When there is no second slash and at the start of a line
|
// When there is no second slash and at the start of a line
|
||||||
|
@ -883,14 +883,14 @@ impl Token {
|
||||||
}
|
}
|
||||||
.into())
|
.into())
|
||||||
} else {
|
} else {
|
||||||
Ok(MacroStringLiteral {
|
Ok(Box::new(MacroStringLiteral {
|
||||||
starting_backtick,
|
starting_backtick,
|
||||||
parts,
|
parts,
|
||||||
ending_backtick: Punctuation {
|
ending_backtick: Punctuation {
|
||||||
span: Self::create_span(start, iter),
|
span: Self::create_span(start, iter),
|
||||||
punctuation: '`',
|
punctuation: '`',
|
||||||
},
|
},
|
||||||
}
|
})
|
||||||
.into())
|
.into())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -100,7 +100,7 @@ pub fn parse(
|
||||||
tracing::info!("Parsing the source code at path: {}", path.display());
|
tracing::info!("Parsing the source code at path: {}", path.display());
|
||||||
|
|
||||||
let mut parser = Parser::new(&tokens);
|
let mut parser = Parser::new(&tokens);
|
||||||
let program = parser.parse_program(handler)?;
|
let program = parser.parse_program(handler).map_err(Box::new)?;
|
||||||
|
|
||||||
if handler.has_received() {
|
if handler.has_received() {
|
||||||
return Err(Error::other(
|
return Err(Error::other(
|
||||||
|
@ -165,8 +165,9 @@ where
|
||||||
|
|
||||||
tracing::info!("Transpiling the source code.");
|
tracing::info!("Transpiling the source code.");
|
||||||
|
|
||||||
let datapack =
|
let datapack = Transpiler::new(main_namespace_name, pack_format)
|
||||||
Transpiler::new(main_namespace_name, pack_format).transpile(&programs, handler)?;
|
.transpile(&programs, handler)
|
||||||
|
.map_err(Box::new)?;
|
||||||
|
|
||||||
if handler.has_received() {
|
if handler.has_received() {
|
||||||
return Err(Error::other(
|
return Err(Error::other(
|
||||||
|
|
|
@ -48,7 +48,7 @@ pub enum Error {
|
||||||
|
|
||||||
/// An error that occurs when a function declaration is missing.
|
/// An error that occurs when a function declaration is missing.
|
||||||
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
||||||
pub struct UnexpectedExpression(pub Expression);
|
pub struct UnexpectedExpression(pub Box<Expression>);
|
||||||
|
|
||||||
impl Display for UnexpectedExpression {
|
impl Display for UnexpectedExpression {
|
||||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||||
|
|
|
@ -70,7 +70,7 @@ fn get_global_scope(declarations: &[Declaration]) -> SemanticScope<'static> {
|
||||||
impl Namespace {
|
impl Namespace {
|
||||||
/// Analyzes the semantics of the namespace.
|
/// Analyzes the semantics of the namespace.
|
||||||
fn analyze_semantics(&self, handler: &impl Handler<base::Error>) -> Result<(), error::Error> {
|
fn analyze_semantics(&self, handler: &impl Handler<base::Error>) -> Result<(), error::Error> {
|
||||||
let name = self.namespace_name();
|
let name = self.name();
|
||||||
Self::validate_str(name.str_content().as_ref()).map_err(|invalid_chars| {
|
Self::validate_str(name.str_content().as_ref()).map_err(|invalid_chars| {
|
||||||
let err = error::Error::from(InvalidNamespaceName {
|
let err = error::Error::from(InvalidNamespaceName {
|
||||||
name: name.clone(),
|
name: name.clone(),
|
||||||
|
@ -561,7 +561,7 @@ impl Primary {
|
||||||
VariableType::Function | VariableType::InternalFunction => Ok(()),
|
VariableType::Function | VariableType::InternalFunction => Ok(()),
|
||||||
_ => {
|
_ => {
|
||||||
let err = error::Error::UnexpectedExpression(UnexpectedExpression(
|
let err = error::Error::UnexpectedExpression(UnexpectedExpression(
|
||||||
Expression::Primary(self.clone()),
|
Box::new(Expression::Primary(self.clone())),
|
||||||
));
|
));
|
||||||
handler.receive(err.clone());
|
handler.receive(err.clone());
|
||||||
Err(err)
|
Err(err)
|
||||||
|
@ -930,9 +930,10 @@ impl MacroStringLiteral {
|
||||||
MacroStringLiteralPart::MacroUsage { identifier, .. } => {
|
MacroStringLiteralPart::MacroUsage { identifier, .. } => {
|
||||||
if let Some(variable_type) = scope.get_variable(identifier.span.str()) {
|
if let Some(variable_type) = scope.get_variable(identifier.span.str()) {
|
||||||
if variable_type != VariableType::MacroParameter {
|
if variable_type != VariableType::MacroParameter {
|
||||||
let err = error::Error::UnexpectedExpression(UnexpectedExpression(
|
let err =
|
||||||
Expression::Primary(Primary::Identifier(identifier.clone())),
|
error::Error::UnexpectedExpression(UnexpectedExpression(Box::new(
|
||||||
));
|
Expression::Primary(Primary::Identifier(identifier.clone())),
|
||||||
|
)));
|
||||||
handler.receive(err.clone());
|
handler.receive(err.clone());
|
||||||
errs.push(err);
|
errs.push(err);
|
||||||
}
|
}
|
||||||
|
|
|
@ -80,7 +80,7 @@ impl<'a> Parser<'a> {
|
||||||
}
|
}
|
||||||
}),
|
}),
|
||||||
});
|
});
|
||||||
handler.receive(err.clone());
|
handler.receive(Box::new(err.clone()));
|
||||||
|
|
||||||
return Err(err);
|
return Err(err);
|
||||||
}
|
}
|
||||||
|
@ -90,7 +90,7 @@ impl<'a> Parser<'a> {
|
||||||
expected: SyntaxKind::Punctuation(expected),
|
expected: SyntaxKind::Punctuation(expected),
|
||||||
found: self.get_reading(None).into_token(),
|
found: self.get_reading(None).into_token(),
|
||||||
});
|
});
|
||||||
handler.receive(err.clone());
|
handler.receive(Box::new(err.clone()));
|
||||||
|
|
||||||
return Err(err);
|
return Err(err);
|
||||||
};
|
};
|
||||||
|
@ -129,7 +129,7 @@ impl<'a> Parser<'a> {
|
||||||
expected: SyntaxKind::Punctuation(expected),
|
expected: SyntaxKind::Punctuation(expected),
|
||||||
found: self.peek().into_token(),
|
found: self.peek().into_token(),
|
||||||
});
|
});
|
||||||
handler.receive(err.clone());
|
handler.receive(Box::new(err.clone()));
|
||||||
return Err(err);
|
return Err(err);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -393,7 +393,7 @@ impl Frame<'_> {
|
||||||
expected: SyntaxKind::Identifier,
|
expected: SyntaxKind::Identifier,
|
||||||
found: found.into_token(),
|
found: found.into_token(),
|
||||||
});
|
});
|
||||||
handler.receive(err.clone());
|
handler.receive(Box::new(err.clone()));
|
||||||
Err(err)
|
Err(err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -432,7 +432,7 @@ impl Frame<'_> {
|
||||||
expected: SyntaxKind::StringLiteral,
|
expected: SyntaxKind::StringLiteral,
|
||||||
found: found.into_token(),
|
found: found.into_token(),
|
||||||
});
|
});
|
||||||
handler.receive(err.clone());
|
handler.receive(Box::new(err.clone()));
|
||||||
Err(err)
|
Err(err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -447,13 +447,13 @@ impl Frame<'_> {
|
||||||
handler: &impl Handler<base::Error>,
|
handler: &impl Handler<base::Error>,
|
||||||
) -> ParseResult<MacroStringLiteral> {
|
) -> ParseResult<MacroStringLiteral> {
|
||||||
match self.next_significant_token() {
|
match self.next_significant_token() {
|
||||||
Reading::Atomic(Token::MacroStringLiteral(literal)) => Ok(literal),
|
Reading::Atomic(Token::MacroStringLiteral(literal)) => Ok(*literal),
|
||||||
found => {
|
found => {
|
||||||
let err = Error::UnexpectedSyntax(UnexpectedSyntax {
|
let err = Error::UnexpectedSyntax(UnexpectedSyntax {
|
||||||
expected: SyntaxKind::MacroStringLiteral,
|
expected: SyntaxKind::MacroStringLiteral,
|
||||||
found: found.into_token(),
|
found: found.into_token(),
|
||||||
});
|
});
|
||||||
handler.receive(err.clone());
|
handler.receive(Box::new(err.clone()));
|
||||||
Err(err)
|
Err(err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -469,13 +469,13 @@ impl Frame<'_> {
|
||||||
) -> ParseResult<AnyStringLiteral> {
|
) -> ParseResult<AnyStringLiteral> {
|
||||||
match self.next_significant_token() {
|
match self.next_significant_token() {
|
||||||
Reading::Atomic(Token::StringLiteral(literal)) => Ok(literal.into()),
|
Reading::Atomic(Token::StringLiteral(literal)) => Ok(literal.into()),
|
||||||
Reading::Atomic(Token::MacroStringLiteral(literal)) => Ok(literal.into()),
|
Reading::Atomic(Token::MacroStringLiteral(literal)) => Ok((*literal).into()),
|
||||||
found => {
|
found => {
|
||||||
let err = Error::UnexpectedSyntax(UnexpectedSyntax {
|
let err = Error::UnexpectedSyntax(UnexpectedSyntax {
|
||||||
expected: SyntaxKind::AnyStringLiteral,
|
expected: SyntaxKind::AnyStringLiteral,
|
||||||
found: found.into_token(),
|
found: found.into_token(),
|
||||||
});
|
});
|
||||||
handler.receive(err.clone());
|
handler.receive(Box::new(err.clone()));
|
||||||
Err(err)
|
Err(err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -499,7 +499,7 @@ impl Frame<'_> {
|
||||||
expected: SyntaxKind::Keyword(expected),
|
expected: SyntaxKind::Keyword(expected),
|
||||||
found: found.into_token(),
|
found: found.into_token(),
|
||||||
});
|
});
|
||||||
handler.receive(err.clone());
|
handler.receive(Box::new(err.clone()));
|
||||||
Err(err)
|
Err(err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -530,7 +530,7 @@ impl Frame<'_> {
|
||||||
expected: SyntaxKind::Punctuation(expected),
|
expected: SyntaxKind::Punctuation(expected),
|
||||||
found: found.into_token(),
|
found: found.into_token(),
|
||||||
});
|
});
|
||||||
handler.receive(err.clone());
|
handler.receive(Box::new(err.clone()));
|
||||||
Err(err)
|
Err(err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
//! Syntax tree nodes for declarations.
|
//! Syntax tree nodes for declarations.
|
||||||
|
|
||||||
#![allow(missing_docs)]
|
#![expect(missing_docs)]
|
||||||
|
#![expect(clippy::struct_field_names)]
|
||||||
|
|
||||||
use std::collections::VecDeque;
|
use std::collections::VecDeque;
|
||||||
|
|
||||||
|
@ -391,7 +392,7 @@ impl Parser<'_> {
|
||||||
|
|
||||||
declaration
|
declaration
|
||||||
.with_annotation(annotation)
|
.with_annotation(annotation)
|
||||||
.inspect_err(|err| handler.receive(err.clone()))
|
.inspect_err(|err| handler.receive(Box::new(err.clone())))
|
||||||
}
|
}
|
||||||
|
|
||||||
Reading::Atomic(Token::Keyword(from_keyword))
|
Reading::Atomic(Token::Keyword(from_keyword))
|
||||||
|
@ -441,7 +442,7 @@ impl Parser<'_> {
|
||||||
expected: SyntaxKind::Punctuation('*'),
|
expected: SyntaxKind::Punctuation('*'),
|
||||||
found: self.stop_at_significant().into_token(),
|
found: self.stop_at_significant().into_token(),
|
||||||
});
|
});
|
||||||
handler.receive(err.clone());
|
handler.receive(Box::new(err.clone()));
|
||||||
|
|
||||||
Err(err)
|
Err(err)
|
||||||
}
|
}
|
||||||
|
@ -511,7 +512,7 @@ impl Parser<'_> {
|
||||||
expected: SyntaxKind::Declaration,
|
expected: SyntaxKind::Declaration,
|
||||||
found: unexpected.into_token(),
|
found: unexpected.into_token(),
|
||||||
});
|
});
|
||||||
handler.receive(err.clone());
|
handler.receive(Box::new(err.clone()));
|
||||||
|
|
||||||
Err(err)
|
Err(err)
|
||||||
}
|
}
|
||||||
|
@ -562,7 +563,7 @@ impl Parser<'_> {
|
||||||
expected: SyntaxKind::Keyword(KeywordKind::Function),
|
expected: SyntaxKind::Keyword(KeywordKind::Function),
|
||||||
found: unexpected.into_token(),
|
found: unexpected.into_token(),
|
||||||
});
|
});
|
||||||
handler.receive(err.clone());
|
handler.receive(Box::new(err.clone()));
|
||||||
Err(err)
|
Err(err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -615,7 +616,7 @@ impl Parser<'_> {
|
||||||
]),
|
]),
|
||||||
found: unexpected.into_token(),
|
found: unexpected.into_token(),
|
||||||
});
|
});
|
||||||
handler.receive(err.clone());
|
handler.receive(Box::new(err.clone()));
|
||||||
Err(err)
|
Err(err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -666,7 +666,7 @@ impl Parser<'_> {
|
||||||
// eat the macro string literal
|
// eat the macro string literal
|
||||||
self.forward();
|
self.forward();
|
||||||
|
|
||||||
Ok(Primary::MacroStringLiteral(macro_string_literal))
|
Ok(Primary::MacroStringLiteral(*macro_string_literal))
|
||||||
}
|
}
|
||||||
|
|
||||||
// lua code expression
|
// lua code expression
|
||||||
|
@ -687,7 +687,7 @@ impl Parser<'_> {
|
||||||
expected: syntax::error::SyntaxKind::Identifier,
|
expected: syntax::error::SyntaxKind::Identifier,
|
||||||
found: unexpected.into_token(),
|
found: unexpected.into_token(),
|
||||||
});
|
});
|
||||||
handler.receive(err.clone());
|
handler.receive(Box::new(err.clone()));
|
||||||
Err(err)
|
Err(err)
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
@ -741,7 +741,7 @@ impl Parser<'_> {
|
||||||
expected: syntax::error::SyntaxKind::Expression,
|
expected: syntax::error::SyntaxKind::Expression,
|
||||||
found: unexpected.into_token(),
|
found: unexpected.into_token(),
|
||||||
});
|
});
|
||||||
handler.receive(err.clone());
|
handler.receive(Box::new(err.clone()));
|
||||||
|
|
||||||
Err(err)
|
Err(err)
|
||||||
}
|
}
|
||||||
|
@ -829,7 +829,7 @@ impl Parser<'_> {
|
||||||
expected: syntax::error::SyntaxKind::Operator,
|
expected: syntax::error::SyntaxKind::Operator,
|
||||||
found: Some(Token::Punctuation(punc)),
|
found: Some(Token::Punctuation(punc)),
|
||||||
});
|
});
|
||||||
handler.receive(err.clone());
|
handler.receive(Box::new(err.clone()));
|
||||||
Err(err)
|
Err(err)
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
@ -838,7 +838,7 @@ impl Parser<'_> {
|
||||||
expected: syntax::error::SyntaxKind::Operator,
|
expected: syntax::error::SyntaxKind::Operator,
|
||||||
found: unexpected.into_token(),
|
found: unexpected.into_token(),
|
||||||
});
|
});
|
||||||
handler.receive(err.clone());
|
handler.receive(Box::new(err.clone()));
|
||||||
Err(err)
|
Err(err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -388,7 +388,7 @@ impl Parser<'_> {
|
||||||
expected: SyntaxKind::Punctuation('#'),
|
expected: SyntaxKind::Punctuation('#'),
|
||||||
found: unexpected.into_token(),
|
found: unexpected.into_token(),
|
||||||
});
|
});
|
||||||
handler.receive(err.clone());
|
handler.receive(Box::new(err.clone()));
|
||||||
Err(err)
|
Err(err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -52,10 +52,10 @@ pub struct ProgramFile {
|
||||||
pub struct Namespace {
|
pub struct Namespace {
|
||||||
/// The `namespace` keyword.
|
/// The `namespace` keyword.
|
||||||
#[get = "pub"]
|
#[get = "pub"]
|
||||||
namespace_keyword: Keyword,
|
keyword: Keyword,
|
||||||
/// The name of the namespace.
|
/// The name of the namespace.
|
||||||
#[get = "pub"]
|
#[get = "pub"]
|
||||||
namespace_name: StringLiteral,
|
name: StringLiteral,
|
||||||
/// The semicolon.
|
/// The semicolon.
|
||||||
#[get = "pub"]
|
#[get = "pub"]
|
||||||
semicolon: Punctuation,
|
semicolon: Punctuation,
|
||||||
|
@ -63,7 +63,7 @@ pub struct Namespace {
|
||||||
|
|
||||||
impl SourceElement for Namespace {
|
impl SourceElement for Namespace {
|
||||||
fn span(&self) -> Span {
|
fn span(&self) -> Span {
|
||||||
self.namespace_keyword
|
self.keyword
|
||||||
.span()
|
.span()
|
||||||
.join(&self.semicolon.span())
|
.join(&self.semicolon.span())
|
||||||
.expect("Invalid span")
|
.expect("Invalid span")
|
||||||
|
@ -74,7 +74,7 @@ impl Namespace {
|
||||||
/// Dissolves the namespace into its components.
|
/// Dissolves the namespace into its components.
|
||||||
#[must_use]
|
#[must_use]
|
||||||
pub fn dissolve(self) -> (Keyword, StringLiteral, Punctuation) {
|
pub fn dissolve(self) -> (Keyword, StringLiteral, Punctuation) {
|
||||||
(self.namespace_keyword, self.namespace_name, self.semicolon)
|
(self.keyword, self.name, self.semicolon)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Validates a namespace string.
|
/// Validates a namespace string.
|
||||||
|
@ -112,19 +112,19 @@ impl Parser<'_> {
|
||||||
tracing::debug!("Parsing program");
|
tracing::debug!("Parsing program");
|
||||||
|
|
||||||
let namespace = match self.stop_at_significant() {
|
let namespace = match self.stop_at_significant() {
|
||||||
Reading::Atomic(Token::Keyword(namespace_keyword))
|
Reading::Atomic(Token::Keyword(keyword))
|
||||||
if namespace_keyword.keyword == KeywordKind::Namespace =>
|
if keyword.keyword == KeywordKind::Namespace =>
|
||||||
{
|
{
|
||||||
// eat the keyword
|
// eat the keyword
|
||||||
self.forward();
|
self.forward();
|
||||||
|
|
||||||
let namespace_name = self.parse_string_literal(handler)?;
|
let name = self.parse_string_literal(handler)?;
|
||||||
|
|
||||||
let semicolon = self.parse_punctuation(';', true, handler)?;
|
let semicolon = self.parse_punctuation(';', true, handler)?;
|
||||||
|
|
||||||
Ok(Namespace {
|
Ok(Namespace {
|
||||||
namespace_keyword,
|
keyword,
|
||||||
namespace_name,
|
name,
|
||||||
semicolon,
|
semicolon,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -133,14 +133,14 @@ impl Parser<'_> {
|
||||||
expected: SyntaxKind::Keyword(KeywordKind::Namespace),
|
expected: SyntaxKind::Keyword(KeywordKind::Namespace),
|
||||||
found: unexpected.into_token(),
|
found: unexpected.into_token(),
|
||||||
});
|
});
|
||||||
handler.receive(err.clone());
|
handler.receive(Box::new(err.clone()));
|
||||||
Err(err)
|
Err(err)
|
||||||
}
|
}
|
||||||
}?;
|
}?;
|
||||||
|
|
||||||
tracing::debug!(
|
tracing::debug!(
|
||||||
"Found namespace '{}', parsing declarations",
|
"Found namespace '{}', parsing declarations",
|
||||||
namespace.namespace_name.str_content()
|
namespace.name.str_content()
|
||||||
);
|
);
|
||||||
|
|
||||||
let mut declarations = Vec::new();
|
let mut declarations = Vec::new();
|
||||||
|
|
|
@ -798,7 +798,7 @@ pub enum AssignmentDestination {
|
||||||
/// Assignment to an identifier.
|
/// Assignment to an identifier.
|
||||||
Identifier(Identifier),
|
Identifier(Identifier),
|
||||||
/// Assignment to an indexed identifier.
|
/// Assignment to an indexed identifier.
|
||||||
Indexed(Identifier, Punctuation, Expression, Punctuation),
|
Indexed(Identifier, Punctuation, Box<Expression>, Punctuation),
|
||||||
}
|
}
|
||||||
|
|
||||||
impl SourceElement for AssignmentDestination {
|
impl SourceElement for AssignmentDestination {
|
||||||
|
@ -872,7 +872,7 @@ impl Parser<'_> {
|
||||||
|
|
||||||
statement
|
statement
|
||||||
.with_annotation(annotation)
|
.with_annotation(annotation)
|
||||||
.inspect_err(|err| handler.receive(err.clone()))
|
.inspect_err(|err| handler.receive(Box::new(err.clone())))
|
||||||
}
|
}
|
||||||
// variable declaration
|
// variable declaration
|
||||||
Reading::Atomic(Token::CommandLiteral(command)) => {
|
Reading::Atomic(Token::CommandLiteral(command)) => {
|
||||||
|
@ -971,7 +971,12 @@ impl Parser<'_> {
|
||||||
let close = tree.close;
|
let close = tree.close;
|
||||||
let expression = tree.tree?;
|
let expression = tree.tree?;
|
||||||
|
|
||||||
AssignmentDestination::Indexed(identifier, open, expression, close)
|
AssignmentDestination::Indexed(
|
||||||
|
identifier,
|
||||||
|
open,
|
||||||
|
Box::new(expression),
|
||||||
|
close,
|
||||||
|
)
|
||||||
}
|
}
|
||||||
_ => AssignmentDestination::Identifier(identifier),
|
_ => AssignmentDestination::Identifier(identifier),
|
||||||
}
|
}
|
||||||
|
@ -1036,7 +1041,7 @@ impl Parser<'_> {
|
||||||
]),
|
]),
|
||||||
found: unexpected.into_token(),
|
found: unexpected.into_token(),
|
||||||
});
|
});
|
||||||
handler.receive(err.clone());
|
handler.receive(Box::new(err.clone()));
|
||||||
return Err(err);
|
return Err(err);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -1076,7 +1081,7 @@ impl Parser<'_> {
|
||||||
expected: SyntaxKind::Integer,
|
expected: SyntaxKind::Integer,
|
||||||
found: unexpected.into_token(),
|
found: unexpected.into_token(),
|
||||||
});
|
});
|
||||||
handler.receive(err.clone());
|
handler.receive(Box::new(err.clone()));
|
||||||
return Err(err);
|
return Err(err);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
//! Execute block statement syntax tree.
|
//! Execute block statement syntax tree.
|
||||||
|
|
||||||
|
#![expect(clippy::struct_field_names)]
|
||||||
|
|
||||||
use derive_more::From;
|
use derive_more::From;
|
||||||
use enum_as_inner::EnumAsInner;
|
use enum_as_inner::EnumAsInner;
|
||||||
use getset::Getters;
|
use getset::Getters;
|
||||||
|
@ -824,7 +826,7 @@ impl Parser<'_> {
|
||||||
expected: SyntaxKind::Punctuation('('),
|
expected: SyntaxKind::Punctuation('('),
|
||||||
found: unexpected.into_token(),
|
found: unexpected.into_token(),
|
||||||
});
|
});
|
||||||
handler.receive(err.clone());
|
handler.receive(Box::new(err.clone()));
|
||||||
Err(err)
|
Err(err)
|
||||||
}
|
}
|
||||||
}?;
|
}?;
|
||||||
|
@ -842,7 +844,7 @@ impl Parser<'_> {
|
||||||
expected: SyntaxKind::ExecuteBlock,
|
expected: SyntaxKind::ExecuteBlock,
|
||||||
found: unexpected.into_token(),
|
found: unexpected.into_token(),
|
||||||
});
|
});
|
||||||
handler.receive(err.clone());
|
handler.receive(Box::new(err.clone()));
|
||||||
Err(err)
|
Err(err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -878,7 +880,7 @@ impl Parser<'_> {
|
||||||
expected: SyntaxKind::ExecuteBlockTail,
|
expected: SyntaxKind::ExecuteBlockTail,
|
||||||
found: unexpected.into_token(),
|
found: unexpected.into_token(),
|
||||||
});
|
});
|
||||||
handler.receive(err.clone());
|
handler.receive(Box::new(err.clone()));
|
||||||
Err(err)
|
Err(err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -104,6 +104,8 @@ impl MissingFunctionDeclaration {
|
||||||
|
|
||||||
impl Display for MissingFunctionDeclaration {
|
impl Display for MissingFunctionDeclaration {
|
||||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||||
|
use std::fmt::Write as _;
|
||||||
|
|
||||||
let message = format!(
|
let message = format!(
|
||||||
"no matching function declaration found for invocation of function `{}`",
|
"no matching function declaration found for invocation of function `{}`",
|
||||||
self.span.str()
|
self.span.str()
|
||||||
|
@ -118,7 +120,7 @@ impl Display for MissingFunctionDeclaration {
|
||||||
if i > 0 {
|
if i > 0 {
|
||||||
message.push_str(", ");
|
message.push_str(", ");
|
||||||
}
|
}
|
||||||
message.push_str(&format!("`{}`", alternative.identifier_span.str()));
|
let _ = write!(message, "`{}`", alternative.identifier_span.str());
|
||||||
}
|
}
|
||||||
Some(message + "?")
|
Some(message + "?")
|
||||||
};
|
};
|
||||||
|
|
|
@ -405,7 +405,7 @@ impl Primary {
|
||||||
Self::Lua(lua) => lua
|
Self::Lua(lua) => lua
|
||||||
.eval_comptime(scope, &VoidHandler)
|
.eval_comptime(scope, &VoidHandler)
|
||||||
.inspect_err(|err| {
|
.inspect_err(|err| {
|
||||||
handler.receive(err.clone());
|
handler.receive(Box::new(err.clone()));
|
||||||
})
|
})
|
||||||
.map_err(|_| NotComptime {
|
.map_err(|_| NotComptime {
|
||||||
expression: lua.span(),
|
expression: lua.span(),
|
||||||
|
@ -1191,7 +1191,7 @@ impl Transpiler {
|
||||||
.into(),
|
.into(),
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
handler.receive(err.clone());
|
handler.receive(Box::new(err.clone()));
|
||||||
Err(err)
|
Err(err)
|
||||||
} else {
|
} else {
|
||||||
let prepare_cmd = Command::Raw(format!("tag {entity} remove {tag_name}"));
|
let prepare_cmd = Command::Raw(format!("tag {entity} remove {tag_name}"));
|
||||||
|
@ -1234,7 +1234,7 @@ impl Transpiler {
|
||||||
index: member_access.member().span(),
|
index: member_access.member().span(),
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
handler.receive(err.clone());
|
handler.receive(Box::new(err.clone()));
|
||||||
Err(err)
|
Err(err)
|
||||||
},
|
},
|
||||||
|value| self.store_comptime_value(&value, target, member_access, handler),
|
|value| self.store_comptime_value(&value, target, member_access, handler),
|
||||||
|
@ -1248,7 +1248,7 @@ impl Transpiler {
|
||||||
let err = TranspileError::MissingValue(MissingValue {
|
let err = TranspileError::MissingValue(MissingValue {
|
||||||
expression: lua.span(),
|
expression: lua.span(),
|
||||||
});
|
});
|
||||||
handler.receive(err.clone());
|
handler.receive(Box::new(err.clone()));
|
||||||
Err(err)
|
Err(err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1273,7 +1273,7 @@ impl Transpiler {
|
||||||
expected_type: target.value_type().into(),
|
expected_type: target.value_type().into(),
|
||||||
expression: primary.span(),
|
expression: primary.span(),
|
||||||
});
|
});
|
||||||
handler.receive(err.clone());
|
handler.receive(Box::new(err.clone()));
|
||||||
Err(err)
|
Err(err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1337,7 +1337,7 @@ impl Transpiler {
|
||||||
expression: prefix.span(),
|
expression: prefix.span(),
|
||||||
expected_type: target.value_type().into(),
|
expected_type: target.value_type().into(),
|
||||||
});
|
});
|
||||||
handler.receive(err.clone());
|
handler.receive(Box::new(err.clone()));
|
||||||
Err(err)
|
Err(err)
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
@ -1433,7 +1433,7 @@ impl Transpiler {
|
||||||
expected_type: target.value_type().into(),
|
expected_type: target.value_type().into(),
|
||||||
expression: primary.span(),
|
expression: primary.span(),
|
||||||
});
|
});
|
||||||
handler.receive(err.clone());
|
handler.receive(Box::new(err.clone()));
|
||||||
Err(err)
|
Err(err)
|
||||||
}
|
}
|
||||||
}?;
|
}?;
|
||||||
|
@ -1443,7 +1443,7 @@ impl Transpiler {
|
||||||
let err = TranspileError::UnknownIdentifier(UnknownIdentifier {
|
let err = TranspileError::UnknownIdentifier(UnknownIdentifier {
|
||||||
identifier: ident.span.clone(),
|
identifier: ident.span.clone(),
|
||||||
});
|
});
|
||||||
handler.receive(err.clone());
|
handler.receive(Box::new(err.clone()));
|
||||||
Err(err)
|
Err(err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1455,7 +1455,7 @@ impl Transpiler {
|
||||||
reason: IllegalIndexingReason::NotIdentifier,
|
reason: IllegalIndexingReason::NotIdentifier,
|
||||||
expression: indexed.object().span(),
|
expression: indexed.object().span(),
|
||||||
});
|
});
|
||||||
handler.receive(err.clone());
|
handler.receive(Box::new(err.clone()));
|
||||||
Err(err)
|
Err(err)
|
||||||
}?;
|
}?;
|
||||||
let variable = scope.get_variable(ident.span.str());
|
let variable = scope.get_variable(ident.span.str());
|
||||||
|
@ -1477,7 +1477,7 @@ impl Transpiler {
|
||||||
},
|
},
|
||||||
expression: indexed.index().span(),
|
expression: indexed.index().span(),
|
||||||
});
|
});
|
||||||
handler.receive(err.clone());
|
handler.receive(Box::new(err.clone()));
|
||||||
Err(err)
|
Err(err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1502,7 +1502,7 @@ impl Transpiler {
|
||||||
},
|
},
|
||||||
expression: indexed.index().span(),
|
expression: indexed.index().span(),
|
||||||
});
|
});
|
||||||
handler.receive(err.clone());
|
handler.receive(Box::new(err.clone()));
|
||||||
Err(err)
|
Err(err)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@ -1512,7 +1512,7 @@ impl Transpiler {
|
||||||
},
|
},
|
||||||
expression: indexed.index().span(),
|
expression: indexed.index().span(),
|
||||||
});
|
});
|
||||||
handler.receive(err.clone());
|
handler.receive(Box::new(err.clone()));
|
||||||
Err(err)
|
Err(err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1541,7 +1541,7 @@ impl Transpiler {
|
||||||
},
|
},
|
||||||
expression: indexed.index().span(),
|
expression: indexed.index().span(),
|
||||||
});
|
});
|
||||||
handler.receive(err.clone());
|
handler.receive(Box::new(err.clone()));
|
||||||
Err(err)
|
Err(err)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@ -1551,7 +1551,7 @@ impl Transpiler {
|
||||||
},
|
},
|
||||||
expression: indexed.index().span(),
|
expression: indexed.index().span(),
|
||||||
});
|
});
|
||||||
handler.receive(err.clone());
|
handler.receive(Box::new(err.clone()));
|
||||||
Err(err)
|
Err(err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1560,7 +1560,7 @@ impl Transpiler {
|
||||||
expected_type: target.value_type().into(),
|
expected_type: target.value_type().into(),
|
||||||
expression: primary.span(),
|
expression: primary.span(),
|
||||||
});
|
});
|
||||||
handler.receive(err.clone());
|
handler.receive(Box::new(err.clone()));
|
||||||
Err(err)
|
Err(err)
|
||||||
}
|
}
|
||||||
}?;
|
}?;
|
||||||
|
@ -1570,7 +1570,7 @@ impl Transpiler {
|
||||||
let err = TranspileError::UnknownIdentifier(UnknownIdentifier {
|
let err = TranspileError::UnknownIdentifier(UnknownIdentifier {
|
||||||
identifier: ident.span.clone(),
|
identifier: ident.span.clone(),
|
||||||
});
|
});
|
||||||
handler.receive(err.clone());
|
handler.receive(Box::new(err.clone()));
|
||||||
Err(err)
|
Err(err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1647,7 +1647,7 @@ impl Transpiler {
|
||||||
expected_type: ExpectedType::Boolean,
|
expected_type: ExpectedType::Boolean,
|
||||||
expression: primary.span(),
|
expression: primary.span(),
|
||||||
});
|
});
|
||||||
handler.receive(err.clone());
|
handler.receive(Box::new(err.clone()));
|
||||||
Err(err)
|
Err(err)
|
||||||
}
|
}
|
||||||
Primary::StringLiteral(s) => Ok((
|
Primary::StringLiteral(s) => Ok((
|
||||||
|
@ -1670,7 +1670,7 @@ impl Transpiler {
|
||||||
message: "Function calls as conditions do not support arguments."
|
message: "Function calls as conditions do not support arguments."
|
||||||
.into(),
|
.into(),
|
||||||
});
|
});
|
||||||
handler.receive(err.clone());
|
handler.receive(Box::new(err.clone()));
|
||||||
Err(err)
|
Err(err)
|
||||||
} else {
|
} else {
|
||||||
let (func_location, _) = self.get_or_transpile_function(
|
let (func_location, _) = self.get_or_transpile_function(
|
||||||
|
@ -1713,7 +1713,7 @@ impl Transpiler {
|
||||||
expected_type: ExpectedType::Boolean,
|
expected_type: ExpectedType::Boolean,
|
||||||
expression: primary.span(),
|
expression: primary.span(),
|
||||||
});
|
});
|
||||||
handler.receive(err.clone());
|
handler.receive(Box::new(err.clone()));
|
||||||
Err(err)
|
Err(err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1721,7 +1721,7 @@ impl Transpiler {
|
||||||
let err = TranspileError::UnknownIdentifier(UnknownIdentifier {
|
let err = TranspileError::UnknownIdentifier(UnknownIdentifier {
|
||||||
identifier: ident.span.clone(),
|
identifier: ident.span.clone(),
|
||||||
});
|
});
|
||||||
handler.receive(err.clone());
|
handler.receive(Box::new(err.clone()));
|
||||||
Err(err)
|
Err(err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1736,7 +1736,7 @@ impl Transpiler {
|
||||||
reason: IllegalIndexingReason::NotIdentifier,
|
reason: IllegalIndexingReason::NotIdentifier,
|
||||||
expression: indexed.object().span(),
|
expression: indexed.object().span(),
|
||||||
});
|
});
|
||||||
handler.receive(err.clone());
|
handler.receive(Box::new(err.clone()));
|
||||||
Err(err)
|
Err(err)
|
||||||
}?;
|
}?;
|
||||||
#[expect(clippy::option_if_let_else)]
|
#[expect(clippy::option_if_let_else)]
|
||||||
|
@ -1770,7 +1770,7 @@ impl Transpiler {
|
||||||
},
|
},
|
||||||
expression: indexed.index().span(),
|
expression: indexed.index().span(),
|
||||||
});
|
});
|
||||||
handler.receive(err.clone());
|
handler.receive(Box::new(err.clone()));
|
||||||
Err(err)
|
Err(err)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@ -1780,7 +1780,7 @@ impl Transpiler {
|
||||||
},
|
},
|
||||||
expression: indexed.index().span(),
|
expression: indexed.index().span(),
|
||||||
});
|
});
|
||||||
handler.receive(err.clone());
|
handler.receive(Box::new(err.clone()));
|
||||||
Err(err)
|
Err(err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1789,7 +1789,7 @@ impl Transpiler {
|
||||||
expected_type: ExpectedType::Boolean,
|
expected_type: ExpectedType::Boolean,
|
||||||
expression: primary.span(),
|
expression: primary.span(),
|
||||||
});
|
});
|
||||||
handler.receive(err.clone());
|
handler.receive(Box::new(err.clone()));
|
||||||
Err(err)
|
Err(err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1797,7 +1797,7 @@ impl Transpiler {
|
||||||
let err = TranspileError::UnknownIdentifier(UnknownIdentifier {
|
let err = TranspileError::UnknownIdentifier(UnknownIdentifier {
|
||||||
identifier: ident.span.clone(),
|
identifier: ident.span.clone(),
|
||||||
});
|
});
|
||||||
handler.receive(err.clone());
|
handler.receive(Box::new(err.clone()));
|
||||||
Err(err)
|
Err(err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1814,7 +1814,7 @@ impl Transpiler {
|
||||||
index: member_access.member().span(),
|
index: member_access.member().span(),
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
handler.receive(err.clone());
|
handler.receive(Box::new(err.clone()));
|
||||||
Err(err)
|
Err(err)
|
||||||
},
|
},
|
||||||
|value| match value {
|
|value| match value {
|
||||||
|
@ -1826,7 +1826,7 @@ impl Transpiler {
|
||||||
expected_type: ExpectedType::Boolean,
|
expected_type: ExpectedType::Boolean,
|
||||||
expression: primary.span(),
|
expression: primary.span(),
|
||||||
});
|
});
|
||||||
handler.receive(err.clone());
|
handler.receive(Box::new(err.clone()));
|
||||||
Err(err)
|
Err(err)
|
||||||
}
|
}
|
||||||
ComptimeValue::String(s) => Ok((
|
ComptimeValue::String(s) => Ok((
|
||||||
|
@ -1882,7 +1882,7 @@ impl Transpiler {
|
||||||
expected_type: ExpectedType::Boolean,
|
expected_type: ExpectedType::Boolean,
|
||||||
expression: primary.span(),
|
expression: primary.span(),
|
||||||
});
|
});
|
||||||
handler.receive(err.clone());
|
handler.receive(Box::new(err.clone()));
|
||||||
Err(err)
|
Err(err)
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
@ -1903,7 +1903,7 @@ impl Transpiler {
|
||||||
expected_type: ExpectedType::Boolean,
|
expected_type: ExpectedType::Boolean,
|
||||||
expression: primary.span(),
|
expression: primary.span(),
|
||||||
});
|
});
|
||||||
handler.receive(err.clone());
|
handler.receive(Box::new(err.clone()));
|
||||||
Err(err)
|
Err(err)
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
@ -1933,7 +1933,7 @@ impl Transpiler {
|
||||||
expected_type: ExpectedType::Boolean,
|
expected_type: ExpectedType::Boolean,
|
||||||
expression: binary.span(),
|
expression: binary.span(),
|
||||||
});
|
});
|
||||||
handler.receive(err.clone());
|
handler.receive(Box::new(err.clone()));
|
||||||
Err(err)
|
Err(err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2022,7 +2022,7 @@ impl Transpiler {
|
||||||
expected_type: ExpectedType::Boolean,
|
expected_type: ExpectedType::Boolean,
|
||||||
expression: binary.span(),
|
expression: binary.span(),
|
||||||
});
|
});
|
||||||
handler.receive(err.clone());
|
handler.receive(Box::new(err.clone()));
|
||||||
return Err(err);
|
return Err(err);
|
||||||
}
|
}
|
||||||
DataLocation::Storage {
|
DataLocation::Storage {
|
||||||
|
@ -2049,7 +2049,7 @@ impl Transpiler {
|
||||||
expected_type: ExpectedType::Boolean,
|
expected_type: ExpectedType::Boolean,
|
||||||
expression: binary.span(),
|
expression: binary.span(),
|
||||||
});
|
});
|
||||||
handler.receive(err.clone());
|
handler.receive(Box::new(err.clone()));
|
||||||
return Err(err);
|
return Err(err);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
@ -2195,7 +2195,7 @@ impl Transpiler {
|
||||||
expected_type: ExpectedType::Boolean,
|
expected_type: ExpectedType::Boolean,
|
||||||
expression: source.span(),
|
expression: source.span(),
|
||||||
});
|
});
|
||||||
handler.receive(err.clone());
|
handler.receive(Box::new(err.clone()));
|
||||||
Err(err)
|
Err(err)
|
||||||
}
|
}
|
||||||
DataLocation::Storage {
|
DataLocation::Storage {
|
||||||
|
@ -2219,7 +2219,7 @@ impl Transpiler {
|
||||||
expression: source.span(),
|
expression: source.span(),
|
||||||
expected_type: target.value_type().into(),
|
expected_type: target.value_type().into(),
|
||||||
});
|
});
|
||||||
handler.receive(err.clone());
|
handler.receive(Box::new(err.clone()));
|
||||||
Err(err)
|
Err(err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2245,7 +2245,7 @@ impl Transpiler {
|
||||||
expression: source.span(),
|
expression: source.span(),
|
||||||
expected_type: target.value_type().into(),
|
expected_type: target.value_type().into(),
|
||||||
});
|
});
|
||||||
handler.receive(err.clone());
|
handler.receive(Box::new(err.clone()));
|
||||||
Err(err)
|
Err(err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2280,7 +2280,7 @@ impl Transpiler {
|
||||||
expected_type: target.value_type().into(),
|
expected_type: target.value_type().into(),
|
||||||
expression: source.span(),
|
expression: source.span(),
|
||||||
});
|
});
|
||||||
handler.receive(err.clone());
|
handler.receive(Box::new(err.clone()));
|
||||||
Err(err)
|
Err(err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2316,7 +2316,7 @@ impl Transpiler {
|
||||||
expected_type: ExpectedType::Boolean,
|
expected_type: ExpectedType::Boolean,
|
||||||
expression: source.span(),
|
expression: source.span(),
|
||||||
});
|
});
|
||||||
handler.receive(err.clone());
|
handler.receive(Box::new(err.clone()));
|
||||||
return Err(err);
|
return Err(err);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -59,11 +59,11 @@ impl Transpiler {
|
||||||
.expect("called variable should be of type function");
|
.expect("called variable should be of type function");
|
||||||
|
|
||||||
let function_data = function.ok_or_else(|| {
|
let function_data = function.ok_or_else(|| {
|
||||||
let error = TranspileError::MissingFunctionDeclaration(
|
let err = TranspileError::MissingFunctionDeclaration(
|
||||||
MissingFunctionDeclaration::from_scope(identifier_span.clone(), scope),
|
MissingFunctionDeclaration::from_scope(identifier_span.clone(), scope),
|
||||||
);
|
);
|
||||||
handler.receive(error.clone());
|
handler.receive(Box::new(err.clone()));
|
||||||
error
|
err
|
||||||
})?;
|
})?;
|
||||||
|
|
||||||
let VariableData::Function {
|
let VariableData::Function {
|
||||||
|
@ -99,7 +99,7 @@ impl Transpiler {
|
||||||
.to_string(),
|
.to_string(),
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
handler.receive(err.clone());
|
handler.receive(Box::new(err.clone()));
|
||||||
err
|
err
|
||||||
}),
|
}),
|
||||||
TranspileAnnotationValue::Map(_, span) => {
|
TranspileAnnotationValue::Map(_, span) => {
|
||||||
|
@ -108,7 +108,7 @@ impl Transpiler {
|
||||||
annotation: span.clone(),
|
annotation: span.clone(),
|
||||||
message: "Deobfuscate annotation cannot be a map.".to_string(),
|
message: "Deobfuscate annotation cannot be a map.".to_string(),
|
||||||
});
|
});
|
||||||
handler.receive(err.clone());
|
handler.receive(Box::new(err.clone()));
|
||||||
Err(err)
|
Err(err)
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
@ -175,7 +175,7 @@ impl Transpiler {
|
||||||
name: modified_name,
|
name: modified_name,
|
||||||
definition: identifier_span.clone(),
|
definition: identifier_span.clone(),
|
||||||
});
|
});
|
||||||
handler.receive(err.clone());
|
handler.receive(Box::new(err.clone()));
|
||||||
return Err(err);
|
return Err(err);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -193,11 +193,11 @@ impl Transpiler {
|
||||||
let function_location = function_path
|
let function_location = function_path
|
||||||
.get()
|
.get()
|
||||||
.ok_or_else(|| {
|
.ok_or_else(|| {
|
||||||
let error = TranspileError::MissingFunctionDeclaration(
|
let err = TranspileError::MissingFunctionDeclaration(
|
||||||
MissingFunctionDeclaration::from_scope(identifier_span.clone(), scope),
|
MissingFunctionDeclaration::from_scope(identifier_span.clone(), scope),
|
||||||
);
|
);
|
||||||
handler.receive(error.clone());
|
handler.receive(Box::new(err.clone()));
|
||||||
error
|
err
|
||||||
})
|
})
|
||||||
.map(String::to_owned)?;
|
.map(String::to_owned)?;
|
||||||
|
|
||||||
|
@ -258,7 +258,7 @@ impl Transpiler {
|
||||||
actual: arg_count,
|
actual: arg_count,
|
||||||
span: identifier_span.clone(),
|
span: identifier_span.clone(),
|
||||||
});
|
});
|
||||||
handler.receive(err.clone());
|
handler.receive(Box::new(err.clone()));
|
||||||
Err(err)
|
Err(err)
|
||||||
}
|
}
|
||||||
Some(arg_count) if arg_count > 0 => {
|
Some(arg_count) if arg_count > 0 => {
|
||||||
|
@ -283,7 +283,7 @@ impl Transpiler {
|
||||||
Ok(val) => Ok(Parameter::Static(val.to_macro_string())),
|
Ok(val) => Ok(Parameter::Static(val.to_macro_string())),
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
let err = TranspileError::NotComptime(err);
|
let err = TranspileError::NotComptime(err);
|
||||||
handler.receive(err.clone());
|
handler.receive(Box::new(err.clone()));
|
||||||
Err(err)
|
Err(err)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
@ -305,7 +305,7 @@ impl Transpiler {
|
||||||
let err = TranspileError::UnknownIdentifier(UnknownIdentifier {
|
let err = TranspileError::UnknownIdentifier(UnknownIdentifier {
|
||||||
identifier: ident.span(),
|
identifier: ident.span(),
|
||||||
});
|
});
|
||||||
handler.receive(err.clone());
|
handler.receive(Box::new(err.clone()));
|
||||||
err
|
err
|
||||||
})?;
|
})?;
|
||||||
match var.as_ref() {
|
match var.as_ref() {
|
||||||
|
@ -353,7 +353,7 @@ impl Transpiler {
|
||||||
ExpectedType::String,
|
ExpectedType::String,
|
||||||
]),
|
]),
|
||||||
});
|
});
|
||||||
handler.receive(err.clone());
|
handler.receive(Box::new(err.clone()));
|
||||||
Err(err)
|
Err(err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -132,7 +132,7 @@ fn print_function(
|
||||||
Ok((false, cmd, value))
|
Ok((false, cmd, value))
|
||||||
}
|
}
|
||||||
_ => Err(TranspileError::UnexpectedExpression(UnexpectedExpression(
|
_ => Err(TranspileError::UnexpectedExpression(UnexpectedExpression(
|
||||||
Expression::Primary(Primary::Identifier(ident.to_owned())),
|
Box::new(Expression::Primary(Primary::Identifier(ident.to_owned()))),
|
||||||
))),
|
))),
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -58,7 +58,7 @@ mod enabled {
|
||||||
};
|
};
|
||||||
|
|
||||||
self.add_globals(&lua, scope)
|
self.add_globals(&lua, scope)
|
||||||
.inspect_err(|err| handler.receive(err.clone()))?;
|
.inspect_err(|err| handler.receive(Box::new(err.clone())))?;
|
||||||
|
|
||||||
let res = lua
|
let res = lua
|
||||||
.load(self.code())
|
.load(self.code())
|
||||||
|
@ -67,7 +67,7 @@ mod enabled {
|
||||||
.map_err(|err| {
|
.map_err(|err| {
|
||||||
let err =
|
let err =
|
||||||
TranspileError::from(LuaRuntimeError::from_lua_err(&err, self.span()));
|
TranspileError::from(LuaRuntimeError::from_lua_err(&err, self.span()));
|
||||||
handler.receive(crate::Error::from(err.clone()));
|
handler.receive(crate::Error::from(Box::new(err.clone())));
|
||||||
err
|
err
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -329,7 +329,7 @@ mod enabled {
|
||||||
code_block: self.span(),
|
code_block: self.span(),
|
||||||
error_message: "return table must contain non-nil 'value'".to_string(),
|
error_message: "return table must contain non-nil 'value'".to_string(),
|
||||||
});
|
});
|
||||||
handler.receive(err.clone());
|
handler.receive(Box::new(err.clone()));
|
||||||
Err(err)
|
Err(err)
|
||||||
}
|
}
|
||||||
Ok(value) => {
|
Ok(value) => {
|
||||||
|
@ -348,7 +348,7 @@ mod enabled {
|
||||||
expression: self.span(),
|
expression: self.span(),
|
||||||
expected_type: ExpectedType::Boolean,
|
expected_type: ExpectedType::Boolean,
|
||||||
});
|
});
|
||||||
handler.receive(err.clone());
|
handler.receive(Box::new(err.clone()));
|
||||||
Err(err)
|
Err(err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -358,7 +358,7 @@ mod enabled {
|
||||||
expression: self.span(),
|
expression: self.span(),
|
||||||
expected_type: ExpectedType::Boolean,
|
expected_type: ExpectedType::Boolean,
|
||||||
});
|
});
|
||||||
handler.receive(err.clone());
|
handler.receive(Box::new(err.clone()));
|
||||||
Err(err)
|
Err(err)
|
||||||
}
|
}
|
||||||
}?;
|
}?;
|
||||||
|
@ -380,7 +380,7 @@ mod enabled {
|
||||||
&err,
|
&err,
|
||||||
self.span(),
|
self.span(),
|
||||||
));
|
));
|
||||||
handler.receive(err.clone());
|
handler.receive(Box::new(err.clone()));
|
||||||
Err(err)
|
Err(err)
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
@ -393,7 +393,7 @@ mod enabled {
|
||||||
code_block: self.span(),
|
code_block: self.span(),
|
||||||
error_message: format!("invalid return type {}", value.type_name()),
|
error_message: format!("invalid return type {}", value.type_name()),
|
||||||
});
|
});
|
||||||
handler.receive(err.clone());
|
handler.receive(Box::new(err.clone()));
|
||||||
Err(err)
|
Err(err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -196,13 +196,12 @@ impl Transpiler {
|
||||||
}
|
}
|
||||||
TranspileAnnotationValue::Expression(_, span)
|
TranspileAnnotationValue::Expression(_, span)
|
||||||
| TranspileAnnotationValue::Map(_, span) => {
|
| TranspileAnnotationValue::Map(_, span) => {
|
||||||
let error =
|
let err = TranspileError::IllegalAnnotationContent(IllegalAnnotationContent {
|
||||||
TranspileError::IllegalAnnotationContent(IllegalAnnotationContent {
|
annotation: span.clone(),
|
||||||
annotation: span.clone(),
|
message: "uninstall annotation must not have a value".to_string(),
|
||||||
message: "uninstall annotation must not have a value".to_string(),
|
});
|
||||||
});
|
handler.receive(Box::new(err.clone()));
|
||||||
handler.receive(error.clone());
|
Err(err)
|
||||||
Err(error)
|
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.collect::<TranspileResult<Vec<_>>>()?;
|
.collect::<TranspileResult<Vec<_>>>()?;
|
||||||
|
@ -273,7 +272,7 @@ impl Transpiler {
|
||||||
})
|
})
|
||||||
.collect();
|
.collect();
|
||||||
let function_data = FunctionData {
|
let function_data = FunctionData {
|
||||||
namespace: namespace.namespace_name().str_content().to_string(),
|
namespace: namespace.name().str_content().to_string(),
|
||||||
identifier_span: identifier_span.clone(),
|
identifier_span: identifier_span.clone(),
|
||||||
parameters: function
|
parameters: function
|
||||||
.parameters()
|
.parameters()
|
||||||
|
@ -318,9 +317,7 @@ impl Transpiler {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Declaration::Tag(tag) => {
|
Declaration::Tag(tag) => {
|
||||||
let namespace = self
|
let namespace = self.datapack.namespace_mut(namespace.name().str_content());
|
||||||
.datapack
|
|
||||||
.namespace_mut(namespace.namespace_name().str_content());
|
|
||||||
let sb_tag = namespace.tag_mut(tag.name().str_content(), tag.tag_type());
|
let sb_tag = namespace.tag_mut(tag.name().str_content(), tag.tag_type());
|
||||||
|
|
||||||
if let Some(list) = &tag.entries().list {
|
if let Some(list) = &tag.entries().list {
|
||||||
|
@ -344,7 +341,7 @@ impl Transpiler {
|
||||||
|
|
||||||
self.setup_cmds.extend(setup_variable_cmds);
|
self.setup_cmds.extend(setup_variable_cmds);
|
||||||
}
|
}
|
||||||
};
|
}
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
@ -415,11 +412,11 @@ impl Transpiler {
|
||||||
self.transpile_run_expression(prefix.operand(), scope, handler)
|
self.transpile_run_expression(prefix.operand(), scope, handler)
|
||||||
}
|
}
|
||||||
unexpected => {
|
unexpected => {
|
||||||
let error = TranspileError::UnexpectedExpression(UnexpectedExpression(
|
let err = TranspileError::UnexpectedExpression(UnexpectedExpression(
|
||||||
unexpected.clone(),
|
Box::new(unexpected.clone()),
|
||||||
));
|
));
|
||||||
handler.receive(error.clone());
|
handler.receive(Box::new(err.clone()));
|
||||||
Err(error)
|
Err(err)
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
SemicolonStatement::VariableDeclaration(decl) => self
|
SemicolonStatement::VariableDeclaration(decl) => self
|
||||||
|
@ -495,11 +492,11 @@ impl Transpiler {
|
||||||
read_only: _,
|
read_only: _,
|
||||||
} => value.read().unwrap().as_ref().map_or_else(
|
} => value.read().unwrap().as_ref().map_or_else(
|
||||||
|| {
|
|| {
|
||||||
let error = TranspileError::MissingValue(MissingValue {
|
let err = TranspileError::MissingValue(MissingValue {
|
||||||
expression: ident.span.clone(),
|
expression: ident.span.clone(),
|
||||||
});
|
});
|
||||||
handler.receive(error.clone());
|
handler.receive(Box::new(err.clone()));
|
||||||
Err(error)
|
Err(err)
|
||||||
},
|
},
|
||||||
|val| {
|
|val| {
|
||||||
let cmd = val.to_string_no_macro().map_or_else(
|
let cmd = val.to_string_no_macro().map_or_else(
|
||||||
|
@ -532,20 +529,21 @@ impl Transpiler {
|
||||||
)))),
|
)))),
|
||||||
),
|
),
|
||||||
_ => {
|
_ => {
|
||||||
let error =
|
let err = TranspileError::UnexpectedExpression(
|
||||||
TranspileError::UnexpectedExpression(UnexpectedExpression(
|
UnexpectedExpression(Box::new(Expression::Primary(
|
||||||
Expression::Primary(Primary::Identifier(ident.clone())),
|
Primary::Identifier(ident.clone()),
|
||||||
));
|
))),
|
||||||
handler.receive(error.clone());
|
);
|
||||||
return Err(error);
|
handler.receive(Box::new(err.clone()));
|
||||||
|
return Err(err);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
let error = TranspileError::UnknownIdentifier(UnknownIdentifier {
|
let err = TranspileError::UnknownIdentifier(UnknownIdentifier {
|
||||||
identifier: ident.span.clone(),
|
identifier: ident.span.clone(),
|
||||||
});
|
});
|
||||||
handler.receive(error.clone());
|
handler.receive(Box::new(err.clone()));
|
||||||
return Err(error);
|
return Err(err);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
_ => {
|
_ => {
|
||||||
|
@ -590,11 +588,11 @@ impl Transpiler {
|
||||||
read_only: _,
|
read_only: _,
|
||||||
}) => value.read().unwrap().as_ref().map_or_else(
|
}) => value.read().unwrap().as_ref().map_or_else(
|
||||||
|| {
|
|| {
|
||||||
let error = TranspileError::MissingValue(MissingValue {
|
let err = TranspileError::MissingValue(MissingValue {
|
||||||
expression: ident.span.clone(),
|
expression: ident.span.clone(),
|
||||||
});
|
});
|
||||||
handler.receive(error.clone());
|
handler.receive(Box::new(err.clone()));
|
||||||
Err(error)
|
Err(err)
|
||||||
},
|
},
|
||||||
|val| {
|
|val| {
|
||||||
let cmd = val.to_string_no_macro().map_or_else(
|
let cmd = val.to_string_no_macro().map_or_else(
|
||||||
|
@ -605,18 +603,18 @@ impl Transpiler {
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
Some(_) => {
|
Some(_) => {
|
||||||
let error = TranspileError::UnexpectedExpression(UnexpectedExpression(
|
let err = TranspileError::UnexpectedExpression(UnexpectedExpression(Box::new(
|
||||||
Expression::Primary(expression.clone()),
|
Expression::Primary(expression.clone()),
|
||||||
));
|
)));
|
||||||
handler.receive(error.clone());
|
handler.receive(Box::new(err.clone()));
|
||||||
Err(error)
|
Err(err)
|
||||||
}
|
}
|
||||||
None => {
|
None => {
|
||||||
let error = TranspileError::UnknownIdentifier(UnknownIdentifier {
|
let err = TranspileError::UnknownIdentifier(UnknownIdentifier {
|
||||||
identifier: ident.span.clone(),
|
identifier: ident.span.clone(),
|
||||||
});
|
});
|
||||||
handler.receive(error.clone());
|
handler.receive(Box::new(err.clone()));
|
||||||
Err(error)
|
Err(err)
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -625,11 +623,11 @@ impl Transpiler {
|
||||||
| Primary::Prefix(_)
|
| Primary::Prefix(_)
|
||||||
| Primary::Indexed(_)
|
| Primary::Indexed(_)
|
||||||
| Primary::MemberAccess(_) => {
|
| Primary::MemberAccess(_) => {
|
||||||
let error = TranspileError::UnexpectedExpression(UnexpectedExpression(
|
let err = TranspileError::UnexpectedExpression(UnexpectedExpression(Box::new(
|
||||||
Expression::Primary(expression.clone()),
|
Expression::Primary(expression.clone()),
|
||||||
));
|
)));
|
||||||
handler.receive(error.clone());
|
handler.receive(Box::new(err.clone()));
|
||||||
Err(error)
|
Err(err)
|
||||||
}
|
}
|
||||||
Primary::StringLiteral(string) => {
|
Primary::StringLiteral(string) => {
|
||||||
Ok(vec![Command::Raw(string.str_content().to_string())])
|
Ok(vec![Command::Raw(string.str_content().to_string())])
|
||||||
|
@ -643,14 +641,14 @@ impl Transpiler {
|
||||||
expected_type: ExpectedType::String,
|
expected_type: ExpectedType::String,
|
||||||
expression: code.span(),
|
expression: code.span(),
|
||||||
});
|
});
|
||||||
handler.receive(err.clone());
|
handler.receive(Box::new(err.clone()));
|
||||||
Err(err)
|
Err(err)
|
||||||
}
|
}
|
||||||
Err(_) => {
|
Err(_) => {
|
||||||
let err = TranspileError::MissingValue(MissingValue {
|
let err = TranspileError::MissingValue(MissingValue {
|
||||||
expression: code.span(),
|
expression: code.span(),
|
||||||
});
|
});
|
||||||
handler.receive(err.clone());
|
handler.receive(Box::new(err.clone()));
|
||||||
Err(err)
|
Err(err)
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
@ -667,12 +665,12 @@ impl Transpiler {
|
||||||
expression: bin.span(),
|
expression: bin.span(),
|
||||||
expected_type: ExpectedType::String,
|
expected_type: ExpectedType::String,
|
||||||
});
|
});
|
||||||
handler.receive(err.clone());
|
handler.receive(Box::new(err.clone()));
|
||||||
Err(err)
|
Err(err)
|
||||||
}
|
}
|
||||||
Err(not_comptime) => {
|
Err(not_comptime) => {
|
||||||
let err = TranspileError::NotComptime(not_comptime);
|
let err = TranspileError::NotComptime(not_comptime);
|
||||||
handler.receive(err.clone());
|
handler.receive(Box::new(err.clone()));
|
||||||
Err(err)
|
Err(err)
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
@ -694,7 +692,7 @@ impl Transpiler {
|
||||||
scope.get_variable(func.identifier().span.str()).as_deref()
|
scope.get_variable(func.identifier().span.str()).as_deref()
|
||||||
{
|
{
|
||||||
implementation(self, scope, func).inspect_err(|err| {
|
implementation(self, scope, func).inspect_err(|err| {
|
||||||
handler.receive(err.clone());
|
handler.receive(Box::new(err.clone()));
|
||||||
})
|
})
|
||||||
} else {
|
} else {
|
||||||
let (location, arguments) = self.get_or_transpile_function(
|
let (location, arguments) = self.get_or_transpile_function(
|
||||||
|
|
|
@ -60,7 +60,7 @@ impl MacroString {
|
||||||
///
|
///
|
||||||
/// # Errors
|
/// # Errors
|
||||||
/// - If the macro string contains macros
|
/// - If the macro string contains macros
|
||||||
pub fn as_str(&self) -> Result<std::borrow::Cow<str>, &[MacroStringPart]> {
|
pub fn as_str(&self) -> Result<std::borrow::Cow<'_, str>, &[MacroStringPart]> {
|
||||||
match self {
|
match self {
|
||||||
Self::String(s) => Ok(std::borrow::Cow::Borrowed(s)),
|
Self::String(s) => Ok(std::borrow::Cow::Borrowed(s)),
|
||||||
Self::MacroString(parts) if self.contains_macros() => Err(parts),
|
Self::MacroString(parts) if self.contains_macros() => Err(parts),
|
||||||
|
|
|
@ -308,7 +308,7 @@ impl Transpiler {
|
||||||
.comptime_eval(scope, handler)
|
.comptime_eval(scope, handler)
|
||||||
.map_err(|err| {
|
.map_err(|err| {
|
||||||
let err = TranspileError::NotComptime(err);
|
let err = TranspileError::NotComptime(err);
|
||||||
handler.receive(err.clone());
|
handler.receive(Box::new(err.clone()));
|
||||||
err
|
err
|
||||||
})?,
|
})?,
|
||||||
)
|
)
|
||||||
|
@ -569,7 +569,7 @@ impl Transpiler {
|
||||||
},
|
},
|
||||||
expression: expression.span(),
|
expression: expression.span(),
|
||||||
});
|
});
|
||||||
handler.receive(err.clone());
|
handler.receive(Box::new(err.clone()));
|
||||||
return Err(err);
|
return Err(err);
|
||||||
}
|
}
|
||||||
Some(_) => {
|
Some(_) => {
|
||||||
|
@ -579,7 +579,7 @@ impl Transpiler {
|
||||||
expected: ExpectedType::String,
|
expected: ExpectedType::String,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
handler.receive(err.clone());
|
handler.receive(Box::new(err.clone()));
|
||||||
return Err(err);
|
return Err(err);
|
||||||
}
|
}
|
||||||
None => {
|
None => {
|
||||||
|
@ -588,7 +588,7 @@ impl Transpiler {
|
||||||
identifier: identifier.span(),
|
identifier: identifier.span(),
|
||||||
message: "Cannot assign to a scoreboard without indexing".to_string(),
|
message: "Cannot assign to a scoreboard without indexing".to_string(),
|
||||||
});
|
});
|
||||||
handler.receive(err.clone());
|
handler.receive(Box::new(err.clone()));
|
||||||
return Err(err);
|
return Err(err);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
@ -617,7 +617,7 @@ impl Transpiler {
|
||||||
length: targets.len(),
|
length: targets.len(),
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
handler.receive(err.clone());
|
handler.receive(Box::new(err.clone()));
|
||||||
return Err(err);
|
return Err(err);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -628,7 +628,7 @@ impl Transpiler {
|
||||||
expected: ExpectedType::Integer,
|
expected: ExpectedType::Integer,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
handler.receive(err.clone());
|
handler.receive(Box::new(err.clone()));
|
||||||
return Err(err);
|
return Err(err);
|
||||||
}
|
}
|
||||||
None => {
|
None => {
|
||||||
|
@ -637,7 +637,7 @@ impl Transpiler {
|
||||||
identifier: identifier.span(),
|
identifier: identifier.span(),
|
||||||
message: "Cannot assign to an array without indexing".to_string(),
|
message: "Cannot assign to an array without indexing".to_string(),
|
||||||
});
|
});
|
||||||
handler.receive(err.clone());
|
handler.receive(Box::new(err.clone()));
|
||||||
return Err(err);
|
return Err(err);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -671,7 +671,7 @@ impl Transpiler {
|
||||||
length: paths.len(),
|
length: paths.len(),
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
handler.receive(err.clone());
|
handler.receive(Box::new(err.clone()));
|
||||||
return Err(err);
|
return Err(err);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -682,7 +682,7 @@ impl Transpiler {
|
||||||
expected: ExpectedType::Integer,
|
expected: ExpectedType::Integer,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
handler.receive(err.clone());
|
handler.receive(Box::new(err.clone()));
|
||||||
return Err(err);
|
return Err(err);
|
||||||
}
|
}
|
||||||
None => {
|
None => {
|
||||||
|
@ -691,7 +691,7 @@ impl Transpiler {
|
||||||
identifier: identifier.span(),
|
identifier: identifier.span(),
|
||||||
message: "Cannot assign to an array without indexing".to_string(),
|
message: "Cannot assign to an array without indexing".to_string(),
|
||||||
});
|
});
|
||||||
handler.receive(err.clone());
|
handler.receive(Box::new(err.clone()));
|
||||||
return Err(err);
|
return Err(err);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -709,7 +709,7 @@ impl Transpiler {
|
||||||
expected: ExpectedType::String,
|
expected: ExpectedType::String,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
handler.receive(err.clone());
|
handler.receive(Box::new(err.clone()));
|
||||||
return Err(err);
|
return Err(err);
|
||||||
}
|
}
|
||||||
Some(_) => {
|
Some(_) => {
|
||||||
|
@ -719,7 +719,7 @@ impl Transpiler {
|
||||||
expected: ExpectedType::String,
|
expected: ExpectedType::String,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
handler.receive(err.clone());
|
handler.receive(Box::new(err.clone()));
|
||||||
return Err(err);
|
return Err(err);
|
||||||
}
|
}
|
||||||
None => {
|
None => {
|
||||||
|
@ -728,7 +728,7 @@ impl Transpiler {
|
||||||
identifier: identifier.span(),
|
identifier: identifier.span(),
|
||||||
message: "Cannot assign to a tag without indexing".to_string(),
|
message: "Cannot assign to a tag without indexing".to_string(),
|
||||||
});
|
});
|
||||||
handler.receive(err.clone());
|
handler.receive(Box::new(err.clone()));
|
||||||
return Err(err);
|
return Err(err);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
@ -738,13 +738,13 @@ impl Transpiler {
|
||||||
identifier: identifier.span(),
|
identifier: identifier.span(),
|
||||||
message: "Cannot assign to a read-only value.".to_string(),
|
message: "Cannot assign to a read-only value.".to_string(),
|
||||||
});
|
});
|
||||||
handler.receive(err.clone());
|
handler.receive(Box::new(err.clone()));
|
||||||
return Err(err);
|
return Err(err);
|
||||||
}
|
}
|
||||||
let comptime_value =
|
let comptime_value =
|
||||||
expression.comptime_eval(scope, handler).map_err(|err| {
|
expression.comptime_eval(scope, handler).map_err(|err| {
|
||||||
let err = TranspileError::NotComptime(err);
|
let err = TranspileError::NotComptime(err);
|
||||||
handler.receive(err.clone());
|
handler.receive(Box::new(err.clone()));
|
||||||
err
|
err
|
||||||
})?;
|
})?;
|
||||||
*value.write().unwrap() = Some(comptime_value);
|
*value.write().unwrap() = Some(comptime_value);
|
||||||
|
@ -765,7 +765,7 @@ impl Transpiler {
|
||||||
}
|
}
|
||||||
),
|
),
|
||||||
});
|
});
|
||||||
handler.receive(err.clone());
|
handler.receive(Box::new(err.clone()));
|
||||||
Err(err)
|
Err(err)
|
||||||
}
|
}
|
||||||
}?;
|
}?;
|
||||||
|
@ -775,7 +775,7 @@ impl Transpiler {
|
||||||
identifier: identifier.span(),
|
identifier: identifier.span(),
|
||||||
message: "Variable does not exist.".to_string(),
|
message: "Variable does not exist.".to_string(),
|
||||||
});
|
});
|
||||||
handler.receive(err.clone());
|
handler.receive(Box::new(err.clone()));
|
||||||
Err(err)
|
Err(err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -796,12 +796,12 @@ impl Transpiler {
|
||||||
let deobfuscate_annotation = deobfuscate_annotations.next();
|
let deobfuscate_annotation = deobfuscate_annotations.next();
|
||||||
|
|
||||||
if let Some(duplicate) = deobfuscate_annotations.next() {
|
if let Some(duplicate) = deobfuscate_annotations.next() {
|
||||||
let error = TranspileError::IllegalAnnotationContent(IllegalAnnotationContent {
|
let err = TranspileError::IllegalAnnotationContent(IllegalAnnotationContent {
|
||||||
annotation: duplicate.span(),
|
annotation: duplicate.span(),
|
||||||
message: "Multiple deobfuscate annotations are not allowed.".to_string(),
|
message: "Multiple deobfuscate annotations are not allowed.".to_string(),
|
||||||
});
|
});
|
||||||
handler.receive(error.clone());
|
handler.receive(Box::new(err.clone()));
|
||||||
return Err(error);
|
return Err(err);
|
||||||
}
|
}
|
||||||
if let Some(deobfuscate_annotation) = deobfuscate_annotation {
|
if let Some(deobfuscate_annotation) = deobfuscate_annotation {
|
||||||
let deobfuscate_annotation_value = TranspileAnnotationValue::from_annotation_value(
|
let deobfuscate_annotation_value = TranspileAnnotationValue::from_annotation_value(
|
||||||
|
@ -818,33 +818,32 @@ impl Transpiler {
|
||||||
{
|
{
|
||||||
// TODO: change invalid criteria if boolean
|
// TODO: change invalid criteria if boolean
|
||||||
if !crate::util::is_valid_scoreboard_objective_name(&name_eval) {
|
if !crate::util::is_valid_scoreboard_objective_name(&name_eval) {
|
||||||
let error = TranspileError::IllegalAnnotationContent(IllegalAnnotationContent {
|
let err = TranspileError::IllegalAnnotationContent(IllegalAnnotationContent {
|
||||||
annotation: deobfuscate_annotation.span(),
|
annotation: deobfuscate_annotation.span(),
|
||||||
message: "Deobfuscate annotation must be a valid scoreboard objective name.".to_string()
|
message: "Deobfuscate annotation must be a valid scoreboard objective name.".to_string()
|
||||||
});
|
});
|
||||||
handler.receive(error.clone());
|
handler.receive(Box::new(err.clone()));
|
||||||
return Err(error);
|
return Err(err);
|
||||||
}
|
}
|
||||||
Ok(name_eval)
|
Ok(name_eval)
|
||||||
} else {
|
} else {
|
||||||
let error = TranspileError::IllegalAnnotationContent(IllegalAnnotationContent {
|
let err = TranspileError::IllegalAnnotationContent(IllegalAnnotationContent {
|
||||||
annotation: deobfuscate_annotation.span(),
|
annotation: deobfuscate_annotation.span(),
|
||||||
message: "Deobfuscate annotation could not have been evaluated at compile time.".to_string()
|
message: "Deobfuscate annotation could not have been evaluated at compile time.".to_string()
|
||||||
});
|
});
|
||||||
handler.receive(error.clone());
|
handler.receive(Box::new(err.clone()));
|
||||||
Err(error)
|
Err(err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
TranspileAnnotationValue::None(_) => Ok(identifier.span.str().to_string()),
|
TranspileAnnotationValue::None(_) => Ok(identifier.span.str().to_string()),
|
||||||
TranspileAnnotationValue::Map(_, _) => {
|
TranspileAnnotationValue::Map(_, _) => {
|
||||||
let error =
|
let err = TranspileError::IllegalAnnotationContent(IllegalAnnotationContent {
|
||||||
TranspileError::IllegalAnnotationContent(IllegalAnnotationContent {
|
annotation: deobfuscate_annotation.span(),
|
||||||
annotation: deobfuscate_annotation.span(),
|
message: "Deobfuscate annotation must have no value or must be string."
|
||||||
message: "Deobfuscate annotation must have no value or must be string."
|
.to_string(),
|
||||||
.to_string(),
|
});
|
||||||
});
|
handler.receive(Box::new(err.clone()));
|
||||||
handler.receive(error.clone());
|
Err(err)
|
||||||
Err(error)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@ -881,12 +880,12 @@ impl Transpiler {
|
||||||
let deobfuscate_annotation = deobfuscate_annotations.next();
|
let deobfuscate_annotation = deobfuscate_annotations.next();
|
||||||
|
|
||||||
if let Some(duplicate) = deobfuscate_annotations.next() {
|
if let Some(duplicate) = deobfuscate_annotations.next() {
|
||||||
let error = TranspileError::IllegalAnnotationContent(IllegalAnnotationContent {
|
let err = TranspileError::IllegalAnnotationContent(IllegalAnnotationContent {
|
||||||
annotation: duplicate.span(),
|
annotation: duplicate.span(),
|
||||||
message: "Multiple deobfuscate annotations are not allowed.".to_string(),
|
message: "Multiple deobfuscate annotations are not allowed.".to_string(),
|
||||||
});
|
});
|
||||||
handler.receive(error.clone());
|
handler.receive(Box::new(err.clone()));
|
||||||
return Err(error);
|
return Err(err);
|
||||||
}
|
}
|
||||||
if let Some(deobfuscate_annotation) = deobfuscate_annotation {
|
if let Some(deobfuscate_annotation) = deobfuscate_annotation {
|
||||||
let deobfuscate_annotation_value = TranspileAnnotationValue::from_annotation_value(
|
let deobfuscate_annotation_value = TranspileAnnotationValue::from_annotation_value(
|
||||||
|
@ -896,14 +895,13 @@ impl Transpiler {
|
||||||
|
|
||||||
if let TranspileAnnotationValue::Map(map, _) = deobfuscate_annotation_value {
|
if let TranspileAnnotationValue::Map(map, _) = deobfuscate_annotation_value {
|
||||||
if map.len() > 2 {
|
if map.len() > 2 {
|
||||||
let error =
|
let err = TranspileError::IllegalAnnotationContent(IllegalAnnotationContent {
|
||||||
TranspileError::IllegalAnnotationContent(IllegalAnnotationContent {
|
annotation: deobfuscate_annotation.span(),
|
||||||
annotation: deobfuscate_annotation.span(),
|
message: "Deobfuscate annotation must have at most 2 key-value pairs."
|
||||||
message: "Deobfuscate annotation must have at most 2 key-value pairs."
|
.to_string(),
|
||||||
.to_string(),
|
});
|
||||||
});
|
handler.receive(Box::new(err.clone()));
|
||||||
handler.receive(error.clone());
|
return Err(err);
|
||||||
return Err(error);
|
|
||||||
}
|
}
|
||||||
if let (Some(name), Some(target)) = (map.get("name"), map.get("target")) {
|
if let (Some(name), Some(target)) = (map.get("name"), map.get("target")) {
|
||||||
if let (
|
if let (
|
||||||
|
@ -923,56 +921,54 @@ impl Transpiler {
|
||||||
) {
|
) {
|
||||||
// TODO: change invalid criteria if boolean
|
// TODO: change invalid criteria if boolean
|
||||||
if !crate::util::is_valid_scoreboard_objective_name(&name_eval) {
|
if !crate::util::is_valid_scoreboard_objective_name(&name_eval) {
|
||||||
let error = TranspileError::IllegalAnnotationContent(IllegalAnnotationContent {
|
let err = TranspileError::IllegalAnnotationContent(IllegalAnnotationContent {
|
||||||
annotation: deobfuscate_annotation.span(),
|
annotation: deobfuscate_annotation.span(),
|
||||||
message: "Deobfuscate annotation 'name' must be a valid scoreboard objective name.".to_string()
|
message: "Deobfuscate annotation 'name' must be a valid scoreboard objective name.".to_string()
|
||||||
});
|
});
|
||||||
handler.receive(error.clone());
|
handler.receive(Box::new(err.clone()));
|
||||||
return Err(error);
|
return Err(err);
|
||||||
}
|
}
|
||||||
if !crate::util::is_valid_scoreboard_target(&target_eval) {
|
if !crate::util::is_valid_scoreboard_target(&target_eval) {
|
||||||
let error = TranspileError::IllegalAnnotationContent(IllegalAnnotationContent {
|
let err = TranspileError::IllegalAnnotationContent(IllegalAnnotationContent {
|
||||||
annotation: deobfuscate_annotation.span(),
|
annotation: deobfuscate_annotation.span(),
|
||||||
message: "Deobfuscate annotation 'target' must be a valid scoreboard player name.".to_string()
|
message: "Deobfuscate annotation 'target' must be a valid scoreboard player name.".to_string()
|
||||||
});
|
});
|
||||||
handler.receive(error.clone());
|
handler.receive(Box::new(err.clone()));
|
||||||
return Err(error);
|
return Err(err);
|
||||||
}
|
}
|
||||||
Ok((name_eval, target_eval))
|
Ok((name_eval, target_eval))
|
||||||
} else {
|
} else {
|
||||||
let error = TranspileError::IllegalAnnotationContent(IllegalAnnotationContent {
|
let err = TranspileError::IllegalAnnotationContent(IllegalAnnotationContent {
|
||||||
annotation: deobfuscate_annotation.span(),
|
annotation: deobfuscate_annotation.span(),
|
||||||
message: "Deobfuscate annotation 'name' or 'target' could not have been evaluated at compile time.".to_string()
|
message: "Deobfuscate annotation 'name' or 'target' could not have been evaluated at compile time.".to_string()
|
||||||
});
|
});
|
||||||
handler.receive(error.clone());
|
handler.receive(Box::new(err.clone()));
|
||||||
Err(error)
|
Err(err)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
let error = TranspileError::IllegalAnnotationContent(IllegalAnnotationContent {
|
let err = TranspileError::IllegalAnnotationContent(IllegalAnnotationContent {
|
||||||
annotation: deobfuscate_annotation.span(),
|
annotation: deobfuscate_annotation.span(),
|
||||||
message: "Deobfuscate annotation 'name' and 'target' must be compile time expressions.".to_string()
|
message: "Deobfuscate annotation 'name' and 'target' must be compile time expressions.".to_string()
|
||||||
});
|
});
|
||||||
handler.receive(error.clone());
|
handler.receive(Box::new(err.clone()));
|
||||||
Err(error)
|
Err(err)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
let error =
|
let err = TranspileError::IllegalAnnotationContent(IllegalAnnotationContent {
|
||||||
TranspileError::IllegalAnnotationContent(IllegalAnnotationContent {
|
annotation: deobfuscate_annotation.span(),
|
||||||
annotation: deobfuscate_annotation.span(),
|
message: "Deobfuscate annotation must have both 'name' and 'target' keys."
|
||||||
message:
|
.to_string(),
|
||||||
"Deobfuscate annotation must have both 'name' and 'target' keys."
|
});
|
||||||
.to_string(),
|
handler.receive(Box::new(err.clone()));
|
||||||
});
|
Err(err)
|
||||||
handler.receive(error.clone());
|
|
||||||
Err(error)
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
let error = TranspileError::IllegalAnnotationContent(IllegalAnnotationContent {
|
let err = TranspileError::IllegalAnnotationContent(IllegalAnnotationContent {
|
||||||
annotation: deobfuscate_annotation.span(),
|
annotation: deobfuscate_annotation.span(),
|
||||||
message: "Deobfuscate annotation must be a map.".to_string(),
|
message: "Deobfuscate annotation must be a map.".to_string(),
|
||||||
});
|
});
|
||||||
handler.receive(error.clone());
|
handler.receive(Box::new(err.clone()));
|
||||||
Err(error)
|
Err(err)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
let hashed = md5::hash(program_identifier).to_hex_lowercase();
|
let hashed = md5::hash(program_identifier).to_hex_lowercase();
|
||||||
|
@ -1017,12 +1013,12 @@ impl Transpiler {
|
||||||
let deobfuscate_annotation = deobfuscate_annotations.next();
|
let deobfuscate_annotation = deobfuscate_annotations.next();
|
||||||
|
|
||||||
if let Some(duplicate) = deobfuscate_annotations.next() {
|
if let Some(duplicate) = deobfuscate_annotations.next() {
|
||||||
let error = TranspileError::IllegalAnnotationContent(IllegalAnnotationContent {
|
let err = TranspileError::IllegalAnnotationContent(IllegalAnnotationContent {
|
||||||
annotation: duplicate.span(),
|
annotation: duplicate.span(),
|
||||||
message: "Multiple deobfuscate annotations are not allowed.".to_string(),
|
message: "Multiple deobfuscate annotations are not allowed.".to_string(),
|
||||||
});
|
});
|
||||||
handler.receive(error.clone());
|
handler.receive(Box::new(err.clone()));
|
||||||
return Err(error);
|
return Err(err);
|
||||||
}
|
}
|
||||||
if let Some(deobfuscate_annotation) = deobfuscate_annotation {
|
if let Some(deobfuscate_annotation) = deobfuscate_annotation {
|
||||||
let deobfuscate_annotation_value = TranspileAnnotationValue::from_annotation_value(
|
let deobfuscate_annotation_value = TranspileAnnotationValue::from_annotation_value(
|
||||||
|
@ -1048,24 +1044,21 @@ impl Transpiler {
|
||||||
}
|
}
|
||||||
TranspileAnnotationValue::Map(map, _) => {
|
TranspileAnnotationValue::Map(map, _) => {
|
||||||
// TODO: implement when map deobfuscate annotation is implemented
|
// TODO: implement when map deobfuscate annotation is implemented
|
||||||
let error =
|
let err = TranspileError::IllegalAnnotationContent(IllegalAnnotationContent {
|
||||||
TranspileError::IllegalAnnotationContent(IllegalAnnotationContent {
|
annotation: deobfuscate_annotation.span(),
|
||||||
annotation: deobfuscate_annotation.span(),
|
message: "Deobfuscate annotation value must be a string or none."
|
||||||
message: "Deobfuscate annotation value must be a string or none."
|
.to_string(),
|
||||||
.to_string(),
|
});
|
||||||
});
|
handler.receive(Box::new(err.clone()));
|
||||||
handler.receive(error.clone());
|
Err(err)
|
||||||
Err(error)
|
|
||||||
}
|
}
|
||||||
TranspileAnnotationValue::Expression(_, _) => {
|
TranspileAnnotationValue::Expression(_, _) => {
|
||||||
let error =
|
let err = TranspileError::IllegalAnnotationContent(IllegalAnnotationContent {
|
||||||
TranspileError::IllegalAnnotationContent(IllegalAnnotationContent {
|
annotation: deobfuscate_annotation.span(),
|
||||||
annotation: deobfuscate_annotation.span(),
|
message: "Deobfuscate annotation value must be a map or none.".to_string(),
|
||||||
message: "Deobfuscate annotation value must be a map or none."
|
});
|
||||||
.to_string(),
|
handler.receive(Box::new(err.clone()));
|
||||||
});
|
Err(err)
|
||||||
handler.receive(error.clone());
|
|
||||||
Err(error)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@ -1168,7 +1161,7 @@ impl Transpiler {
|
||||||
expression: expression.span(),
|
expression: expression.span(),
|
||||||
expected_type: to.value_type().into(),
|
expected_type: to.value_type().into(),
|
||||||
});
|
});
|
||||||
handler.receive(err.clone());
|
handler.receive(Box::new(err.clone()));
|
||||||
Err(err)
|
Err(err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1219,7 +1212,7 @@ impl Transpiler {
|
||||||
expression: expression.span(),
|
expression: expression.span(),
|
||||||
expected_type: to.value_type().into(),
|
expected_type: to.value_type().into(),
|
||||||
});
|
});
|
||||||
handler.receive(err.clone());
|
handler.receive(Box::new(err.clone()));
|
||||||
Err(err)
|
Err(err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1228,7 +1221,7 @@ impl Transpiler {
|
||||||
expected_type: ExpectedType::Boolean,
|
expected_type: ExpectedType::Boolean,
|
||||||
expression: expression.span(),
|
expression: expression.span(),
|
||||||
});
|
});
|
||||||
handler.receive(err.clone());
|
handler.receive(Box::new(err.clone()));
|
||||||
Err(err)
|
Err(err)
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
@ -1237,7 +1230,7 @@ impl Transpiler {
|
||||||
expected_type: to.value_type().into(),
|
expected_type: to.value_type().into(),
|
||||||
expression: expression.span(),
|
expression: expression.span(),
|
||||||
});
|
});
|
||||||
handler.receive(err.clone());
|
handler.receive(Box::new(err.clone()));
|
||||||
Err(err)
|
Err(err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,7 +4,7 @@ use std::borrow::Cow;
|
||||||
|
|
||||||
/// Escapes `"` and `\` in a string.
|
/// Escapes `"` and `\` in a string.
|
||||||
#[must_use]
|
#[must_use]
|
||||||
pub fn escape_str(s: &str) -> Cow<str> {
|
pub fn escape_str(s: &str) -> Cow<'_, str> {
|
||||||
if s.contains('"') || s.contains('\\') {
|
if s.contains('"') || s.contains('\\') {
|
||||||
let mut escaped = String::with_capacity(s.len());
|
let mut escaped = String::with_capacity(s.len());
|
||||||
for c in s.chars() {
|
for c in s.chars() {
|
||||||
|
@ -22,7 +22,7 @@ pub fn escape_str(s: &str) -> Cow<str> {
|
||||||
|
|
||||||
/// Unescapes '\`', `\`, `\n`, `\r` and `\t` in a string.
|
/// Unescapes '\`', `\`, `\n`, `\r` and `\t` in a string.
|
||||||
#[must_use]
|
#[must_use]
|
||||||
pub fn unescape_macro_string(s: &str) -> Cow<str> {
|
pub fn unescape_macro_string(s: &str) -> Cow<'_, str> {
|
||||||
if s.contains('\\') || s.contains('`') {
|
if s.contains('\\') || s.contains('`') {
|
||||||
Cow::Owned(
|
Cow::Owned(
|
||||||
s.replace("\\n", "\n")
|
s.replace("\\n", "\n")
|
||||||
|
@ -39,7 +39,7 @@ pub fn unescape_macro_string(s: &str) -> Cow<str> {
|
||||||
/// Transforms an identifier to a macro name that only contains `a-zA-Z0-9_`.
|
/// Transforms an identifier to a macro name that only contains `a-zA-Z0-9_`.
|
||||||
#[cfg(feature = "shulkerbox")]
|
#[cfg(feature = "shulkerbox")]
|
||||||
#[must_use]
|
#[must_use]
|
||||||
pub fn identifier_to_macro(ident: &str) -> std::borrow::Cow<str> {
|
pub fn identifier_to_macro(ident: &str) -> std::borrow::Cow<'_, str> {
|
||||||
if ident.contains("__")
|
if ident.contains("__")
|
||||||
|| ident
|
|| ident
|
||||||
.chars()
|
.chars()
|
||||||
|
@ -82,7 +82,7 @@ pub fn identifier_to_macro(ident: &str) -> std::borrow::Cow<str> {
|
||||||
/// Transforms an identifier to a macro name that only contains `a-zA-Z0-9_`.
|
/// Transforms an identifier to a macro name that only contains `a-zA-Z0-9_`.
|
||||||
#[cfg(feature = "shulkerbox")]
|
#[cfg(feature = "shulkerbox")]
|
||||||
#[must_use]
|
#[must_use]
|
||||||
pub fn identifier_to_scoreboard_target(ident: &str) -> std::borrow::Cow<str> {
|
pub fn identifier_to_scoreboard_target(ident: &str) -> std::borrow::Cow<'_, str> {
|
||||||
if !(..=16).contains(&ident.len())
|
if !(..=16).contains(&ident.len())
|
||||||
|| ident
|
|| ident
|
||||||
.chars()
|
.chars()
|
||||||
|
|
|
@ -20,10 +20,7 @@ fn parsing_test1() {
|
||||||
)
|
)
|
||||||
.expect("Failed to parse");
|
.expect("Failed to parse");
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(parsed.namespace().name().str_content(), "parsing-test");
|
||||||
parsed.namespace().namespace_name().str_content(),
|
|
||||||
"parsing-test"
|
|
||||||
);
|
|
||||||
|
|
||||||
let declarations = parsed.declarations();
|
let declarations = parsed.declarations();
|
||||||
assert_eq!(declarations.len(), 1);
|
assert_eq!(declarations.len(), 1);
|
||||||
|
|
Loading…
Reference in New Issue