// lexMapQuotedKey consumes the text of a key between quotes.
17571
func lexMapDubQuotedKey(lx *lexer) stateFn {
	r := lx.peek()
	if r == dqStringEnd {
		lx.emit(itemKey)
		lx.next()
		return lexSkip(lx, lexMapKeyEnd)
	}
	lx.next()
	return lexMapDubQuotedKey
}
1144438
func lexKeyEnd(lx *lexer) stateFn {
	r := lx.next()
	switch {
	case isWhitespace(r) || isNL(r):
		return lexSkip(lx, lexKeyEnd)
	case isKeySeparator(r):
		return lexSkip(lx, lexValue)
	}
	// We start the value here
	lx.backup()
	return lexValue
}
795751
func (d *decodeState) valueQuoted() (interface{}, error) {
	switch d.opcode {
	default:
		return nil, errPhase

	case scanBeginArray:
		d.skip()
		d.scanNext()

	case scanBeginObject:
		d.skip()
		d.scanNext()

	case scanBeginLiteral:
		v, err := d.literalInterface()
		if err != nil {
			return nil, err
		}
		switch v.(type) {
		case nil, string:
			return v, nil
		}
	}
	return unquotedValue{}, nil
}
361577
func lexShortcodeParam(l *pageLexer, escapedQuoteStart bool) stateFunc {

	first := true
	nextEq := false

	var r rune

	for {
		r = l.next()
		if first {
			if r == '"' {
				// a positional param with quotes
				if l.paramElements == 2 {
					return l.errorf("got quoted positional parameter. Cannot mix named and positional parameters")
				}
				l.paramElements = 1
				l.backup()
				return lexShortcodeQuotedParamVal(l, !escapedQuoteStart, tScParam)
			}
			first = false
		} else if r == '=' {
			// a named param
			l.backup()
			nextEq = true
			break
		}

		if !isAlphaNumericOrHyphen(r) {
			l.backup()
			break
		}
	}

	if l.paramElements == 0 {
		l.paramElements++

		if nextEq {
			l.paramElements++
		}
	} else {
		if nextEq && l.paramElements == 1 {
			return l.errorf("got named parameter '%s'. Cannot mix named and positional parameters", l.current())
		} else if !nextEq && l.paramElements == 2 {
			return l.errorf("got positional parameter '%s'. Cannot mix named and positional parameters", l.current())
		}
	}

	l.emit(tScParam)
	return lexInsideShortcode

}
375847
func (l *tomlLexer) lexVoid() tomlLexStateFn {
	for {
		next := l.peek()
		switch next {
		case '[':
			return l.lexTableKey
		case '#':
			return l.lexComment(l.lexVoid)
		case '=':
			return l.lexEqual
		case '\r':
			fallthrough
		case '\n':
			l.skip()
			continue
		}

		if isSpace(next) {
			l.skip()
		}

		if l.depth > 0 {
			return l.lexRvalue
		}

		if isKeyStartChar(next) {
			return l.lexKey
		}

		if next == eof {
			l.next()
			break
		}
	}

	l.emit(tokenEOF)
	return nil
}
1299395
func lexTop(lx *lexer) stateFn {
	r := lx.next()
	if isWhitespace(r) || isNL(r) {
		return lexSkip(lx, lexTop)
	}
	switch r {
	case commentStart:
		lx.push(lexTop)
		return lexCommentStart
	case tableStart:
		return lexTableStart
	case eof:
		if lx.pos > lx.start {
			return lx.errorf("unexpected EOF")
		}
		lx.emit(itemEOF)
		return nil
	}

	// At this point, the only valid item can be a key, so we back up
	// and let the key lexer do the rest.
	lx.backup()
	lx.push(lexTopEnd)
	return lexKeyStart
}
1217863
func LiteralQuoteEscapeBuf(buf *bytes.Buffer, quote rune, literal string) {
	if len(literal) > 1 {
		quoteb := byte(quote)
		if literal[0] == quoteb && literal[len(literal)-1] == quoteb {
			// Already escaped??
			io.WriteString(buf, literal)
			return
		}
	}
	buf.WriteByte(byte(quote))
	escapeQuote(buf, quote, literal)
	if quote == '[' {
		buf.WriteByte(']')
	} else {
		buf.WriteByte(byte(quote))
	}
}
292862
func lexIncludeQuotedString(lx *lexer) stateFn {
	r := lx.next()
	switch {
	case r == sqStringEnd:
		lx.backup()
		lx.emit(itemInclude)
		lx.next()
		lx.ignore()
		return lx.pop()
	}
	return lexIncludeQuotedString
}
900095
func unquoteString(s string) (string, error) {
	ret := new(bytes.Buffer)
	for i := 0; i < len(s); i++ {
		if s[i] == '\\' {
			i++
			if i == len(s) {
				return "", errors.New("Missing a closing quotation mark in string")
			}
			switch s[i] {
			case '"':
				ret.WriteByte('"')
			case 'b':
				ret.WriteByte('\b')
			case 'f':
				ret.WriteByte('\f')
			case 'n':
				ret.WriteByte('\n')
			case 'r':
				ret.WriteByte('\r')
			case 't':
				ret.WriteByte('\t')
			case '\\':
				ret.WriteByte('\\')
			case 'u':
				if i+4 > len(s) {
					return "", errors.Errorf("Invalid unicode: %s", s[i+1:])
				}
				char, size, err := decodeEscapedUnicode(hack.Slice(s[i+1 : i+5]))
				if err != nil {
					return "", errors.Trace(err)
				}
				ret.Write(char[0:size])
				i += 4
			default:
				// For all other escape sequences, backslash is ignored.
				ret.WriteByte(s[i])
			}
		} else {
			ret.WriteByte(s[i])
		}
	}
	return ret.String(), nil
}
206370
func (p *Parser) parseQuote(cur *ListNode, end rune) error {
Loop:
	for {
		switch p.next() {
		case eof, '\n':
			return fmt.Errorf("unterminated quoted string")
		case end:
			//if it's not escape break the Loop
			if p.input[p.pos-2] != '\\' {
				break Loop
			}
		}
	}
	value := p.consumeText()
	s, err := UnquoteExtend(value)
	if err != nil {
		return fmt.Errorf("unquote string %s error %v", value, err)
	}
	cur.append(newText(s))
	return p.parseInsideAction(cur)
}
764322
func lexDubQuotedKey(lx *lexer) stateFn {
	r := lx.peek()
	if r == dqStringEnd {
		lx.emit(itemKey)
		lx.next()
		return lexSkip(lx, lexKeyEnd)
	} else if r == eof {
		if lx.pos > lx.start {
			return lx.errorf("Unexpected EOF.")
		}
		lx.emit(itemEOF)
		return nil
	}
	lx.next()
	return lexDubQuotedKey
}
443207
func parseQuotaSpecImpl(result *api.QuotaSpec, list *ast.ObjectList) error {
	// Check for invalid keys
	valid := []string{
		"name",
		"description",
		"limit",
	}
	if err := helper.CheckHCLKeys(list, valid); err != nil {
		return err
	}

	// Decode the full thing into a map[string]interface for ease
	var m map[string]interface{}
	if err := hcl.DecodeObject(&m, list); err != nil {
		return err
	}

	// Manually parse
	delete(m, "limit")

	// Decode the rest
	if err := mapstructure.WeakDecode(m, result); err != nil {
		return err
	}

	// Parse limits
	if o := list.Filter("limit"); len(o.Items) > 0 {
		if err := parseQuotaLimits(&result.Limits, o); err != nil {
			return multierror.Prefix(err, "limit ->")
		}
	}

	return nil
}
1333930
func quote(unquoted string, triple bool) string {
	q := `"`
	if triple {
		q = `"""`
	}

	var buf bytes.Buffer
	buf.WriteString(q)

	for i := 0; i < len(unquoted); i++ {
		c := unquoted[i]
		if c == '"' && triple && (i+1 < len(unquoted) && unquoted[i+1] != '"' || i+2 < len(unquoted) && unquoted[i+2] != '"') {
			// Can pass up to two quotes through, because they are followed by a non-quote byte.
			buf.WriteByte(c)
			if i+1 < len(unquoted) && unquoted[i+1] == '"' {
				buf.WriteByte(c)
				i++
			}
			continue
		}
		if triple && c == '\n' {
			// Can allow newline in triple-quoted string.
			buf.WriteByte(c)
			continue
		}
		if c == '\'' {
			// Can allow ' since we always use ".
			buf.WriteByte(c)
			continue
		}
		if c == '\\' {
			if i+1 < len(unquoted) && indexByte(notEsc, unquoted[i+1]) >= 0 {
				// Can pass \ through when followed by a byte that
				// known not to be a valid escape sequence and also
				// that does not trigger an escape sequence of its own.
				// Use this, because various BUILD files do.
				buf.WriteByte('\\')
				buf.WriteByte(unquoted[i+1])
				i++
				continue
			}
		}
		if esc[c] != 0 {
			buf.WriteByte('\\')
			buf.WriteByte(esc[c])
			continue
		}
		if c < 0x20 || c >= 0x80 {
			// BUILD files are supposed to be Latin-1, so escape all control and high bytes.
			// I'd prefer to use \x here, but Blaze does not implement
			// \x in quoted strings (b/7272572).
			buf.WriteByte('\\')
			buf.WriteByte(hex[c>>6]) // actually octal but reusing hex digits 0-7.
			buf.WriteByte(hex[(c>>3)&7])
			buf.WriteByte(hex[c&7])
			/*
				buf.WriteByte('\\')
				buf.WriteByte('x')
				buf.WriteByte(hex[c>>4])
				buf.WriteByte(hex[c&0xF])
			*/
			continue
		}
		buf.WriteByte(c)
		continue
	}

	buf.WriteString(q)
	return buf.String()
}
1357448
func lexKeyStart(lx *lexer) stateFn {
	r := lx.peek()
	switch {
	case r == keySep:
		return lx.errorf("unexpected key separator %q", keySep)
	case isWhitespace(r) || isNL(r):
		lx.next()
		return lexSkip(lx, lexKeyStart)
	case r == stringStart || r == rawStringStart:
		lx.ignore()
		lx.emit(itemKeyStart)
		lx.push(lexKeyEnd)
		return lexValue // reuse string lexing
	default:
		lx.ignore()
		lx.emit(itemKeyStart)
		return lexBareKey
	}
}
968351
func Unquote(types ...string) Option {
	if len(types) == 0 {
		types = []string{"String"}
	}
	return Map(func(t lexer.Token) (lexer.Token, error) {
		value, err := unquote(t.Value)
		if err != nil {
			return t, lexer.Errorf(t.Pos, "invalid quoted string %q: %s", t.Value, err.Error())
		}
		t.Value = value
		return t, nil
	}, types...)
}
321988
func lexKeyword(l *lexer) stateFn {
	input := l.input[l.pos:]
	f := func(r rune) bool {
		return !unicode.IsLetter(r)
	}
	if idx := strings.IndexFunc(input, f); idx >= 0 {
		input = input[:idx]
	}
	if strings.EqualFold(input, query) {
		consumeKeyword(l, ItemQuery)
		return lexSpace
	}
	if strings.EqualFold(input, insert) {
		consumeKeyword(l, ItemInsert)
		return lexSpace
	}
	if strings.EqualFold(input, delete) {
		consumeKeyword(l, ItemDelete)
		return lexSpace
	}
	if strings.EqualFold(input, create) {
		consumeKeyword(l, ItemCreate)
		return lexSpace
	}
	if strings.EqualFold(input, construct) {
		consumeKeyword(l, ItemConstruct)
		return lexSpace
	}
	if strings.EqualFold(input, deconstruct) {
		consumeKeyword(l, ItemDeconstruct)
		return lexSpace
	}
	if strings.EqualFold(input, drop) {
		consumeKeyword(l, ItemDrop)
		return lexSpace
	}
	if strings.EqualFold(input, graph) {
		consumeKeyword(l, ItemGraph)
		return lexSpace
	}
	if strings.EqualFold(input, data) {
		consumeKeyword(l, ItemData)
		return lexSpace
	}
	if strings.EqualFold(input, into) {
		consumeKeyword(l, ItemInto)
		return lexSpace
	}
	if strings.EqualFold(input, from) {
		consumeKeyword(l, ItemFrom)
		return lexSpace
	}
	if strings.EqualFold(input, where) {
		consumeKeyword(l, ItemWhere)
		return lexSpace
	}
	if strings.EqualFold(input, as) {
		consumeKeyword(l, ItemAs)
		return lexSpace
	}
	if strings.EqualFold(input, before) {
		consumeKeyword(l, ItemBefore)
		return lexSpace
	}
	if strings.EqualFold(input, after) {
		consumeKeyword(l, ItemAfter)
		return lexSpace
	}
	if strings.EqualFold(input, between) {
		consumeKeyword(l, ItemBetween)
		return lexSpace
	}
	if strings.EqualFold(input, count) {
		consumeKeyword(l, ItemCount)
		return lexSpace
	}
	if strings.EqualFold(input, distinct) {
		consumeKeyword(l, ItemDistinct)
		return lexSpace
	}
	if strings.EqualFold(input, sum) {
		consumeKeyword(l, ItemSum)
		return lexSpace
	}
	if strings.EqualFold(input, group) {
		consumeKeyword(l, ItemGroup)
		return lexSpace
	}
	if strings.EqualFold(input, by) {
		consumeKeyword(l, ItemBy)
		return lexSpace
	}
	if strings.EqualFold(input, order) {
		consumeKeyword(l, ItemOrder)
		return lexSpace
	}
	if strings.EqualFold(input, asc) {
		consumeKeyword(l, ItemAsc)
		return lexSpace
	}
	if strings.EqualFold(input, desc) {
		consumeKeyword(l, ItemDesc)
		return lexSpace
	}
	if strings.EqualFold(input, having) {
		consumeKeyword(l, ItemHaving)
		return lexSpace
	}
	if strings.EqualFold(input, limit) {
		consumeKeyword(l, ItemLimit)
		return lexSpace
	}
	if strings.EqualFold(input, not) {
		consumeKeyword(l, ItemNot)
		return lexSpace
	}
	if strings.EqualFold(input, and) {
		consumeKeyword(l, ItemAnd)
		return lexSpace
	}
	if strings.EqualFold(input, or) {
		consumeKeyword(l, ItemOr)
		return lexSpace
	}
	if strings.EqualFold(input, id) {
		consumeKeyword(l, ItemID)
		return lexSpace
	}
	if strings.EqualFold(input, typeKeyword) {
		consumeKeyword(l, ItemType)
		return lexSpace
	}
	if strings.EqualFold(input, atKeyword) {
		consumeKeyword(l, ItemAt)
		return lexSpace
	}
	if strings.EqualFold(input, inKeyword) {
		consumeKeyword(l, ItemIn)
		return lexSpace
	}
	if strings.EqualFold(input, showKeyword) {
		consumeKeyword(l, ItemShow)
		return lexSpace
	}
	if strings.EqualFold(input, graphsKeyword) {
		consumeKeyword(l, ItemGraphs)
		return lexSpace
	}
	for {
		r := l.next()
		if unicode.IsSpace(r) || r == eof {
			l.backup()
			break
		}
	}
	l.emitError("found unknown keyword")
	return nil
}
832844
func quoteName(w io.Writer, s string) error {
	if _, err := w.Write(astBackquote); err != nil {
		return err
	}
	if _, err := io.WriteString(w, s); err != nil {
		return err
	}
	_, err := w.Write(astBackquote)
	return err
}