Get read_line built-in working
This commit is contained in:
parent
dd5136827c
commit
3a97ba76a0
@ -117,7 +117,11 @@ impl Error {
|
|||||||
collection_type,
|
collection_type,
|
||||||
index_type,
|
index_type,
|
||||||
position,
|
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::InterpreterExpectedReturn => todo!(),
|
||||||
ValidationError::ExpectedFunction { .. } => todo!(),
|
ValidationError::ExpectedFunction { .. } => todo!(),
|
||||||
ValidationError::ExpectedValue => todo!(),
|
ValidationError::ExpectedValue => todo!(),
|
||||||
|
@ -191,26 +191,8 @@ pub fn parser<'src>() -> DustParser<'src> {
|
|||||||
.with_position(state.span())
|
.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((
|
let atom = choice((
|
||||||
function_call.clone(),
|
function.clone(),
|
||||||
identifier_expression.clone(),
|
identifier_expression.clone(),
|
||||||
basic_value.clone(),
|
basic_value.clone(),
|
||||||
list.clone(),
|
list.clone(),
|
||||||
@ -223,7 +205,7 @@ pub fn parser<'src>() -> DustParser<'src> {
|
|||||||
|
|
||||||
use Operator::*;
|
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| {
|
prefix(2, just(Token::Operator(Not)), |_, expression, span| {
|
||||||
Expression::Logic(Box::new(Logic::Not(expression))).with_position(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::SquareOpen)),
|
||||||
just(Token::Control(Control::SquareClose)),
|
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| {
|
|op, expression, span| {
|
||||||
Expression::ListIndex(Box::new(ListIndex::new(op, expression)))
|
Expression::FunctionCall(FunctionCall::new(op, expression))
|
||||||
.with_position(span)
|
.with_position(span)
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
infix(
|
infix(
|
||||||
left(3),
|
left(4),
|
||||||
just(Token::Control(Control::Dot)),
|
just(Token::Control(Control::Dot)),
|
||||||
|left, _, right, span| {
|
|left, _, right, span| {
|
||||||
Expression::MapIndex(Box::new(MapIndex::new(left, right)))
|
Expression::MapIndex(Box::new(MapIndex::new(left, right)))
|
||||||
@ -344,9 +341,8 @@ pub fn parser<'src>() -> DustParser<'src> {
|
|||||||
|
|
||||||
choice((
|
choice((
|
||||||
range,
|
range,
|
||||||
logic_math_and_indexes,
|
logic_math_indexes_and_function_calls,
|
||||||
function,
|
function,
|
||||||
function_call,
|
|
||||||
list,
|
list,
|
||||||
map,
|
map,
|
||||||
basic_value,
|
basic_value,
|
||||||
|
12
src/value.rs
12
src/value.rs
@ -90,7 +90,17 @@ impl Value {
|
|||||||
ValueInner::Map(_) => Type::Map,
|
ValueInner::Map(_) => Type::Map,
|
||||||
ValueInner::Range(_) => Type::Range,
|
ValueInner::Range(_) => Type::Range,
|
||||||
ValueInner::String(_) => Type::String,
|
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(),
|
||||||
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user