// WriteLiteral writes literal with escapes if needed
540402
func (w *defaultDialect) WriteLiteral(l string) {
	if len(l) == 1 && l == "*" {
		w.WriteByte('*')
		return
	}
	LiteralQuoteEscapeBuf(&w.Buffer, rune(w.LiteralQuote), l)
}
584634
func (ar *atRule) WriteTo(w io.Writer) (int64, error) {
	bf := new(bytes.Buffer)

	bf.WriteString(strings.TrimSpace(ar.ln.s))

	if len(ar.sels) == 0 && len(ar.decs) == 0 && !ar.hasMixinDecs() && !ar.hasMixinSels() {
		bf.WriteString(semicolon)
		n, err := w.Write(bf.Bytes())
		return int64(n), err
	}

	bf.WriteString(openBrace)

	// Writing to the bytes.Buffer never returns an error.
	ar.writeDecsTo(bf, nil)

	for _, sel := range ar.sels {
		// Writing to the bytes.Buffer never returns an error.
		sel.WriteTo(bf)
	}

	// Write the mixin's selectors.
	for _, mi := range ar.mixins {
		sels, prms := mi.selsParams()

		for _, sl := range sels {
			sl.parent = ar
			// Writing to the bytes.Buffer never returns an error.
			sl.writeTo(bf, prms)
		}
	}

	bf.WriteString(closeBrace)

	n, err := w.Write(bf.Bytes())

	return int64(n), err
}
303619
func SignLiteral(payload []byte, alg jwa.SignatureAlgorithm, key interface{}, headers []byte) ([]byte, error) {

	signer, err := sign.New(alg)
	if err != nil {
		return nil, errors.Wrap(err, `failed to create signer`)
	}

	var buf bytes.Buffer
	enc := base64.NewEncoder(base64.RawURLEncoding, &buf)
	if _, err := enc.Write(headers); err != nil {
		return nil, errors.Wrap(err, `failed to write headers as base64`)
	}
	if err := enc.Close(); err != nil {
		return nil, errors.Wrap(err, `failed to finalize writing headers as base64`)
	}

	buf.WriteByte('.')
	enc = base64.NewEncoder(base64.RawURLEncoding, &buf)
	if _, err := enc.Write(payload); err != nil {
		return nil, errors.Wrap(err, `failed to write payload as base64`)
	}
	if err := enc.Close(); err != nil {
		return nil, errors.Wrap(err, `failed to finalize writing payload as base64`)
	}

	signature, err := signer.Sign(buf.Bytes(), key)
	if err != nil {
		return nil, errors.Wrap(err, `failed to sign payload`)
	}

	buf.WriteByte('.')
	enc = base64.NewEncoder(base64.RawURLEncoding, &buf)
	if _, err := enc.Write(signature); err != nil {
		return nil, errors.Wrap(err, `failed to write signature as base64`)
	}
	if err := enc.Close(); err != nil {
		return nil, errors.Wrap(err, `failed to finalize writing signature as base64`)
	}

	return buf.Bytes(), nil
}
463424
func NewNumberLiteral(pos int, line int, val float64, isInt bool, original string) *NumberLiteral {
	return &NumberLiteral{
		NodeType: NodeNumber,
		Loc:      Loc{pos, line},

		Value:    val,
		IsInt:    isInt,
		Original: original,
	}
}
129655
func (s *numericCompilerVisitor) AcceptNumericLiteral(v tree.NumericLiteral) {
	s.ctx.op(OP_LOAD_VAL, uint32(v.Value))
}
986038
func ReplaceLiteral(expression, replacement, input string) (string, error) {
	re, err := stdre.Compile(expression)
	if err != nil {
		return "", err
	}
	return re.ReplaceAllLiteralString(input, replacement), nil
}
624219
func isTrueLiteral(expr Expr) bool {
	if expr, ok := expr.(*BooleanLiteral); ok {
		return expr.Val == true
	}
	return false
}
1016429
func (d *decodeState) literalInterface() (interface{}, error) {
	// All bytes inside literal return scanContinue op code.
	start := d.off - 1
	op := d.scanWhile(scanContinue)

	// Scan read one byte too far; back up.
	d.off--
	d.scan.undo(op)
	item := d.data[start:d.off]

	switch c := item[0]; c {
	case 'n': // null
		return nil, nil

	case 't', 'f': // true, false
		return c == 't', nil

	case '"': // string
		s, ok := unquote(item)
		if !ok {
			return nil, errPhase
		}
		return s, nil

	default: // number
		if c != '-' && (c < '0' || c > '9') {
			return nil, errPhase
		}
		n, err := d.convertNumber(string(item))
		if err != nil {
			return nil, err
		}
		return n, nil
	}
}
615843
func (sv *StringVisitor) AcceptNumericLiteral(v NumericLiteral) {
	sv.result += fmt.Sprintf("%d", v.Value)
}
445169
func (l *Literal) Text() (string, error) {
	if l.t != Text {
		return "", fmt.Errorf("literal.Text: literal is of type %v; cannot be converted to a string", l.t)
	}
	return l.v.(string), nil
}
572583
func (f *field) escape() field {
	pos := 0
	for i := 0; i < len(f.str); i++ {
		c := f.str[i]
		if i+1 < len(f.str) && f.str[i] == '\\' {
			c = f.escapeChar(f.str[i+1])
			i++
		}

		f.str[pos] = c
		pos++
	}
	return field{f.str[:pos], f.maybeNull, f.enclosed}
}
567932
func (s *booleanCompilerVisitor) AcceptBooleanLiteral(v tree.BooleanLiteral) {
	if s.topLevel {
		s.ctx.unconditionalJumpTo(s.jt)
	} else {
		s.err = errors.New("a boolean literal was found in an expression - this is likely a programmer error")
	}
}
45255
func ToLiteral(ce ConsumedElement) (*literal.Literal, error) {
	if ce.IsSymbol() {
		return nil, fmt.Errorf("semantic.ToLiteral cannot convert symbol %v to a literal", ce)
	}
	tkn := ce.Token()
	if tkn.Type != lexer.ItemLiteral {
		return nil, fmt.Errorf("semantic.ToLiteral cannot convert token type %s to a literal", tkn.Type)
	}
	return literal.DefaultBuilder().Parse(tkn.Text)
}
1321210
func PrepareSelfWrite(msg SelfWriteMessage) (string, error) {
	buf, err := json.Marshal(msg)
	if err != nil {
		return "", err
	}
	return string(buf), nil
}
554136
func CloneRegexLiteral(r *RegexLiteral) *RegexLiteral {
	if r == nil {
		return nil
	}

	clone := &RegexLiteral{}
	if r.Val != nil {
		clone.Val = regexp.MustCompile(r.Val.String())
	}

	return clone
}
1128757
func (l *StringLiteral) ToTimeLiteral(loc *time.Location) (*TimeLiteral, error) {
	if loc == nil {
		loc = time.UTC
	}

	if isDateTimeString(l.Val) {
		t, err := time.ParseInLocation(DateTimeFormat, l.Val, loc)
		if err != nil {
			// try to parse it as an RFCNano time
			t, err = time.ParseInLocation(time.RFC3339Nano, l.Val, loc)
			if err != nil {
				return nil, ErrInvalidTime
			}
		}
		return &TimeLiteral{Val: t}, nil
	} else if isDateString(l.Val) {
		t, err := time.ParseInLocation(DateFormat, l.Val, loc)
		if err != nil {
			return nil, ErrInvalidTime
		}
		return &TimeLiteral{Val: t}, nil
	}
	return nil, ErrInvalidTime
}
887224
func (t *typeChecker) AcceptBooleanLiteral(v tree.BooleanLiteral) {
	if !t.expectBoolean {
		t.result = fmt.Errorf("expected numeric expression but found: %s", tree.ExpressionString(v))
	}
}