Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(170)

Side by Side Diff: mojom/mojom_parser/parser/parsing.go

Issue 1767033002: Mojom parser: Compute and validate struct field ordinals. (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Maintain the property that the fields of a module.Struct are sorted in declaration order. Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « mojom/mojom_parser/parser/parser_test.go ('k') | mojom/mojom_parser/parser/resolution_test.go » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 package parser 1 package parser
2 2
3 import ( 3 import (
4 "fmt" 4 "fmt"
5 "math" 5 "math"
6 "mojom/mojom_parser/lexer" 6 "mojom/mojom_parser/lexer"
7 "mojom/mojom_parser/mojom" 7 "mojom/mojom_parser/mojom"
8 "strconv" 8 "strconv"
9 ) 9 )
10 10
(...skipping 636 matching lines...) Expand 10 before | Expand all | Expand 10 after
647 continue 647 continue
648 case lexer.RParen: 648 case lexer.RParen:
649 continue 649 continue
650 default: 650 default:
651 p.unexpectedTokenError(nextToken, "comma or )") 651 p.unexpectedTokenError(nextToken, "comma or )")
652 return nil 652 return nil
653 } 653 }
654 } 654 }
655 655
656 if p.OK() { 656 if p.OK() {
657 » » paramStruct.ComputeFieldOrdinals() 657 » » if err := paramStruct.ComputeFieldOrdinals(); err != nil {
658 » » » p.err = err
659 » » » return nil
660 » » }
658 } 661 }
659 return 662 return
660 } 663 }
661 664
662 // STRUCT_DECL -> struct name lbrace STRUCT_BODY rbrace semi 665 // STRUCT_DECL -> struct name lbrace STRUCT_BODY rbrace semi
663 func (p *Parser) parseStructDecl(attributes *mojom.Attributes) (mojomStruct *moj om.MojomStruct) { 666 func (p *Parser) parseStructDecl(attributes *mojom.Attributes) (mojomStruct *moj om.MojomStruct) {
664 if !p.OK() { 667 if !p.OK() {
665 return 668 return
666 } 669 }
667 p.pushChildNode("structDecl") 670 p.pushChildNode("structDecl")
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
743 default: 746 default:
744 p.unexpectedTokenError(nextToken, "field, enum or consta nt declaration") 747 p.unexpectedTokenError(nextToken, "field, enum or consta nt declaration")
745 return false 748 return false
746 } 749 }
747 if p.OK() && duplicateNameError != nil { 750 if p.OK() && duplicateNameError != nil {
748 p.err = duplicateNameError 751 p.err = duplicateNameError
749 return false 752 return false
750 } 753 }
751 } 754 }
752 if p.OK() { 755 if p.OK() {
753 » » mojomStruct.ComputeFieldOrdinals() 756 » » if err := mojomStruct.ComputeFieldOrdinals(); err != nil {
757 » » » p.err = err
758 » » » return false
759 » » }
754 } 760 }
761
755 return p.OK() 762 return p.OK()
756 } 763 }
757 764
758 // STRUCT_FIELD -> TYPE name [ordinal] [equals DEFAULT_VALUE] semi 765 // STRUCT_FIELD -> TYPE name [ordinal] [equals DEFAULT_VALUE] semi
759 // DEFAULT_VALUE -> COMPATIBLE_VALUE_REF | default 766 // DEFAULT_VALUE -> COMPATIBLE_VALUE_REF | default
760 func (p *Parser) parseStructField(attributes *mojom.Attributes) *mojom.StructFie ld { 767 func (p *Parser) parseStructField(attributes *mojom.Attributes) *mojom.StructFie ld {
761 if !p.OK() { 768 if !p.OK() {
762 return nil 769 return nil
763 } 770 }
764 p.pushChildNode("structField") 771 p.pushChildNode("structField")
(...skipping 983 matching lines...) Expand 10 before | Expand all | Expand 10 after
1748 func (p *Parser) unexpectedTokenError(token lexer.Token, expected string) { 1755 func (p *Parser) unexpectedTokenError(token lexer.Token, expected string) {
1749 var message string 1756 var message string
1750 switch token.Kind { 1757 switch token.Kind {
1751 case lexer.ErrorUnterminatedStringLiteral, lexer.ErrorUnterminatedCommen t: 1758 case lexer.ErrorUnterminatedStringLiteral, lexer.ErrorUnterminatedCommen t:
1752 message = fmt.Sprintf("%s", token) 1759 message = fmt.Sprintf("%s", token)
1753 default: 1760 default:
1754 message = fmt.Sprintf("Unexpected %s. Expecting %s.", token, exp ected) 1761 message = fmt.Sprintf("Unexpected %s. Expecting %s.", token, exp ected)
1755 } 1762 }
1756 p.parseErrorT(ParserErrorCodeUnexpectedToken, message, token) 1763 p.parseErrorT(ParserErrorCodeUnexpectedToken, message, token)
1757 } 1764 }
OLDNEW
« no previous file with comments | « mojom/mojom_parser/parser/parser_test.go ('k') | mojom/mojom_parser/parser/resolution_test.go » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698