introduce symbol to indicate matching, now used on all single-arg invocations
This commit is contained in:
parent
23490cc237
commit
ed6c52f120
|
@ -35,8 +35,8 @@ as an argument, prefix the block with `'`.
|
||||||
## Control flow builtins
|
## Control flow builtins
|
||||||
|
|
||||||
- `cflow.if, cond = ..., then = ..., else = ...`
|
- `cflow.if, cond = ..., then = ..., else = ...`
|
||||||
- `cflow.loop ...`
|
- `cflow.loop § ...`
|
||||||
- `cflow.return ...` (implicit when last expr in a block is not terminated via semicolon)
|
- `cflow.return § ...` (implicit when last expr in a block is not terminated via semicolon)
|
||||||
|
|
||||||
## Modules
|
## Modules
|
||||||
|
|
||||||
|
@ -61,7 +61,7 @@ with package-lock files or such. Packages (packaged module trees) would then be
|
||||||
# 1.
|
# 1.
|
||||||
|
|
||||||
final main { args env } = {
|
final main { args env } = {
|
||||||
std.io.writeln "Hello World!";
|
std.io.writeln § "Hello World!";
|
||||||
0
|
0
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -72,7 +72,7 @@ with package-lock files or such. Packages (packaged module trees) would then be
|
||||||
what_now = {
|
what_now = {
|
||||||
self.business_in_the_front;
|
self.business_in_the_front;
|
||||||
}, self.party_in_the_back {
|
}, self.party_in_the_back {
|
||||||
std.io.writeln "It works";
|
std.io.writeln § "It works";
|
||||||
};
|
};
|
||||||
|
|
||||||
# running `what_now` results in "It works" being printed.
|
# running `what_now` results in "It works" being printed.
|
||||||
|
|
|
@ -19,6 +19,7 @@ pub enum Token<'a> {
|
||||||
Comma,
|
Comma,
|
||||||
SemiColon,
|
SemiColon,
|
||||||
Dot,
|
Dot,
|
||||||
|
MatchPara,
|
||||||
|
|
||||||
// dynamic stuff
|
// dynamic stuff
|
||||||
/// amount of prefixed `$` to force immediate application
|
/// amount of prefixed `$` to force immediate application
|
||||||
|
@ -102,7 +103,7 @@ impl<'a> Iterator for Lexer<'a> {
|
||||||
let x = self.s.chars().next()?;
|
let x = self.s.chars().next()?;
|
||||||
let loc = self.loc;
|
let loc = self.loc;
|
||||||
let rtok = match x {
|
let rtok = match x {
|
||||||
'{' | '}' | '(' | ')' | '=' | ',' | ';' | '.' => {
|
'{' | '}' | '(' | ')' | '=' | ',' | ';' | '.' | '§' => {
|
||||||
self.eat(x.len_utf8());
|
self.eat(x.len_utf8());
|
||||||
match x {
|
match x {
|
||||||
'{' => Token::OpenBrace,
|
'{' => Token::OpenBrace,
|
||||||
|
@ -113,6 +114,7 @@ impl<'a> Iterator for Lexer<'a> {
|
||||||
',' => Token::Comma,
|
',' => Token::Comma,
|
||||||
';' => Token::SemiColon,
|
';' => Token::SemiColon,
|
||||||
'.' => Token::Dot,
|
'.' => Token::Dot,
|
||||||
|
'§' => Token::MatchPara,
|
||||||
_ => unreachable!(),
|
_ => unreachable!(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -249,8 +249,8 @@ impl Expression {
|
||||||
_ => FullIdentifier::parse_high(ctx).map(Expression::Alias),
|
_ => FullIdentifier::parse_high(ctx).map(Expression::Alias),
|
||||||
}?;
|
}?;
|
||||||
|
|
||||||
Ok(match ctx.pklx.peek() {
|
match ctx.pklx.peek() {
|
||||||
None | Some((_, Token::SemiColon)) => obj,
|
None | Some((_, Token::SemiColon | Token::CloseBrace | Token::CloseParen)) => Ok(obj),
|
||||||
Some((_, Token::Comma)) => {
|
Some((_, Token::Comma)) => {
|
||||||
let mut args = BTreeMap::new();
|
let mut args = BTreeMap::new();
|
||||||
while ctx.maybe_eat_token(Token::Comma).is_some() {
|
while ctx.maybe_eat_token(Token::Comma).is_some() {
|
||||||
|
@ -264,13 +264,23 @@ impl Expression {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Expression::InvocationMulti {
|
Ok(Expression::InvocationMulti {
|
||||||
obj: Box::new(obj),
|
obj: Box::new(obj),
|
||||||
args,
|
args,
|
||||||
}
|
})
|
||||||
}
|
}
|
||||||
_ => Expression::InvocationSingle(Box::new((obj, Expression::parse_high(ctx)?))),
|
Some((_, Token::MatchPara)) => {
|
||||||
})
|
ctx.pklx.next();
|
||||||
|
Ok(Expression::InvocationSingle(Box::new((
|
||||||
|
obj,
|
||||||
|
Expression::parse_high(ctx)?,
|
||||||
|
))))
|
||||||
|
}
|
||||||
|
_ => Err(Error {
|
||||||
|
loc: ctx.peek_loc(),
|
||||||
|
kind: ErrorKind::Unexpected("end of expression"),
|
||||||
|
}),
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue