parser: parse assignments, WIP

This commit is contained in:
Fatih Arslan 2015-10-16 14:44:11 +03:00
parent f432878452
commit 378bec0cf4

View File

@ -59,12 +59,25 @@ func (p *Parser) parseObjectItem() (*ObjectItem, error) {
// either an assignment or object // either an assignment or object
switch p.tok.Type { switch p.tok.Type {
case scanner.ASSIGN: case scanner.ASSIGN:
o := &ObjectItem{
keys: keys,
assign: p.tok.Pos,
}
o.val, err = p.parseType()
if err != nil {
return nil, err
}
return o, nil
case scanner.LBRACE: case scanner.LBRACE:
if len(keys) > 1 { if len(keys) > 1 {
// nested object // nested object
fmt.Println("nested object")
} }
// object or nested object // object
fmt.Println("object")
} }
switch len(keys) { switch len(keys) {
@ -78,8 +91,6 @@ func (p *Parser) parseObjectItem() (*ObjectItem, error) {
fmt.Println(tok) // debug fmt.Println(tok) // debug
switch tok.Type { switch tok.Type {
case scanner.ASSIGN:
// return p.parseAssignment()
case scanner.LBRACK: case scanner.LBRACK:
// return p.parseListType() // return p.parseListType()
case scanner.LBRACE: case scanner.LBRACE:
@ -93,6 +104,12 @@ func (p *Parser) parseObjectItem() (*ObjectItem, error) {
return nil, fmt.Errorf("not yet implemented: %s", tok.Type) return nil, fmt.Errorf("not yet implemented: %s", tok.Type)
} }
// parseType parses any type of Type, such as number, bool, string, object or
// list.
func (p *Parser) parseType() (Node, error) {
return nil, errors.New("ParseType is not implemented yet")
}
// parseObjectKey parses an object key and returns a ObjectKey AST // parseObjectKey parses an object key and returns a ObjectKey AST
func (p *Parser) parseObjectKey() ([]*ObjectKey, error) { func (p *Parser) parseObjectKey() ([]*ObjectKey, error) {
tok := p.scan() tok := p.scan()
@ -117,7 +134,8 @@ func (p *Parser) parseObjectKey() ([]*ObjectKey, error) {
tok := p.scan() tok := p.scan()
switch tok.Type { switch tok.Type {
case scanner.ASSIGN: case scanner.ASSIGN:
// assignment or object, but not nested objects // assignment or object only, but not nested objects. this is not
// allowed: `foo bar = {}`
if nestedObj { if nestedObj {
return nil, fmt.Errorf("nested object expected: LBRACE got: %s", tok.Type) return nil, fmt.Errorf("nested object expected: LBRACE got: %s", tok.Type)
} }