Esempio n. 1
0
File: lex.go Progetto: knakk/rdf
// acceptRunMin consumes a run of runes from the valid set, returning
// true if a minimum number of runes where consumed.
func (l *lexer) acceptRunMin(valid []byte, num int) bool {
	c := 0
	for bytes.ContainsRune(valid, l.next()) {
		c++
	}
	l.backup()
	return c >= num
}
Esempio n. 2
0
func (p *printer) literalType(lit *ast.LiteralType) []byte {
	result := []byte(lit.Token.Text)
	switch lit.Token.Type {
	case token.HEREDOC:
		// Clear the trailing newline from heredocs
		if result[len(result)-1] == '\n' {
			result = result[:len(result)-1]
		}

		// Poison lines 2+ so that we don't indent them
		result = p.heredocIndent(result)
	case token.STRING:
		// If this is a multiline string, poison lines 2+ so we don't
		// indent them.
		if bytes.ContainsRune(result, '\n') {
			result = p.heredocIndent(result)
		}
	}

	return result
}