Operators can no longer be arguments

This commit is contained in:
Sasha Koshka 2022-09-27 14:48:05 -04:00
parent 1ed612b3d1
commit 4228d2b4cf
2 changed files with 20 additions and 15 deletions

View File

@ -129,7 +129,10 @@ func (parser *ParsingOperation) parseBlockLevelPhrase (
// get command
err = parser.expect(validPhraseStartTokens...)
if err != nil { return }
phrase.command, phrase.kind, err = parser.parsePhraseCommand()
phrase.command,
phrase.kind,
phrase.operator,
err = parser.parsePhraseCommand()
if err != nil { return }
for {
@ -233,7 +236,10 @@ func (parser *ParsingOperation) parseArgumentLevelPhrase () (
// get command
err = parser.nextToken(validPhraseStartTokens...)
if err != nil { return }
phrase.command, phrase.kind, err = parser.parsePhraseCommand()
phrase.command,
phrase.kind,
phrase.operator,
err = parser.parsePhraseCommand()
if err != nil { return }
for {
@ -272,24 +278,22 @@ func (parser *ParsingOperation) parseArgumentLevelPhrase () (
// parsePhraseCommand parses the command argument of a phrase.
func (parser *ParsingOperation) parsePhraseCommand () (
command Argument,
kind PhraseKind,
err error,
command Argument,
kind PhraseKind,
operator lexer.TokenKind,
err error,
) {
if isTokenOperator(parser.token) {
err = parser.expect(operatorTokens...)
if err != nil { return }
command.location = parser.token.Location()
command.kind = ArgumentKindOperator
command.value = parser.token.Kind()
if parser.token.Is(lexer.TokenKindColon) {
kind = PhraseKindCase
} else if parser.token.Is(lexer.TokenKindAssignment) {
kind = PhraseKindAssign
} else {
kind = PhraseKindOperator
operator = parser.token.Kind()
}
err = parser.nextToken()

View File

@ -2,6 +2,7 @@ package parser
import "git.tebibyte.media/arf/arf/file"
import "git.tebibyte.media/arf/arf/types"
import "git.tebibyte.media/arf/arf/lexer"
import "git.tebibyte.media/arf/arf/infoerr"
// SyntaxTree represents an abstract syntax tree. It covers an entire module. It
@ -135,10 +136,6 @@ const (
// 'S'
ArgumentKindRune
// + - * / etc...
// this is only used as a phrase command
ArgumentKindOperator
)
// Argument represents a value that can be placed anywhere a value goes. This
@ -229,11 +226,15 @@ const (
// syntactical concept.
type Phrase struct {
location file.Location
command Argument
returnees []Argument
multiValuable
kind PhraseKind
command Argument
// only applicable for PhraseKindOperator
operator lexer.TokenKind
// only applicable for control flow phrases
block Block