package d2format

import (
	

	
)

// FormatKeyPath formats the scalar values in a as a canonical key path, like
// Format(d2ast.MakeKeyPathString(a)), without building a temporary key path AST.
// Quoting in the input nodes is intentionally ignored, just as in MakeKeyPathString.
func ( []d2ast.String) string {
	 := printer{inKey: true}
	for ,  := range  {
		if  > 0 {
			.sb.WriteByte('.')
		}
		 := .ScalarString()
		// The exported specials set can be customized by callers.
		if plainKey() && !strings.ContainsAny(, d2ast.UnquotedKeySpecials) {
			 := strings.ToLower()
			if  == "null" {
				.sb.WriteString("'null'")
			} else if ,  := d2ast.ReservedKeywords[];  {
				.sb.WriteString()
			} else {
				.sb.WriteString()
			}
		} else {
			.node(d2ast.RawString(, true))
		}
	}
	return .sb.String()
}

// Keep the fast path deliberately narrow. Other strings use the regular
// formatter's quoting, escaping, Unicode, and invalid UTF-8 handling.
func plainKey( string) bool {
	if  == "" {
		return false
	}
	for  := 0;  < len(); ++ {
		 := []
		if  >= 'a' &&  <= 'z' ||  >= 'A' &&  <= 'Z' ||  >= '0' &&  <= '9' ||  == '_' {
			continue
		}
		return false
	}
	return true
}