If-then-else

This commit is contained in:
Smaug123
2024-01-22 19:22:36 +00:00
parent 4275b5caa7
commit 6c26bcb5eb
3 changed files with 33 additions and 1 deletions

View File

@@ -71,6 +71,24 @@ module Parser =
Expr.paren contents, rest
elif firstToken.Type = TokenType.If then
let ifClause, rest = parseInner inputString rest 0
match rest with
| [] -> failwith "if requires a trailing then"
| head :: _ when head.Type <> TokenType.Then -> failwithf "if was not followed by then, got: %+A" head
| _ :: rest ->
let thenClause, rest = parseInner inputString rest 0
match rest with
| [] -> Expr.ifThen ifClause thenClause, rest
| head :: _ when head.Type <> TokenType.Else -> Expr.ifThen ifClause thenClause, rest
| _ :: rest ->
let elseClause, rest = parseInner inputString rest 0
Expr.ifThenElse ifClause thenClause elseClause, rest
else
match Token.prefixPrecedence firstToken.Type with