Ejemplo n.º 1
0
 public static void PrintCodeUnit(PrintState s, CodeUnit u)
 {
     foreach (var it in u.Contents)
     {
         PrintAny(s, it);
     }
 }
Ejemplo n.º 2
0
 public static void AddUnit(Program p, CodeUnit u)
 {
     foreach (var it in u.Contents)
     {
         AddItem(p.Top, it);
     }
 }
Ejemplo n.º 3
0
        public static CodeUnit Parse(string filename, string source)
        {
            var s = new ParserState {
                Source = source + "\0", Index = 0
            };
            var unit = new CodeUnit {
                Filename = filename, Source = s.Source, Contents = new List <object>()
            };

            s.Unit = unit;
            ReadToken(s);
            while (s.Token.Type != TokenType.End)
            {
                if (s.Token.Type == TokenType.Identifier)
                {
                    var id = s.Token;
                    ReadToken(s);
                    if (s.Token.Type == TokenType.OpenBrace || s.Token.Type == TokenType.Identifier)
                    {
                        unit.Contents.Add(ParseNamespaceTail(s, id));
                    }
                    else if (s.Token.Type == TokenType.OpenParen)
                    {
                        unit.Contents.Add(ParseFunctionTail(s, null, id));
                    }
                    else if (s.Token.Type == TokenType.OpenAngleBracket)
                    {
                        if (IsProbablyANamespace(id.Value))
                        {
                            unit.Contents.Add(ParseNamespaceTail(s, id));
                        }
                        else
                        {
                            unit.Contents.Add(ParseFunctionTail(s, null, id));
                        }
                    }
                    else
                    {
                        Expected(s, "(, { or <");
                    }
                }
                else if (s.Token.Type == TokenType.Colon)
                {
                    unit.Contents.Add(ParseStaticField(s, null));
                }
                else
                {
                    Expected(s, "Top-level declaration");
                }
            }
            return(unit);
        }
Ejemplo n.º 4
0
 public static void CheckCodeUnit(RangeFinderState s, CodeUnit a)
 {
     CheckList(s, a.Contents);
 }