Пример #1
0
        public override Word Visit(ImportNode importNode)//chapuz bajo: NO retorna nada nunca para que no tengamos que hacer otra clase que herrede de Word, Este metodo como tal se encarga de agregar a sus imports
        {
            string path = ((MyString)importNode.Path.Accept(this)).StringValue;

            if (path.Length < 1)
            {
                return(ErrorFactory.PathNotValid(importNode.Path, path));
            }
            if ((path[0] != Path.DirectorySeparatorChar) || (path[0] != 'C' && path[0] != 'D' && path[1] != ':'))//tiene que agregar al path la ruta del archivo con el que este nodo fue creado
            {
                path = importNode.NodePath.GetParentPath() + Path.DirectorySeparatorChar + PyPath.ReplaceSepartors(path);
            }
            if (!File.Exists(path))
            {
                ErrorFactory.FileNotFound(importNode, path);
                return(null);
            }

            var import = CreateStaticEntity(path);

            if (import == null)
            {
                ErrorFactory.SyntaxErrorInImport(importNode, path);
                return(null);
            }
            StaticEntity.AddImport(import);

            return(null);
        }
Пример #2
0
        /// <summary>
        /// retorna null si ocurrio un error al leer el archivo.
        /// </summary>
        /// <param name="path"></param>
        /// <returns></returns>
        private StaticEntity CreateStaticEntity(string path)
        {
            var src       = File.ReadAllText(path);
            var grammar   = new PyUsacGrammar();
            var langData  = new LanguageData(grammar);
            var parser    = new Irony.Parsing.Parser(langData);//Para evitar conflicto con el namespace Parser
            var parseTree = parser.Parse(src);

            bool hasErrors = false;

            foreach (var error in parseTree.ParserMessages)
            {
                if (error.Level == Irony.ErrorLevel.Error)
                {
                    hasErrors = true;
                }
                ErrorFactory.CreateParsingError(error, path);
            }
            if (hasErrors)
            {
                return(null);
            }

            var astBuilder = new PyAstBuilder(new AstContext(langData), path);

            astBuilder.BuildAst(parseTree);
            var programNode = (ProgramNode)parseTree.Root.AstNode;

            var entity = new StaticEntity(programNode);

            entity.InitVisitor(true);

            return(entity);
        }
        public void AddImport(StaticEntity import)
        {
            if (import is null)
            {
                throw new ArgumentNullException(nameof(import));
            }

            Imports.Add(import);
        }
Пример #4
0
 public InstanceVisitor(StaticEntity entity, ClassNode classNode)
 {
     StaticEntity = entity;
     classNode.Accept(this);
 }
Пример #5
0
 public StaticVisitor(StaticEntity staticEntity)
 {
     StaticEntity = staticEntity;
 }