fix string parsing
This commit is contained in:
parent
baf8b57804
commit
4937c176bb
3 changed files with 38 additions and 21 deletions
|
@ -23,7 +23,7 @@ fn import_directive_to_symbol_vec(
|
|||
match import {
|
||||
pest::ImportDirective::Main(import) => {
|
||||
let span = import.span;
|
||||
let source = Path::new(import.source.span.as_str());
|
||||
let source = Path::new(import.source.raw.span.as_str());
|
||||
let id = "main";
|
||||
let alias = import.alias.map(|a| a.span.as_str());
|
||||
|
||||
|
@ -41,7 +41,7 @@ fn import_directive_to_symbol_vec(
|
|||
}
|
||||
pest::ImportDirective::From(import) => {
|
||||
let span = import.span;
|
||||
let source = Path::new(import.source.span.as_str());
|
||||
let source = Path::new(import.source.raw.span.as_str());
|
||||
import
|
||||
.symbols
|
||||
.into_iter()
|
||||
|
@ -251,7 +251,7 @@ impl<'ast> From<pest::LogStatement<'ast>> for untyped::StatementNode<'ast> {
|
|||
.map(untyped::ExpressionNode::from)
|
||||
.collect();
|
||||
|
||||
untyped::Statement::Log(statement.format_string.span.as_str(), expressions)
|
||||
untyped::Statement::Log(statement.format_string.raw.span.as_str(), expressions)
|
||||
.span(statement.span)
|
||||
}
|
||||
}
|
||||
|
@ -321,7 +321,7 @@ impl<'ast> From<pest::AssertionStatement<'ast>> for untyped::StatementNode<'ast>
|
|||
|
||||
untyped::Statement::Assertion(
|
||||
untyped::ExpressionNode::from(statement.expression),
|
||||
statement.message.map(|m| m.value),
|
||||
statement.message.map(|m| m.raw.value),
|
||||
)
|
||||
.span(statement.span)
|
||||
}
|
||||
|
|
|
@ -2,9 +2,9 @@ file = { SOI ~ pragma? ~ symbol_declaration* ~ EOI }
|
|||
|
||||
pragma = { "#pragma" ~ "curve" ~ curve }
|
||||
curve = @{ (ASCII_ALPHANUMERIC | "_") * }
|
||||
string = @{(!"\"" ~ ANY)*}
|
||||
raw_string = @{(!"\"" ~ ANY)*}
|
||||
quoted_string = ${ "\"" ~ raw_string ~ "\"" }
|
||||
semicolon = _{";"}
|
||||
quoted_string = _{ "\"" ~ string ~ "\"" }
|
||||
|
||||
symbol_declaration = { (((import_directive | const_definition | type_definition) ~ semicolon) | (ty_struct_definition | function_definition)) }
|
||||
|
||||
|
|
|
@ -211,7 +211,7 @@ mod ast {
|
|||
#[derive(Debug, FromPest, PartialEq, Eq, Clone)]
|
||||
#[pest_ast(rule(Rule::main_import_directive))]
|
||||
pub struct MainImportDirective<'ast> {
|
||||
pub source: AnyString<'ast>,
|
||||
pub source: QString<'ast>,
|
||||
pub alias: Option<IdentifierExpression<'ast>>,
|
||||
#[pest_ast(outer())]
|
||||
pub span: Span<'ast>,
|
||||
|
@ -229,7 +229,7 @@ mod ast {
|
|||
#[derive(Debug, FromPest, PartialEq, Eq, Clone)]
|
||||
#[pest_ast(rule(Rule::from_import_directive))]
|
||||
pub struct FromImportDirective<'ast> {
|
||||
pub source: AnyString<'ast>,
|
||||
pub source: QString<'ast>,
|
||||
pub symbols: Vec<ImportSymbol<'ast>>,
|
||||
#[pest_ast(outer())]
|
||||
pub span: Span<'ast>,
|
||||
|
@ -371,7 +371,7 @@ mod ast {
|
|||
#[derive(Debug, FromPest, PartialEq, Clone)]
|
||||
#[pest_ast(rule(Rule::log_statement))]
|
||||
pub struct LogStatement<'ast> {
|
||||
pub format_string: AnyString<'ast>,
|
||||
pub format_string: QString<'ast>,
|
||||
pub expressions: Vec<Expression<'ast>>,
|
||||
#[pest_ast(outer())]
|
||||
pub span: Span<'ast>,
|
||||
|
@ -387,19 +387,27 @@ mod ast {
|
|||
}
|
||||
|
||||
#[derive(Debug, FromPest, PartialEq, Eq, Clone)]
|
||||
#[pest_ast(rule(Rule::string))]
|
||||
pub struct AnyString<'ast> {
|
||||
#[pest_ast(rule(Rule::raw_string))]
|
||||
pub struct RawString<'ast> {
|
||||
#[pest_ast(outer(with(span_into_str)))]
|
||||
pub value: String,
|
||||
#[pest_ast(outer())]
|
||||
pub span: Span<'ast>,
|
||||
}
|
||||
|
||||
#[derive(Debug, FromPest, PartialEq, Eq, Clone)]
|
||||
#[pest_ast(rule(Rule::quoted_string))]
|
||||
pub struct QString<'ast> {
|
||||
pub raw: RawString<'ast>,
|
||||
#[pest_ast(outer())]
|
||||
pub span: Span<'ast>,
|
||||
}
|
||||
|
||||
#[derive(Debug, FromPest, PartialEq, Clone)]
|
||||
#[pest_ast(rule(Rule::assertion_statement))]
|
||||
pub struct AssertionStatement<'ast> {
|
||||
pub expression: Expression<'ast>,
|
||||
pub message: Option<AnyString<'ast>>,
|
||||
pub message: Option<QString<'ast>>,
|
||||
#[pest_ast(outer())]
|
||||
pub span: Span<'ast>,
|
||||
}
|
||||
|
@ -1178,9 +1186,12 @@ mod tests {
|
|||
pragma: None,
|
||||
declarations: vec![
|
||||
SymbolDeclaration::Import(ImportDirective::Main(MainImportDirective {
|
||||
source: AnyString {
|
||||
value: String::from("foo"),
|
||||
span: Span::new(source, 17, 20).unwrap()
|
||||
source: QString {
|
||||
raw: RawString {
|
||||
value: String::from("foo"),
|
||||
span: Span::new(source, 17, 20).unwrap()
|
||||
},
|
||||
span: Span::new(source, 16, 21).unwrap()
|
||||
},
|
||||
alias: None,
|
||||
span: Span::new(source, 9, 21).unwrap()
|
||||
|
@ -1243,9 +1254,12 @@ mod tests {
|
|||
pragma: None,
|
||||
declarations: vec![
|
||||
SymbolDeclaration::Import(ImportDirective::Main(MainImportDirective {
|
||||
source: AnyString {
|
||||
value: String::from("foo"),
|
||||
span: Span::new(source, 17, 20).unwrap()
|
||||
source: QString {
|
||||
raw: RawString {
|
||||
value: String::from("foo"),
|
||||
span: Span::new(source, 17, 20).unwrap()
|
||||
},
|
||||
span: Span::new(source, 16, 21).unwrap()
|
||||
},
|
||||
alias: None,
|
||||
span: Span::new(source, 9, 21).unwrap()
|
||||
|
@ -1332,9 +1346,12 @@ mod tests {
|
|||
pragma: None,
|
||||
declarations: vec![
|
||||
SymbolDeclaration::Import(ImportDirective::Main(MainImportDirective {
|
||||
source: AnyString {
|
||||
value: String::from("foo"),
|
||||
span: Span::new(source, 17, 20).unwrap()
|
||||
source: QString {
|
||||
raw: RawString {
|
||||
value: String::from("foo"),
|
||||
span: Span::new(source, 17, 20).unwrap()
|
||||
},
|
||||
span: Span::new(source, 16, 21).unwrap()
|
||||
},
|
||||
alias: None,
|
||||
span: Span::new(source, 9, 21).unwrap()
|
||||
|
|
Loading…
Reference in a new issue