public Assigned assigned_transitive(Object variable) { Assigned a = assigned(variable); if (a != null) { return(a); } if (zuper != null) { return(zuper.assigned_transitive(variable)); } return(null); }
public Object assign(Object variable, Value value, bool is_final) { Assigned t = assigned(variable); Value a = t != null ? t.value : null; // Existing value if (a != null && a != value && variable != this) { throw new System.ArgumentException(pathname() + zuper_name() + " cannot have two assignments to " + variable.pathname()); } if (variable.is_syntax) { syntax = value as RegexValue; return(variable); // Not used, but flags that we succeeded } else { return(new Assignment(this, variable, value, is_final)); } }
private Object assignment(Object variable) { string op; if ((op = expect("equals")) != null || (op = expect("approx")) != null) { bool is_final = op == "="; opt_white(); Object parent = context.stacktop; Assigned existing = parent.assigned(variable); if (existing != null) { error("Cannot reassign " + parent.name + "." + variable.name + " from " + existing.ToString()); } Object controlling_syntax = variable; Object refine_from = null; Value val; if (variable.is_syntax) { // Parse a Regular Expression string regexp_string = expect("regexp"); List <string> path_with_syntax; Object existing_object; Assigned assigned_syntax; if (regexp_string != null) { val = new RegexValue(regexp_string); } else if ((path_with_syntax = path_name()) != null && (existing_object = @context.resolve_name(path_with_syntax)) != null && (assigned_syntax = existing_object.assigned(@context.syntax)) != null ) { val = assigned_syntax.value as RegexValue; } else { error("Assignment to Syntax variable requires a regular expression"); val = null; // Will not be reached, but prevents compile error } } else { if (variable.is_reference) { Assigned overriding = parent.assigned_transitive(variable); if (overriding == null) { overriding = variable.assigned(variable); } if (overriding != null && overriding.final) // Final { if (overriding.value is ArrayValue) // the Value is an array { refine_from = ((overriding.value as ArrayValue).element(0) as ObjectValue).obj; } else { refine_from = (overriding.value as ObjectValue).obj; } } // Otherwise just refine_from Object if (refine_from == null) { List <Object> st = parent.supertypes; refine_from = st[st.Count - 1]; } } else { if (variable.supertypes.Contains(variable.parent) && parent.supertypes.Contains(variable.parent)) { controlling_syntax = parent; } existing = parent.assigned_transitive(variable); if (existing == null) { existing = variable.assigned(variable); } if (existing != null && existing.final) // Is Final { error("Cannot override final assignment " + parent.name + "." + variable.name + "=" + existing.ToString()); } } val = parse_value(controlling_syntax, refine_from); } return(parent.assign(variable, val, is_final)); } return(null); }