Cleaned up phrase parsing a bit
This commit is contained in:
parent
77acfd1cf2
commit
85f97189ac
@ -139,25 +139,16 @@ func (parser *ParsingOperation) parseBlockLevelPhrase (
|
|||||||
err = parser.expect(validDelimitedPhraseTokens...)
|
err = parser.expect(validDelimitedPhraseTokens...)
|
||||||
if err != nil { return }
|
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) {
|
if parser.token.Is(lexer.TokenKindRBracket) {
|
||||||
// this is an ending delimiter
|
// this is an ending delimiter
|
||||||
err = parser.nextToken()
|
err = parser.nextToken()
|
||||||
if err != nil { return }
|
if err != nil { return }
|
||||||
break
|
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 {
|
} else {
|
||||||
// not delimited
|
// 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
|
var argument Argument
|
||||||
argument, err = parser.parseArgument()
|
argument, err = parser.parseArgument()
|
||||||
phrase.arguments = append(phrase.arguments, argument)
|
phrase.arguments = append(phrase.arguments, argument)
|
||||||
@ -222,10 +213,9 @@ func (parser *ParsingOperation) parseBlockLevelPhrase (
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if !isControlFlow { return }
|
if isControlFlow {
|
||||||
|
|
||||||
// if it is any of those, parse the block under it
|
|
||||||
phrase.block, err = parser.parseBlock(indent + 1)
|
phrase.block, err = parser.parseBlock(indent + 1)
|
||||||
|
}
|
||||||
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -318,6 +308,8 @@ func (parser *ParsingOperation) parsePhraseCommand () (
|
|||||||
identifier := command.value.(Identifier)
|
identifier := command.value.(Identifier)
|
||||||
if len(identifier.trail) == 1 {
|
if len(identifier.trail) == 1 {
|
||||||
switch identifier.trail[0] {
|
switch identifier.trail[0] {
|
||||||
|
case "let":
|
||||||
|
kind = PhraseKindLet
|
||||||
case "loc":
|
case "loc":
|
||||||
kind = PhraseKindReference
|
kind = PhraseKindReference
|
||||||
case "defer":
|
case "defer":
|
||||||
|
@ -231,6 +231,7 @@ const (
|
|||||||
PhraseKindCall = iota
|
PhraseKindCall = iota
|
||||||
PhraseKindCallExternal
|
PhraseKindCallExternal
|
||||||
PhraseKindOperator
|
PhraseKindOperator
|
||||||
|
PhraseKindLet
|
||||||
PhraseKindAssign
|
PhraseKindAssign
|
||||||
PhraseKindReference
|
PhraseKindReference
|
||||||
PhraseKindDefer
|
PhraseKindDefer
|
||||||
|
Reference in New Issue
Block a user