MCPcopy Create free account
hub / github.com/brettlangdon/forge / parseReference

Method parseReference

parser.go:111–144  ·  view source on GitHub ↗
(startingSection *Section, period bool)

Source from the content-addressed store, hash-verified

109}
110
111func (parser *Parser) parseReference(startingSection *Section, period bool) (Value, error) {
112 name := ""
113 if period == false {
114 name = parser.curTok.Literal
115 }
116 for {
117 parser.readToken()
118 if parser.curTok.ID == token.PERIOD && period == false {
119 period = true
120 } else if period && parser.curTok.ID == token.IDENTIFIER {
121 if len(name) > 0 {
122 name += "."
123 }
124 name += parser.curTok.Literal
125 period = false
126 } else if isSemicolonOrNewline(parser.curTok.ID) {
127 break
128 } else {
129 msg := fmt.Sprintf("expected ';' or '\n' instead found '%s'", parser.curTok.Literal)
130 return nil, parser.syntaxError(msg)
131 }
132 }
133 if len(name) == 0 {
134 return nil, parser.syntaxError(
135 fmt.Sprintf("expected IDENTIFIER instead found %s", parser.curTok.Literal),
136 )
137 }
138
139 if period {
140 return nil, parser.syntaxError(fmt.Sprintf("expected IDENTIFIER after PERIOD"))
141 }
142
143 return NewReference(name, startingSection), nil
144}
145
146func (parser *Parser) parseSettingValue() (Value, error) {
147 var value Value

Callers 1

parseSettingValueMethod · 0.95

Calls 4

readTokenMethod · 0.95
syntaxErrorMethod · 0.95
isSemicolonOrNewlineFunction · 0.85
NewReferenceFunction · 0.85

Tested by

no test coverage detected