Пример #1
0
        public static IExpression Parse(IEnumerator <TokenData> tokens, IContext parentContext, ref bool done)
        {
            if (!tokens.MoveNext())
            {
                done = true;
            }
            if (done)
            {
                return(null);
            }
            var moduleDecl = new ModuleDeclaration();
            var token      = tokens.Current;

            #region Identifier

            var identifiers = (ILocalIdentifierScope) new LocalIdentifierScope();
            if (token.Type == Token.IdentifierLiteral)
            {
                moduleDecl.Name = ((IIdentifierLiteral)token.Data).Content;
                identifiers     = parentContext.AddModule(moduleDecl);
                if (!tokens.MoveNext())
                {
                    done = true;
                }
                if (done)
                {
                    return(moduleDecl);      // fully forward declared
                }
                token = tokens.Current;
            }

            #endregion

            #region Body

            if (token.Type == Token.BlockStartIndentation)
            {
                var context = new Context(identifiers, new LocalValueScope())
                {
                    Parent = parentContext
                };
                var contentBlock = (BlockLiteral)token.Data;
                moduleDecl.Block = Parser.ParseBlockWithContext(contentBlock, context);
                if (!tokens.MoveNext())
                {
                    done = true;
                }
                if (done)
                {
                    return(moduleDecl);
                }
            }

            #endregion

            return(moduleDecl);
        }
Пример #2
0
        /*
         * Protected.
         */

        protected void AddModule <T>() where T : IModule, new()
        {
            _context.AddModule <T>();
        }