namespace Eva { public class Atom : Object, Term { public string value {get; construct;} public Atom(string v) { assert(v.validate()); Object(value: v); } public string to_string() { if(value.length == 0) return "''"; bool special = false; unichar c = value.get_char(); if(!c.islower()) special = true; for(unowned string rest = value.next_char(); rest.length != 0 && !special; rest = rest.next_char()) { c = rest.get_char(); if(!(c == '_' || c.isalnum())) special = true; } if(!special) { return value; } else { return "'" + value.replace("\\", "\\\\").replace("'", "\\'") + "'"; } } protected bool do_match(Term o, Gee.Map vars, Gee.Map aliases) { if(o is Var) { return o.do_match(this, vars, aliases); } if(o is Atom) { return value == (o as Atom).value; } else { return false; } } internal void encode(Buffer buffer) { char[]? array = string_to_binary(value); assert(array != null); buffer.buffer.encode_atom(array); } } }