当前位置: 首页>>代码示例>>Golang>>正文


Golang Token.LongLocationString方法代码示例

本文整理汇总了Golang中mojom/mojom_parser/lexer.Token.LongLocationString方法的典型用法代码示例。如果您正苦于以下问题:Golang Token.LongLocationString方法的具体用法?Golang Token.LongLocationString怎么用?Golang Token.LongLocationString使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在mojom/mojom_parser/lexer.Token的用法示例。


在下文中一共展示了Token.LongLocationString方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: matchSemicolonToken

func (p *Parser) matchSemicolonToken(previousToken lexer.Token) bool {
	if !p.OK() {
		return false
	}
	if p.match(lexer.Semi) {
		return true
	}
	message := fmt.Sprintf("Missing semicolon after %s at %s.",
		previousToken, previousToken.LongLocationString())
	p.err = &ParseError{ParserErrorCodeUnexpectedToken, message}
	return false
}
开发者ID:krisgiesing,项目名称:mojo,代码行数:12,代码来源:parsing.go

示例2: matchSemicolonToken

func (p *Parser) matchSemicolonToken(previousToken lexer.Token) bool {
	if !p.OK() {
		return false
	}
	if p.match(lexer.SEMI) {
		return true
	}
	message := fmt.Sprintf("Missing semicolon after %s at %s.",
		previousToken, previousToken.LongLocationString())
	p.err = &ParseError{E_UNEXPECTED_TOKEN, message}
	return false
}
开发者ID:MitchRudominer,项目名称:mojom_parser,代码行数:12,代码来源:parsing.go

示例3: expectedTokenError

// |unexpected| should be a string of the grammatical form "Unexpected token at %s: %s."
// |expected| should be a string of the grammatic form "a semicolon"
func (p *Parser) expectedTokenError(token lexer.Token, unexpected string, expected string) string {
	message := fmt.Sprintf(" Expecting %s.", expected)
	switch token.Kind {
	case lexer.ErrorUnknown, lexer.ErrorIllegalChar,
		lexer.ErrorUnterminatedStringLiteral,
		lexer.ErrorUnterminatedComment:
		message = fmt.Sprintf("%s at %s.", token, token.LongLocationString()) + message
	default:
		message = fmt.Sprintf(unexpected, token.LongLocationString(), token) + message
	}
	p.err = &ParseError{ParserErrorCodeUnexpectedToken, message}
	return message
}
开发者ID:krisgiesing,项目名称:mojo,代码行数:15,代码来源:parsing.go

示例4: expectedTokenError

// |unexpected| should be a string of the grammatical form "Unexpected token at %s: %s."
// |expected| should be a string of the grammatic form "a semicolon"
func (p *Parser) expectedTokenError(token lexer.Token, unexpected string, expected string) string {
	message := fmt.Sprintf(" Expecting %s.", expected)
	switch token.Kind {
	case lexer.ERROR_UNKNOWN, lexer.ERROR_ILLEGAL_CHAR,
		lexer.ERROR_UNTERMINATED_STRING_LITERAL,
		lexer.ERROR_UNTERMINATED_COMMENT:
		message = fmt.Sprintf("%s at %s.", token, token.LongLocationString()) + message
	default:
		message = fmt.Sprintf(unexpected, token.LongLocationString(), token) + message
	}
	p.err = &ParseError{E_UNEXPECTED_TOKEN, message}
	return message
}
开发者ID:MitchRudominer,项目名称:mojom_parser,代码行数:15,代码来源:parsing.go

示例5: parseStructField

// STRUCT_FIELD         -> TYPE name [ordinal] [equals DEFAULT_VALUE] semi
// DEFAULT_VALUE        -> APPROPRIATE_VAL_SPEC | default
// APPROPRIATE_VAL_SPEC -> VALUE_REF {{that resolves to a type that is assignment compatible to the type of the assignee}}
func (p *Parser) parseStructField(attributes *mojom.Attributes) *mojom.StructField {
	if !p.OK() {
		return nil
	}
	p.pushChildNode("structField")
	defer p.popNode()

	fieldType := p.parseType()
	fieldName := p.readName()
	nameToken := p.lastConsumed
	p.attachToken()

	ordinalValue, err := p.readOrdinal()
	if err != nil {
		p.err = p.newInvalidOrdinalError("field", fieldName, nameToken, err)
		return nil
	}

	var defaultValue mojom.ValueRef
	var defaultValueToken lexer.Token
	if p.tryMatch(lexer.Equals) {
		defaultValueToken = p.peekNextToken("Expecting a default value.")
		if defaultValueToken.Kind == lexer.Default {
			p.consumeNextToken()
			defaultValue = mojom.MakeDefaultLiteral()
		} else {
			defaultValue = p.parseValue(fieldType)
		}
	}
	if !p.matchSemicolon() {
		return nil
	}

	declData := p.DeclDataWithOrdinal(fieldName, nameToken, attributes, ordinalValue)
	field := mojom.NewStructField(declData, fieldType, defaultValue)
	if !field.ValidateDefaultValue() {
		valueString := fmt.Sprintf("%v", defaultValue)
		valueTypeString := ""
		concreteValue := defaultValue.ResolvedConcreteValue()
		if concreteValue != nil {
			valueString = fmt.Sprintf("%v", concreteValue.Value())
			valueTypeString = fmt.Sprintf(" of type %s", concreteValue.ValueType())
		}
		message := fmt.Sprintf("Illegal assignment at %s: Field %s of type %s may not be assigned the value %v%s.",
			defaultValueToken.LongLocationString(), fieldName, fieldType, valueString, valueTypeString)
		p.err = &ParseError{ParserErrorCodeNotAssignmentCompatible, message}
		return nil
	}

	return field
}
开发者ID:krisgiesing,项目名称:mojo,代码行数:54,代码来源:parsing.go

示例6: parseStructField

// STRUCT_FIELD         -> TYPE name [ordinal] [equals DEFAULT_VALUE] semi
// DEFAULT_VALUE        -> APPROPRIATE_VAL_SPEC | default
// APPROPRIATE_VAL_SPEC -> VALUE_REF {{that resolves to a type that is assignment compatible to the type of the assignee}}
func (p *Parser) parseStructField(attributes *mojom.Attributes) *mojom.StructField {
	if !p.OK() {
		return nil
	}
	p.pushChildNode("structField")
	defer p.popNode()

	fieldType := p.parseType()
	fieldName := p.readName()
	p.attachToken()
	ordinalValue := p.readOrdinal()
	var defaultValue mojom.ValueRef
	var defaultValueToken lexer.Token
	if p.tryMatch(lexer.EQUALS) {
		defaultValueToken = p.peekNextToken("Expecting a default value.")
		if defaultValueToken.Kind == lexer.DEFAULT {
			p.consumeNextToken()
			defaultValue = mojom.MakeDefaultLiteral()
		} else {
			defaultValue = p.parseValue(fieldType)
		}
	}
	if !p.matchSemicolon() {
		return nil
	}

	field := mojom.NewStructField(fieldType, fieldName, ordinalValue, attributes, defaultValue)
	if !field.ValidateDefaultValue() {
		valueString := fmt.Sprintf("%v", defaultValue)
		valueTypeString := ""
		concreteValue := defaultValue.ResolvedConcreteValue()
		if concreteValue != nil {
			valueString = fmt.Sprintf("%v", concreteValue.Value())
			valueTypeString = fmt.Sprintf(" of type %s", concreteValue.ValueType())
		}
		message := fmt.Sprintf("Illegal assignment at %s: Field %s of type %s may not be assigned the value %v%s.",
			defaultValueToken.LongLocationString(), fieldName, fieldType, valueString, valueTypeString)
		p.err = &ParseError{E_TYPE_NOT_ASSIGNMENT_COMPATIBLE, message}
		return nil
	}

	return field
}
开发者ID:MitchRudominer,项目名称:mojom_parser,代码行数:46,代码来源:parsing.go


注:本文中的mojom/mojom_parser/lexer.Token.LongLocationString方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。