package bibtex import ( "bytes" "strconv" "strings" ) type Literal interface{} type BraceLiteral string type StringLiteral string type NumberLiteral int type VariableLiteral struct { Name string Value *Value } func Marshal(l Literal) (res string) { switch v := l.(type) { case BraceLiteral: res = "{" + string(v) + "}" case StringLiteral: res = "\"" + string(v) + "\"" case NumberLiteral: res = strconv.Itoa(int(v)) case VariableLiteral: res = v.Name } return } type Value []Literal func (v Value) Marshal() string { res := make([]string, len(v)) for i, l := range v { res[i] = Marshal(l) } return strings.Join(res, " # ") } func (v Value) String() string { var buf bytes.Buffer for _, l := range v { switch lit := l.(type) { case BraceLiteral: buf.WriteString(string(lit)) case StringLiteral: buf.WriteString(string(lit)) case NumberLiteral: buf.WriteString(strconv.Itoa(int(lit))) case VariableLiteral: buf.WriteString(lit.Value.String()) } } return buf.String() } type Entry struct { Type string Key string Fields map[string]Value FNames []string } type Database struct { SNames []string Strings map[string]Value Entries map[string]Entry Preamble Value EKeys []string }