Compare commits
No commits in common. "0a471ed71c32f58a2d5f56ccca65d256044c741a" and "fc463d38070f44da8c4d9173717f8412d932c72c" have entirely different histories.
0a471ed71c
...
fc463d3807
@ -267,9 +267,8 @@ pub enum PatternLiteral {
|
||||
|
||||
#[derive(Debug, PartialEq, Clone)]
|
||||
pub struct Enumerator {
|
||||
pub identifier: Rc<String>,
|
||||
pub id: Rc<String>, //TODO rename this field
|
||||
pub generator: Expression,
|
||||
pub assignment: bool, //true if `=`, false if `<-`
|
||||
}
|
||||
|
||||
#[derive(Debug, PartialEq, Clone)]
|
||||
|
@ -791,13 +791,12 @@ fn for_expr(input: Span) -> ParseResult<ExpressionKind> {
|
||||
fn enumerator(input: Span) -> ParseResult<Enumerator> {
|
||||
alt((
|
||||
map(separated_pair(identifier, kw("<-"), expression_no_struct), |(ident, generator)| {
|
||||
Enumerator { identifier: rc_string(ident.fragment()), generator, assignment: false }
|
||||
Enumerator { id: rc_string(ident.fragment()), generator }
|
||||
}),
|
||||
//TODO distinguish these two cases in AST
|
||||
map(separated_pair(identifier, kw("="), expression_no_struct), |(ident, generator)| Enumerator {
|
||||
identifier: rc_string(ident.fragment()),
|
||||
id: rc_string(ident.fragment()),
|
||||
generator,
|
||||
assignment: true,
|
||||
}),
|
||||
))(input)
|
||||
}
|
||||
|
@ -298,11 +298,11 @@ peg::parser! {
|
||||
//TODO add guards, etc.
|
||||
rule enumerator(parser: &mut Parser) -> Enumerator =
|
||||
ident:identifier() _ "<-" _ generator:expression_no_struct(parser) {
|
||||
Enumerator { identifier: Rc::new(ident.to_string()), generator, assignment: false }
|
||||
Enumerator { id: Rc::new(ident.to_string()), generator }
|
||||
} /
|
||||
//TODO need to distinguish these two cases in AST
|
||||
ident:identifier() _ "=" _ generator:expression_no_struct(parser) {
|
||||
Enumerator { identifier: Rc::new(ident.to_string()), generator, assignment: true }
|
||||
Enumerator { id: Rc::new(ident.to_string()), generator }
|
||||
}
|
||||
|
||||
rule for_body(parser: &mut Parser) -> Box<ForBody> =
|
||||
@ -470,7 +470,7 @@ peg::parser! {
|
||||
bin_literal() / hex_literal() / unmarked_literal()
|
||||
|
||||
rule unmarked_literal() -> ExpressionKind =
|
||||
digits:digits() { let n = digits.chars().filter(|ch| *ch != '_').collect::<String>().parse().unwrap(); ExpressionKind::NatLiteral(n) }
|
||||
digits:digits() { ExpressionKind::NatLiteral(digits.parse().unwrap()) }
|
||||
|
||||
rule bin_literal() -> ExpressionKind =
|
||||
"0b" digits:bin_digits() {? parse_binary(digits).map(ExpressionKind::NatLiteral) }
|
||||
|
@ -405,11 +405,7 @@ fn for_expression() {
|
||||
assert_expr!(
|
||||
"for { a <- garodzny::maybeValue } return 1",
|
||||
expr(ForExpression {
|
||||
enumerators: vec![Enumerator {
|
||||
identifier: rc("a"),
|
||||
assignment: false,
|
||||
generator: expr(Value(qn!(garodzny, maybeValue)))
|
||||
}],
|
||||
enumerators: vec![Enumerator { id: rc("a"), generator: expr(Value(qn!(garodzny, maybeValue))) }],
|
||||
body: bx(ForBody::MonadicReturn(expr(NatLiteral(1))))
|
||||
})
|
||||
);
|
||||
@ -417,11 +413,7 @@ fn for_expression() {
|
||||
assert_expr!(
|
||||
"for n <- someRange { f(n) ; }",
|
||||
expr(ForExpression {
|
||||
enumerators: vec![Enumerator {
|
||||
identifier: rc("n"),
|
||||
assignment: false,
|
||||
generator: expr(Value(qn!(someRange)))
|
||||
}],
|
||||
enumerators: vec![Enumerator { id: rc("n"), generator: expr(Value(qn!(someRange))) }],
|
||||
body: bx(ForBody::StatementBlock(
|
||||
vec![stmt(StatementKind::Expression(expr(Call {
|
||||
f: bx(expr(Value(qn!(f)))),
|
||||
@ -1391,6 +1383,7 @@ fn blocks() {
|
||||
|
||||
assert_block!("{}", vec![].into());
|
||||
|
||||
//TODO this case is broken in the peg version
|
||||
let source = r#"{
|
||||
|
||||
//hella
|
||||
@ -1398,8 +1391,11 @@ fn blocks() {
|
||||
11; /*chutney*/0xf
|
||||
}"#;
|
||||
|
||||
assert_block!(
|
||||
source,
|
||||
let mut parser = Parser::new();
|
||||
let block = parser.block_comb(source);
|
||||
|
||||
assert_eq!(
|
||||
block.unwrap(),
|
||||
vec![
|
||||
Statement {
|
||||
id: Default::default(),
|
||||
|
Loading…
Reference in New Issue
Block a user