Inheritance: CiSymbol
Exemplo n.º 1
0
        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());
            }
        }
Exemplo n.º 2
0
        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);
        }
Exemplo n.º 3
0
 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();
 }
Exemplo n.º 4
0
 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();
 }
Exemplo n.º 5
0
 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);
     }
 }
Exemplo n.º 6
0
 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);
     }
 }
Exemplo n.º 7
0
        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);
        }
Exemplo n.º 8
0
 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();
 }
Exemplo n.º 9
0
Arquivo: CiParser.cs Projeto: epi/cito
 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;
 }
Exemplo n.º 10
0
        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());
            }
        }