Cleaned up phrase parsing a bit

This commit is contained in:
Sasha Koshka 2022-09-17 12:30:56 -04:00
parent 77acfd1cf2
commit 85f97189ac
2 changed files with 11 additions and 18 deletions

View File

@ -139,25 +139,16 @@ func (parser *ParsingOperation) parseBlockLevelPhrase (
err = parser.expect(validDelimitedPhraseTokens...)
if err != nil { return }
// we are delimited so we can safely skip whitespace
err = parser.skipWhitespace()
if err != nil { return }
if parser.token.Is(lexer.TokenKindRBracket) {
// this is an ending delimiter
err = parser.nextToken()
if err != nil { return }
break
} else if parser.token.Is(lexer.TokenKindNewline) {
// we are delimited, so we can safely skip
// newlines
err = parser.nextToken()
if err != nil { return }
continue
} else if parser.token.Is(lexer.TokenKindIndent) {
// we are delimited, so we can safely skip
// indents
err = parser.nextToken()
if err != nil { return }
continue
}
} else {
// not delimited
@ -176,7 +167,7 @@ func (parser *ParsingOperation) parseBlockLevelPhrase (
}
}
// this is an argument
// if we've got this far, we are parsing an argument
var argument Argument
argument, err = parser.parseArgument()
phrase.arguments = append(phrase.arguments, argument)
@ -222,10 +213,9 @@ func (parser *ParsingOperation) parseBlockLevelPhrase (
}
}
if !isControlFlow { return }
// if it is any of those, parse the block under it
phrase.block, err = parser.parseBlock(indent + 1)
if isControlFlow {
phrase.block, err = parser.parseBlock(indent + 1)
}
return
}
@ -318,6 +308,8 @@ func (parser *ParsingOperation) parsePhraseCommand () (
identifier := command.value.(Identifier)
if len(identifier.trail) == 1 {
switch identifier.trail[0] {
case "let":
kind = PhraseKindLet
case "loc":
kind = PhraseKindReference
case "defer":

View File

@ -231,6 +231,7 @@ const (
PhraseKindCall = iota
PhraseKindCallExternal
PhraseKindOperator
PhraseKindLet
PhraseKindAssign
PhraseKindReference
PhraseKindDefer