1
0

Get read_line built-in working

This commit is contained in:
Jeff 2024-03-17 21:42:53 -04:00
parent dd5136827c
commit 3a97ba76a0
3 changed files with 36 additions and 26 deletions

View File

@ -117,7 +117,11 @@ impl Error {
collection_type,
index_type,
position,
} => todo!(),
} => builder.add_label(Label::new(position.0..position.1).with_message(format!(
"Cannot index into a {} with a {}.",
collection_type.fg(type_color),
index_type.fg(type_color)
))),
ValidationError::InterpreterExpectedReturn => todo!(),
ValidationError::ExpectedFunction { .. } => todo!(),
ValidationError::ExpectedValue => todo!(),

View File

@ -191,26 +191,8 @@ pub fn parser<'src>() -> DustParser<'src> {
.with_position(state.span())
});
let function_expression = choice((identifier_expression.clone(), function.clone()));
let function_call = function_expression
.then(
positioned_expression
.clone()
.separated_by(just(Token::Control(Control::Comma)))
.collect()
.delimited_by(
just(Token::Control(Control::ParenOpen)),
just(Token::Control(Control::ParenClose)),
),
)
.map_with(|(function, arguments), state| {
Expression::FunctionCall(FunctionCall::new(function, arguments))
.with_position(state.span())
});
let atom = choice((
function_call.clone(),
function.clone(),
identifier_expression.clone(),
basic_value.clone(),
list.clone(),
@ -223,7 +205,7 @@ pub fn parser<'src>() -> DustParser<'src> {
use Operator::*;
let logic_math_and_indexes = atom.pratt((
let logic_math_indexes_and_function_calls = atom.pratt((
prefix(2, just(Token::Operator(Not)), |_, expression, span| {
Expression::Logic(Box::new(Logic::Not(expression))).with_position(span)
}),
@ -233,13 +215,28 @@ pub fn parser<'src>() -> DustParser<'src> {
just(Token::Control(Control::SquareOpen)),
just(Token::Control(Control::SquareClose)),
),
|left, right, span| {
Expression::ListIndex(Box::new(ListIndex::new(left, right)))
.with_position(span)
},
),
postfix(
3,
positioned_expression
.clone()
.separated_by(just(Token::Control(Control::Comma)))
.collect()
.delimited_by(
just(Token::Control(Control::ParenOpen)),
just(Token::Control(Control::ParenClose)),
),
|op, expression, span| {
Expression::ListIndex(Box::new(ListIndex::new(op, expression)))
Expression::FunctionCall(FunctionCall::new(op, expression))
.with_position(span)
},
),
infix(
left(3),
left(4),
just(Token::Control(Control::Dot)),
|left, _, right, span| {
Expression::MapIndex(Box::new(MapIndex::new(left, right)))
@ -344,9 +341,8 @@ pub fn parser<'src>() -> DustParser<'src> {
choice((
range,
logic_math_and_indexes,
logic_math_indexes_and_function_calls,
function,
function_call,
list,
map,
basic_value,

View File

@ -90,7 +90,17 @@ impl Value {
ValueInner::Map(_) => Type::Map,
ValueInner::Range(_) => Type::Range,
ValueInner::String(_) => Type::String,
ValueInner::Function(_) => todo!(),
ValueInner::Function(function) => match function {
Function::Parsed(parsed_function) => Type::Function {
parameter_types: parsed_function
.parameters
.iter()
.map(|(_, r#type)| r#type.node.clone())
.collect(),
return_type: Box::new(parsed_function.return_type.node.clone()),
},
Function::BuiltIn(built_in_function) => built_in_function.r#type(),
},
}
}