protected virtual void WriteConst(object value) { if (value is bool) { Write((bool)value ? "true" : "false"); } else if (value is byte) { Write((byte)value); } else if (value is int) { Write((int)value); } else if (value is string) { Write('"'); foreach (char c in (string)value) { switch (c) { case '\t': Write("\\t"); break; case '\r': Write("\\r"); break; case '\n': Write("\\n"); break; case '\\': Write("\\\\"); break; case '\"': Write("\\\""); break; default: Write(c); break; } } Write('"'); } else if (value is CiEnumValue) { CiEnumValue ev = (CiEnumValue)value; Write(ev.Type.Name); Write('.'); Write(ev.Name); } else if (value is Array) { Write("{ "); WriteContent((Array)value); Write(" }"); } else if (value == null) { Write("null"); } else { throw new ArgumentException(value.ToString()); } }
public override CiSymbol LookupMember(string name) { CiEnumValue value = this.Values.SingleOrDefault(v => v.Name == name); if (value == null) { throw new ParseException("{0} not found in enum {1}", name, this.Name); } return(value); }
void ICiSymbolVisitor.Visit(CiEnum enu) { CreateAsFile(enu); Write("class "); WriteLine(enu.Name); OpenBlock(); for (int i = 0; i < enu.Values.Length; i++) { CiEnumValue value = enu.Values[i]; Write(value.Documentation); Write("public static const "); WriteUppercaseWithUnderscores(value.Name); Write(" : int = "); Write(i); WriteLine(";"); } CloseAsFile(); }
void ICiSymbolVisitor.Visit(CiEnum enu) { CreateJavaFile(enu); Write("interface "); WriteLine(enu.Name); OpenBlock(); for (int i = 0; i < enu.Values.Length; i++) { CiEnumValue value = enu.Values[i]; Write(value.Documentation); Write("int "); WriteUppercaseWithUnderscores(value.Name); Write(" = "); Write(i); WriteLine(";"); } CloseJavaFile(); }
protected override void WriteConst(object value) { if (value is byte) { Write((sbyte)(byte)value); } else if (value is CiEnumValue) { CiEnumValue ev = (CiEnumValue)value; Write(ev.Type.Name); Write('.'); WriteUppercaseWithUnderscores(ev.Name); } else { base.WriteConst(value); } }
protected override void WriteConst(object value) { if (value is CiEnumValue) { CiEnumValue ev = (CiEnumValue)value; Write(ev.Type.Name); Write('.'); WriteUppercaseWithUnderscores(ev.Name); } else if (value is Array) { Write("[ "); WriteContent((Array)value); Write(" ]"); } else { base.WriteConst(value); } }
CiEnum ParseEnum() { CiEnum enu = new CiEnum(); Expect(CiToken.Enum); enu.Name = ParseId(); Expect(CiToken.LeftBrace); List <CiEnumValue> values = new List <CiEnumValue>(); do { CiEnumValue value = new CiEnumValue(); value.Documentation = ParseDoc(); value.Name = ParseId(); value.Type = enu; values.Add(value); } while (Eat(CiToken.Comma)); Expect(CiToken.RightBrace); enu.Values = values.ToArray(); return(enu); }
void Write(CiEnum enu) { WriteLine(); Write(enu.Documentation); Write("var "); Write(enu.Name); Write(" = "); OpenBlock(); for (int i = 0; i < enu.Values.Length; i++) { if (i > 0) { WriteLine(","); } CiEnumValue value = enu.Values[i]; Write(value.Documentation); WriteUppercaseWithUnderscores(value.Name); Write(" : "); Write(i); } WriteLine(); CloseBlock(); }
CiEnum ParseEnum() { CiEnum enu = new CiEnum(); Expect(CiToken.Enum); enu.Name = ParseId(); Expect(CiToken.LeftBrace); List<CiEnumValue> values = new List<CiEnumValue>(); do { CiEnumValue value = new CiEnumValue(); value.Documentation = ParseDoc(); value.Name = ParseId(); value.Type = enu; values.Add(value); } while (Eat(CiToken.Comma)); Expect(CiToken.RightBrace); enu.Values = values.ToArray(); return enu; }
protected override void WriteConst(object value) { if (value is bool) { Write((bool)value ? '1' : '0'); } else if (value is byte) { Write((byte)value); } else if (value is int) { Write((int)value); } else if (value is string) { Write('"'); foreach (char c in (string)value) { switch (c) { case '\t': Write("\\t"); break; case '\r': Write("\\r"); break; case '\n': Write("\\n"); break; case '\\': Write("\\\\"); break; case '\"': Write("\\\""); break; case '$': Write("\\$"); break; case '@': Write("\\@"); break; default: Write(c); break; } } Write('"'); } else if (value is CiEnumValue) { CiEnumValue ev = (CiEnumValue)value; Write(ev.Type.Name); Write("::"); WriteUppercaseWithUnderscores(ev.Name); Write("()"); } else if (value is Array) { Write("( "); WriteContent((Array)value); Write(" )"); } else if (value == null) { Write("undef"); } else { throw new ArgumentException(value.ToString()); } }