本文整理汇总了Golang中mojom/mojom_parser/lexer.Token.ShortLocationString方法的典型用法代码示例。如果您正苦于以下问题:Golang Token.ShortLocationString方法的具体用法?Golang Token.ShortLocationString怎么用?Golang Token.ShortLocationString使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类mojom/mojom_parser/lexer.Token
的用法示例。
在下文中一共展示了Token.ShortLocationString方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: duplicateNameMessage
func (p *Parser) duplicateNameMessage(dupeError *mojom.DuplicateNameError,
nameToken lexer.Token) string {
if dupeError == nil {
return ""
}
if dupeError.ExistingType() != nil {
return fmt.Sprintf("%s:%s. Duplicate definition for name '%s'. "+
"The fully-qualified name of this type would be the same as "+
"an existing type definition: "+
"%s %s in %s.", p.mojomFile.FileName,
nameToken.ShortLocationString(), nameToken.Text,
dupeError.ExistingType().Kind(),
dupeError.ExistingType().FullyQualifiedName(),
dupeError.ExistingType().Scope())
} else {
return fmt.Sprintf("%s:%s. Duplicate definition for name '%s'. "+
"The fully-qualified name of this value would be the same as "+
"an existing value definition: "+
"%s %s in %s.", p.mojomFile.FileName,
nameToken.ShortLocationString(), nameToken.Text,
dupeError.ExistingValue().Kind(),
dupeError.ExistingValue().FullyQualifiedName(),
dupeError.ExistingValue().Scope())
}
}
示例2: UserErrorMessageP
// UserErrorMessageP is responsible for formatting user-facing error messages
// This function is similar to UserErrorMessage except that it also allows the
// caller to specify the message prefix.
// prefix: An error message prefix such as "Error:". It should not end with a space.
func UserErrorMessageP(file *MojomFile, token lexer.Token, prefix, message string) string {
// TODO(rudominer) Allow users to disable the use of color in snippets.
useColor := true
// Optionally color the prefix red.
if useColor && len(prefix) > 0 {
prefix = fmt.Sprintf("\x1b[31;1m%s\x1b[0m", prefix)
}
if len(prefix) > 0 {
prefix = fmt.Sprintf("%s ", prefix)
}
message = fmt.Sprintf("%s%s", prefix, message)
filePath := "Unknown file"
importedFromMessage := ""
snippet := ""
if file != nil {
if len(file.fileContents) > 0 {
snippet = fmt.Sprintf("\n%s", token.Snippet(file.fileContents, useColor))
}
filePath = RelPathIfShorter(file.CanonicalFileName)
importedFromMessage = file.ImportedFromMessage()
}
return fmt.Sprintf("\n%s:%s: %s%s\n%s", filePath, token.ShortLocationString(),
message, snippet, importedFromMessage)
}
示例3: newInvalidOrdinalError
func (p *Parser) newInvalidOrdinalError(objectType, objectName string, nameToken lexer.Token, err error) *ParseError {
message := fmt.Sprintf("%s:%s %s %q: %s",
p.mojomFile.CanonicalFileName, nameToken.ShortLocationString(),
objectType, objectName, err.Error())
return &ParseError{ParserErrorCodeBadOrdinal, message}
}