fix: properly lex new token and adjust parsed spans
This commit is contained in:
parent
e647330433
commit
a88a193383
|
@ -235,14 +235,14 @@ pub fn type_alias_parser() -> impl Parser<Token, ast::UntypedDefinition, Error =
|
|||
|
||||
pub fn validator_parser() -> impl Parser<Token, ast::UntypedDefinition, Error = ParseError> {
|
||||
just(Token::Validator)
|
||||
.ignore_then(select! {Token::Name {name} => name})
|
||||
.ignore_then(select! {Token::Name {name} => name}.map_with_span(|name, span| (name, span)))
|
||||
.then(
|
||||
fn_param_parser()
|
||||
.separated_by(just(Token::Comma))
|
||||
.allow_trailing()
|
||||
.delimited_by(just(Token::LeftParen), just(Token::RightParen))
|
||||
.or_not()
|
||||
.map_with_span(|arguments, span| (arguments.unwrap_or_default(), span)),
|
||||
.map_with_span(|arguments, span| (arguments, span))
|
||||
.or_not(),
|
||||
)
|
||||
.then(
|
||||
just(Token::Fn)
|
||||
|
@ -284,8 +284,10 @@ pub fn validator_parser() -> impl Parser<Token, ast::UntypedDefinition, Error =
|
|||
)
|
||||
.delimited_by(just(Token::LeftBrace), just(Token::RightBrace)),
|
||||
)
|
||||
.map_with_span(|((name, (params, params_span)), mut fun), span| {
|
||||
fun.name = name;
|
||||
.map_with_span(|((name, opt_extra_params), mut fun), span| {
|
||||
fun.name = name.0;
|
||||
|
||||
let (params, params_span) = opt_extra_params.unwrap_or((vec![], name.1));
|
||||
|
||||
ast::UntypedDefinition::Validator(ast::Validator {
|
||||
doc: None,
|
||||
|
|
|
@ -102,6 +102,7 @@ pub fn lexer() -> impl Parser<char, Vec<(Token, Span)>, Error = ParseError> {
|
|||
"todo" => Token::Todo,
|
||||
"type" => Token::Type,
|
||||
"when" => Token::When,
|
||||
"validator" => Token::Validator,
|
||||
_ => {
|
||||
if s.chars().next().map_or(false, |c| c.is_uppercase()) {
|
||||
Token::UpName {
|
||||
|
|
|
@ -50,12 +50,56 @@ fn validator() {
|
|||
|
||||
assert_definitions(
|
||||
code,
|
||||
vec![ast::UntypedDefinition::Use(Use {
|
||||
location: Span::new((), 0..12),
|
||||
module: vec!["std".to_string(), "list".to_string()],
|
||||
as_name: None,
|
||||
unqualified: vec![],
|
||||
package: (),
|
||||
vec![ast::UntypedDefinition::Validator(ast::Validator {
|
||||
doc: None,
|
||||
end_position: 54,
|
||||
fun: Function {
|
||||
arguments: vec![
|
||||
ast::Arg {
|
||||
arg_name: ast::ArgName::Named {
|
||||
name: "datum".to_string(),
|
||||
label: "datum".to_string(),
|
||||
location: Span::new((), 21..26),
|
||||
},
|
||||
location: Span::new((), 21..26),
|
||||
annotation: None,
|
||||
tipo: (),
|
||||
},
|
||||
ast::Arg {
|
||||
arg_name: ast::ArgName::Named {
|
||||
name: "rdmr".to_string(),
|
||||
label: "rdmr".to_string(),
|
||||
location: Span::new((), 28..32),
|
||||
},
|
||||
location: Span::new((), 28..32),
|
||||
annotation: None,
|
||||
tipo: (),
|
||||
},
|
||||
ast::Arg {
|
||||
arg_name: ast::ArgName::Named {
|
||||
name: "ctx".to_string(),
|
||||
label: "ctx".to_string(),
|
||||
location: Span::new((), 34..37),
|
||||
},
|
||||
location: Span::new((), 34..37),
|
||||
annotation: None,
|
||||
tipo: (),
|
||||
},
|
||||
],
|
||||
body: expr::UntypedExpr::Var {
|
||||
location: Span::new((), 45..49),
|
||||
name: "True".to_string(),
|
||||
},
|
||||
doc: None,
|
||||
location: Span::new((), 18..38),
|
||||
name: "foo".to_string(),
|
||||
public: false,
|
||||
return_annotation: None,
|
||||
return_type: (),
|
||||
end_position: 52,
|
||||
},
|
||||
location: Span::new((), 0..13),
|
||||
params: vec![],
|
||||
})],
|
||||
)
|
||||
}
|
||||
|
|
|
@ -12,11 +12,14 @@ type Redeemer {
|
|||
msg: ByteArray,
|
||||
}
|
||||
|
||||
fn spend(datum: Datum, redeemer: Redeemer, context: ScriptContext) -> Bool {
|
||||
validator spend {
|
||||
fn(datum: Datum, redeemer: Redeemer, context: ScriptContext) -> Bool {
|
||||
let must_say_hello = string.from_bytearray(redeemer.msg) == "Hello, World!"
|
||||
|
||||
let must_be_signed =
|
||||
list.has(context.transaction.extra_signatories, datum.owner)
|
||||
|
||||
must_say_hello && must_be_signed
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue