Implemented list parsing

This commit is contained in:
Sasha Koshka 2022-09-27 18:03:27 -04:00
parent 37a216a53d
commit 8dd90e1c6b
3 changed files with 42 additions and 0 deletions

View File

@ -3,6 +3,8 @@ package parser
import "git.tebibyte.media/arf/arf/lexer"
import "git.tebibyte.media/arf/arf/infoerr"
// TODO: add support for dereferences and subscripts
var validArgumentStartTokens = []lexer.TokenKind {
lexer.TokenKindName,
@ -13,6 +15,7 @@ var validArgumentStartTokens = []lexer.TokenKind {
lexer.TokenKindRune,
lexer.TokenKindLBracket,
lexer.TokenKindLParen,
}
func (parser *ParsingOperation) parseArgument () (argument Argument, err error) {
@ -84,6 +87,10 @@ func (parser *ParsingOperation) parseArgument () (argument Argument, err error)
argument.kind = ArgumentKindPhrase
argument.value, err = parser.parseArgumentLevelPhrase()
case lexer.TokenKindLParen:
argument.kind = ArgumentKindList
argument.value, err = parser.parseList()
default:
panic (
"unimplemented argument kind " +

32
parser/list.go Normal file
View File

@ -0,0 +1,32 @@
package parser
import "git.tebibyte.media/arf/arf/lexer"
// parseList parses a parenthetically delimited list of arguments.
func (parser *ParsingOperation) parseList () (list List, err error) {
list.location = parser.token.Location()
err = parser.expect(lexer.TokenKindLParen)
if err != nil { return }
err = parser.nextToken()
if err != nil { return }
for {
err = parser.skipWhitespace()
if err != nil { return }
// if we have reached the end of the list, stop
if parser.token.Is(lexer.TokenKindRParen) { break }
// otherwise, parse argument
var argument Argument
argument, err = parser.parseArgument()
list.arguments = append(list.arguments, argument)
if err != nil { return }
}
err = parser.nextToken()
if err != nil { return }
return
}

View File

@ -86,6 +86,9 @@ type Declaration struct {
// List represents an array or object literal.
type List struct {
locatable
// TODO: have an array of unnamed arguments, and a map of named
// arguments
multiValuable
}