Skip to content

Commit 643fa8f

Browse files
committed
fix multi-line expressions
1 parent f458ae8 commit 643fa8f

4 files changed

Lines changed: 53 additions & 2 deletions

File tree

FadeBasic/CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,11 @@ All notable changes to this project will be documented in this file.
55
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
66
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
77

8+
## [0.0.46] - 2025-11-25
9+
10+
### Fixed
11+
- expressions can be multiline
12+
813
## [0.0.45] - 2025-06-19
914

1015
### Fixed

FadeBasic/FadeBasic/Parser.cs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3071,12 +3071,36 @@ private IExpressionNode ParseWikiExpression(IExpressionNode lhs, int minPrec)
30713071
{
30723072

30733073
var lookAhead = _stream.Peek;
3074+
3075+
while (lookAhead.type == LexemType.EndStatement)
3076+
{
3077+
var x = _stream.Save();
3078+
_stream.Advance();
3079+
lookAhead = _stream.Peek;
3080+
if (lookAhead.type != LexemType.EndStatement && !IsBinaryOp(lookAhead))
3081+
{
3082+
_stream.Restore(x);
3083+
}
3084+
}
3085+
30743086
while (IsBinaryOp(lookAhead) && GetOperatorOrder(lookAhead) >= minPrec)
30753087
{
30763088
var op = lookAhead;
30773089
_stream.Advance();
30783090
var rhs = ParseWikiTerm();
30793091
lookAhead = _stream.Peek;
3092+
3093+
while (lookAhead.type == LexemType.EndStatement)
3094+
{
3095+
var x = _stream.Save();
3096+
_stream.Advance();
3097+
lookAhead = _stream.Peek;
3098+
if (lookAhead.type != LexemType.EndStatement && !IsBinaryOp(lookAhead))
3099+
{
3100+
_stream.Restore(x);
3101+
}
3102+
}
3103+
30803104
// while lookahead is a binary operator whose precedence is greater
30813105
// than op's, or a right-associative operator
30823106
// whose precedence is equal to op's

FadeBasic/Tests/ExpressionTests.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ public Parser BuildParser(string src, out List<Token> tokens)
4444
[TestCase("1+2", "(+ (1),(2))")]
4545
[TestCase("(2)", "(2)")]
4646
[TestCase("1+2+3", "(+ (1),(+ (2),(3)))")]
47+
[TestCase("1+2\n+3", "(+ (1),(+ (2),(3)))")]
4748
[TestCase("1+2+3+4", "(+ (1),(+ (2),(+ (3),(4))))")]
4849
[TestCase("1+(2+3)+4", "(+ (1),(+ (+ (2),(3)),(4)))")]
4950
[TestCase("(1+2)+3", "(+ (+ (1),(2)),(3))")]
@@ -66,6 +67,7 @@ public Parser BuildParser(string src, out List<Token> tokens)
6667
[TestCase("-a", "(neg (ref a))")]
6768
[TestCase("b - -a", "(- (ref b),(neg (ref a)))")]
6869
[TestCase("3 AND 2", "(and (3),(2))")]
70+
[TestCase("3 \nAND 2", "(and (3),(2))")]
6971
[TestCase("3 XOR 2", "(xor (3),(2))")]
7072
[TestCase("3 AND 2+1", "(and (3),(+ (2),(1)))")]
7173
[TestCase("(3 AND 2)+1", "(+ (and (3),(2)),(1))")]

FadeBasic/Tests/ParserTests_Erros.cs

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1679,8 +1679,28 @@ function toast(x)
16791679
Assert.That(errors[0].Display, Is.EqualTo($"[3:4] - {ErrorCodes.InvalidReference} | unknown symbol, x"));
16801680
}
16811681

1682-
1683-
1682+
[Test]
1683+
public void Bug_Nov24_2025_MultiLineWhileClause()
1684+
{
1685+
/*
1686+
* This is a pretty major issue. Multi-line expressions should work, but
1687+
* they get stuck on EndOfStatement tokens.
1688+
*
1689+
* The rest of the parser is written to use the EndOfStatement, so re-writing it
1690+
* is not ideal.
1691+
*
1692+
* This test/note is here for me to deal with this later. Sad Sauce.
1693+
*/
1694+
var input = $@"
1695+
while (3
1696+
or 5)
1697+
endwhile
1698+
";
1699+
var parser = MakeParser(input);
1700+
var prog = parser.ParseProgram();
1701+
1702+
prog.AssertNoParseErrors();
1703+
}
16841704

16851705
[Test]
16861706
public void ParseError_StructCastToForLoopVariable()

0 commit comments

Comments
 (0)