@@ -103,7 +103,7 @@ func (p *Parser) parseComment(pos lexer.Position) (*Comment, core.Location, erro
103103
104104 data , found := p .DelimString ("-->" , false )
105105 if ! found {
106- return nil , core.Location {}, p .NewError (p .Current ().Position , p .Current ().Position , "<!--" , locale .ErrNotFoundEndTag )
106+ return nil , core.Location {}, p .newError (p .Current ().Position , p .Current ().Position , "<!--" , locale .ErrNotFoundEndTag )
107107 }
108108 end := p .Current ()
109109 p .Next (3 ) // 跳过 --> 三个字符
@@ -127,7 +127,7 @@ func (p *Parser) parseStartElement(pos lexer.Position) (*StartElement, core.Loca
127127 start := p .Current ()
128128 name , found := p .DelimFunc (func (r rune ) bool { return unicode .IsSpace (r ) || r == '/' || r == '>' }, false )
129129 if ! found || len (name ) == 0 {
130- return nil , core.Location {}, p .NewError (p .Current ().Position , p .Current ().Position , "" , locale .ErrInvalidXML )
130+ return nil , core.Location {}, p .newError (p .Current ().Position , p .Current ().Position , "" , locale .ErrInvalidXML )
131131 }
132132
133133 elem := & StartElement {
@@ -152,7 +152,7 @@ func (p *Parser) parseStartElement(pos lexer.Position) (*StartElement, core.Loca
152152 return elem , elem .Location , nil
153153 }
154154
155- return nil , core.Location {}, p .NewError (p .Current ().Position , p .Current ().Position , string (name ), locale .ErrNotFoundEndTag )
155+ return nil , core.Location {}, p .newError (p .Current ().Position , p .Current ().Position , string (name ), locale .ErrNotFoundEndTag )
156156}
157157
158158func parseName (name []byte , uri core.URI , start , end core.Position ) Name {
@@ -188,7 +188,7 @@ func (p *Parser) parseEndElement(pos lexer.Position) (*EndElement, core.Location
188188
189189 name , found := p .Delim ('>' , false )
190190 if ! found || len (name ) == 0 {
191- return nil , core.Location {}, p .NewError (p .Current ().Position , p .Current ().Position , "" , locale .ErrInvalidXML )
191+ return nil , core.Location {}, p .newError (p .Current ().Position , p .Current ().Position , "" , locale .ErrInvalidXML )
192192 }
193193 end := p .Current ()
194194 p .Next (1 ) // 去掉 > 符号
@@ -211,7 +211,7 @@ func (p *Parser) parseCData(pos lexer.Position) (*CData, core.Location, error) {
211211 for {
212212 v , found := p .DelimString (cdataEnd , false )
213213 if ! found {
214- return nil , core.Location {}, p .NewError (pos .Position , p .Current ().Position , cdataStart , locale .ErrNotFoundEndTag )
214+ return nil , core.Location {}, p .newError (pos .Position , p .Current ().Position , cdataStart , locale .ErrNotFoundEndTag )
215215 }
216216 value = append (value , v ... )
217217
@@ -291,7 +291,7 @@ func (p *Parser) parseCData(pos lexer.Position) (*CData, core.Location, error) {
291291func (p * Parser ) parseInstruction (pos lexer.Position ) (* Instruction , core.Location , error ) {
292292 name , nameRange := p .getName ()
293293 if len (name ) == 0 {
294- return nil , core.Location {}, p .NewError (p .Current ().Position , p .Current ().Position , "" , locale .ErrInvalidXML )
294+ return nil , core.Location {}, p .newError (p .Current ().Position , p .Current ().Position , "" , locale .ErrInvalidXML )
295295 }
296296 elem := & Instruction {
297297 Location : core.Location {URI : p .Location .URI },
@@ -316,7 +316,7 @@ func (p *Parser) parseInstruction(pos lexer.Position) (*Instruction, core.Locati
316316 return elem , elem .Location , nil
317317 }
318318
319- return nil , core.Location {}, p .NewError (p .Current ().Position , p .Current ().Position , "<?" , locale .ErrNotFoundEndTag )
319+ return nil , core.Location {}, p .newError (p .Current ().Position , p .Current ().Position , "<?" , locale .ErrNotFoundEndTag )
320320}
321321
322322func (p * Parser ) parseAttributes () (attrs []* Attribute , err error ) {
@@ -351,18 +351,18 @@ func (p *Parser) parseAttribute() (*Attribute, error) {
351351
352352 p .Spaces (0 )
353353 if ! p .Match ("=" ) {
354- return nil , p .NewError (p .Current ().Position , p .Current ().Position , "" , locale .ErrInvalidXML )
354+ return nil , p .newError (p .Current ().Position , p .Current ().Position , "" , locale .ErrInvalidXML )
355355 }
356356
357357 p .Spaces (0 )
358358 if ! p .Match ("\" " ) {
359- return nil , p .NewError (p .Current ().Position , p .Current ().Position , "" , locale .ErrInvalidXML )
359+ return nil , p .newError (p .Current ().Position , p .Current ().Position , "" , locale .ErrInvalidXML )
360360 }
361361
362362 pos = p .Current ()
363363 value , found := p .Delim ('"' , true )
364364 if ! found || len (value ) == 0 {
365- return nil , p .NewError (p .Current ().Position , p .Current ().Position , "" , locale .ErrInvalidXML )
365+ return nil , p .newError (p .Current ().Position , p .Current ().Position , "" , locale .ErrInvalidXML )
366366 }
367367 end := p .Current ().SubRune ('"' ) // 不包含 " 符号
368368 attr .Value = String {
@@ -438,10 +438,8 @@ func (p *Parser) endElement(start *StartElement) error {
438438 }
439439}
440440
441- // NewError 生成 *core.Error 对象
442- //
443- // 其中的 URI 来自于 p.Location.URI
444- func (p * Parser ) NewError (start , end core.Position , field string , key message.Reference , v ... interface {}) * core.Error {
441+ // newError 生成 *core.Error 对象,其中的 URI 来自于 p.Location.URI。
442+ func (p * Parser ) newError (start , end core.Position , field string , key message.Reference , v ... interface {}) * core.Error {
445443 return core .NewError (key , v ... ).
446444 WithField (field ).
447445 WithLocation (core.Location {
0 commit comments