Compare commits
2 commits
26871aa9ae
...
f203da328b
| Author | SHA1 | Date | |
|---|---|---|---|
| f203da328b | |||
| ec5e59aed3 |
3 changed files with 41 additions and 7 deletions
|
|
@ -422,7 +422,9 @@ fn statement_let(p: &mut CParser) {
|
||||||
p.expect(TokenKind::Identifier, "expected a name for the variable");
|
p.expect(TokenKind::Identifier, "expected a name for the variable");
|
||||||
p.expect(TokenKind::Equal, "expected a '=' after the variable name");
|
p.expect(TokenKind::Equal, "expected a '=' after the variable name");
|
||||||
expression(p);
|
expression(p);
|
||||||
p.expect(TokenKind::Semicolon, "expect ';' to end a let statement");
|
if !p.at(TokenKind::RightBrace) {
|
||||||
|
p.expect(TokenKind::Semicolon, "expect ';' to end a let statement");
|
||||||
|
}
|
||||||
|
|
||||||
p.end(m, TreeKind::LetStatement);
|
p.end(m, TreeKind::LetStatement);
|
||||||
}
|
}
|
||||||
|
|
@ -436,7 +438,9 @@ fn statement_return(p: &mut CParser) {
|
||||||
"expect 'return' to start a return statement",
|
"expect 'return' to start a return statement",
|
||||||
);
|
);
|
||||||
expression(p);
|
expression(p);
|
||||||
p.expect(TokenKind::Semicolon, "expect ';' to end a return statement");
|
if !p.at(TokenKind::RightBrace) {
|
||||||
|
p.expect(TokenKind::Semicolon, "expect ';' to end a return statement");
|
||||||
|
}
|
||||||
|
|
||||||
p.end(m, TreeKind::ReturnStatement);
|
p.end(m, TreeKind::ReturnStatement);
|
||||||
}
|
}
|
||||||
|
|
@ -445,10 +449,12 @@ fn statement_expression(p: &mut CParser) {
|
||||||
let m = p.start();
|
let m = p.start();
|
||||||
|
|
||||||
expression(p);
|
expression(p);
|
||||||
p.expect(
|
if !p.at(TokenKind::RightBrace) {
|
||||||
TokenKind::Semicolon,
|
p.expect(
|
||||||
"expect ';' to end an expression statement",
|
TokenKind::Semicolon,
|
||||||
);
|
"expect ';' to end an expression statement",
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
p.end(m, TreeKind::ExpressionStatement);
|
p.end(m, TreeKind::ExpressionStatement);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -2,13 +2,13 @@ use fine::parser::concrete::Tree;
|
||||||
use pretty_assertions::assert_eq;
|
use pretty_assertions::assert_eq;
|
||||||
|
|
||||||
fn rebase_concrete(source_path: &str, dump: &str) {
|
fn rebase_concrete(source_path: &str, dump: &str) {
|
||||||
// RE-BASE
|
|
||||||
let contents = std::fs::read_to_string(source_path)
|
let contents = std::fs::read_to_string(source_path)
|
||||||
.expect(&format!("unable to read input file {}", source_path));
|
.expect(&format!("unable to read input file {}", source_path));
|
||||||
|
|
||||||
let mut result = String::new();
|
let mut result = String::new();
|
||||||
let mut lines = contents.lines();
|
let mut lines = contents.lines();
|
||||||
|
|
||||||
|
// Search for the "concrete:" section.
|
||||||
let mut found_concrete_section = false;
|
let mut found_concrete_section = false;
|
||||||
while let Some(line) = lines.next() {
|
while let Some(line) = lines.next() {
|
||||||
result.push_str(line);
|
result.push_str(line);
|
||||||
|
|
@ -26,6 +26,8 @@ fn rebase_concrete(source_path: &str, dump: &str) {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// We've found the section we care about, replace all the lines we care
|
||||||
|
// about with the actual lines.
|
||||||
let mut replaced_output = false;
|
let mut replaced_output = false;
|
||||||
while let Some(line) = lines.next() {
|
while let Some(line) = lines.next() {
|
||||||
if line.starts_with("// | ") {
|
if line.starts_with("// | ") {
|
||||||
|
|
|
||||||
26
fine/tests/expression/conditional.fine
Normal file
26
fine/tests/expression/conditional.fine
Normal file
|
|
@ -0,0 +1,26 @@
|
||||||
|
// concrete:
|
||||||
|
// | File
|
||||||
|
// | IfStatement
|
||||||
|
// | ConditionalExpression
|
||||||
|
// | If:'"if"'
|
||||||
|
// | LiteralExpression
|
||||||
|
// | True:'"true"'
|
||||||
|
// | Block
|
||||||
|
// | LeftBrace:'"{"'
|
||||||
|
// | ExpressionStatement
|
||||||
|
// | LiteralExpression
|
||||||
|
// | String:'"\"discarded\""'
|
||||||
|
// | Semicolon:'";"'
|
||||||
|
// | ExpressionStatement
|
||||||
|
// | LiteralExpression
|
||||||
|
// | Number:'"23"'
|
||||||
|
// | RightBrace:'"}"'
|
||||||
|
// | Else:'"else"'
|
||||||
|
// | Block
|
||||||
|
// | LeftBrace:'"{"'
|
||||||
|
// | ExpressionStatement
|
||||||
|
// | LiteralExpression
|
||||||
|
// | Number:'"45"'
|
||||||
|
// | RightBrace:'"}"'
|
||||||
|
//
|
||||||
|
if true { "discarded"; 23 } else { 45 }
|
||||||
Loading…
Add table
Add a link
Reference in a new issue