Symbol quoting and user defined incoming MIDI message processing
This commit is contained in:
parent
387835a155
commit
ed3b2006e9
@ -609,6 +609,23 @@ error:
|
|||||||
unreachable();
|
unreachable();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
global.force_define("incoming", +[](Interpreter &i, std::vector<Value> args) -> Result<Value> {
|
||||||
|
assert(args.size() == 2, "Wrong arity of 'incoming' function");
|
||||||
|
assert(args[0].type == Value::Type::Symbol, "Expected symbol for first argument of 'incoming'");
|
||||||
|
assert(is_callable(args[1].type), "Expected function for second argument of 'incoming'");
|
||||||
|
|
||||||
|
std::string const& symbol = args[0].s;
|
||||||
|
|
||||||
|
if (symbol == "note_on" || symbol == "noteon") {
|
||||||
|
i.callbacks->note_on = std::move(args[1]);
|
||||||
|
} else if (symbol == "note_off" || symbol == "noteoff") {
|
||||||
|
i.callbacks->note_off = std::move(args[1]);
|
||||||
|
} else {
|
||||||
|
assert(false, "symbol not recognized for 'incoming'");
|
||||||
|
}
|
||||||
|
return Value{};
|
||||||
|
});
|
||||||
|
|
||||||
{
|
{
|
||||||
constexpr auto pgmchange = +[](Interpreter &i, std::vector<Value> args) -> Result<Value> {
|
constexpr auto pgmchange = +[](Interpreter &i, std::vector<Value> args) -> Result<Value> {
|
||||||
using Program = Shape<Value::Type::Number>;
|
using Program = Shape<Value::Type::Number>;
|
||||||
@ -668,6 +685,10 @@ Result<Value> Interpreter::eval(Ast &&ast)
|
|||||||
switch (ast.token.type) {
|
switch (ast.token.type) {
|
||||||
case Token::Type::Symbol:
|
case Token::Type::Symbol:
|
||||||
{
|
{
|
||||||
|
if (ast.token.source.starts_with('\'')) {
|
||||||
|
return Value::from(std::move(ast.token.source).substr(1));
|
||||||
|
}
|
||||||
|
|
||||||
auto const value = env->find(std::string(ast.token.source));
|
auto const value = env->find(std::string(ast.token.source));
|
||||||
assert(value, "Missing variable error is not implemented yet: variable: "s + std::string(ast.token.source));
|
assert(value, "Missing variable error is not implemented yet: variable: "s + std::string(ast.token.source));
|
||||||
return *value;
|
return *value;
|
||||||
|
@ -100,6 +100,11 @@ bool unicode::is_space(u32 space)
|
|||||||
|
|
||||||
bool unicode::is_identifier(u32 letter, unicode::First_Character is_first_character)
|
bool unicode::is_identifier(u32 letter, unicode::First_Character is_first_character)
|
||||||
{
|
{
|
||||||
return (unicode::is_letter(letter) || letter == '_' || letter == '#' || letter == '$' || letter == '@')
|
return (unicode::is_letter(letter)
|
||||||
|| (!bool(is_first_character) && (letter == '\'' || unicode::is_digit(letter)));
|
|| letter == '\''
|
||||||
|
|| letter == '_'
|
||||||
|
|| letter == '#'
|
||||||
|
|| letter == '$'
|
||||||
|
|| letter == '@')
|
||||||
|
|| (!bool(is_first_character) && unicode::is_digit(letter));
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user