Пример #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
        public ImportNode Load(string json)
        {
            ImportNode importNode = new ImportNode();

            importNode = JsonConvert.DeserializeObject <ImportNode>(json);
            return(importNode);
        }
Пример #3
0
        internal ImportNode Compile(ImportModuleHandler importer)
        {
            ImportNode impNode = null;

            foreach (var item in mData)
            {
                SortedSet <Type> types = GetTypesForImport(item.Value.Data);
                foreach (var type in types)
                {
                    if (CLRObjectMarshler.IsMarshaledAsNativeType(type))
                    {
                        continue;
                    }
                    ImportNode node = importer.Import(type.Assembly.Location, type.FullName, "");
                    if (impNode != null && node != null)
                    {
                        impNode.CodeNode.Body.AddRange(node.CodeNode.Body);
                    }
                    else
                    {
                        impNode = node;
                    }
                }
                if (impNode == null)
                {
                    impNode = new ImportNode()
                    {
                        ModuleName = "ExternalContext", CodeNode = new ProtoCore.AST.AssociativeAST.CodeBlockNode()
                    }
                }
                ;
                impNode.CodeNode.Body.Add(ContextDataMethodCallNode(item.Value));
            }
            return(impNode);
        }
 /// <summary>The <see cref="Ast.ImportNode"/> visit implementation</summary>
 /// <param name="importNode">The import AST node</param>
 /// <returns>The modified AST node if modified otherwise the original node</returns>
 public override AstNode VisitImportNode(ImportNode importNode)
 {
     return(new ImportNode(
                importNode.AllowedImportDataType,
                importNode.ImportDataValue,
                importNode.MediaQueries.Select(mediaQueryNode => (MediaQueryNode)mediaQueryNode.Accept(this)).ToSafeReadOnlyCollection()));
 }
Пример #5
0
        public override AstNode VisitImports(ALangParser.ImportsContext context)
        {
            var node = new ImportNode(context);

            node.Path = context.ALANGFILENAME().GetText();
            return(node);
        }
Пример #6
0
            private ImportNode(ImportNode parent, SettingsExporter.Node node)
            {
                this.parent = parent;
                this.node   = node;

                this.arrayExportOptions = ExportableAttribute.ArrayOptions.Immutable | ExportableAttribute.ArrayOptions.Overwrite;
                this.arrayImportOption  = ArrayImportOption.Overwrite;

                this.instanceType = Type.GetType(node.name);

                if (this.instanceType != null)
                {
                    UnityEngine.Object[] instances = Resources.FindObjectsOfTypeAll(this.instanceType);

                    if (instances.Length > 0)
                    {
                        this.instance = instances[0];
                        this.children = new ImportNode[node.children.Count];

                        for (int i = 0; i < this.children.Length; i++)
                        {
                            this.children[i] = new ImportNode(this, node.children[i], this.instanceType, this.instance);
                        }
                    }
                }
            }
Пример #7
0
        public ImportNode Load()
        {
            var path = @"C:\Data\Projects\UmbracoImporter\src\json-site-spec.json";
            //var path = @"D:\MentorDigital-D\Projects\Projects\UmbracoImporter\src\json-site-spec.json";

            ImportNode importNode = new ImportNode();

            using (StreamReader r = new StreamReader(path))
            {
                string json = r.ReadToEnd();

                importNode = JsonConvert.DeserializeObject <ImportNode>(json);
                //dynamic test = JsonConvert.DeserializeObject(json);

                //var dataTypes = test.DataTypes;
                //var ds = JsonConvert.DeserializeObject<DataTypes>(dataTypes.ToString());

                //var documentTypes = test.DocumentTypes;
                //var dt = JsonConvert.DeserializeObject<DocumentTypes>(documentTypes.ToString());

                //var content = test.Content;
                //var cc = JsonConvert.DeserializeObject<Content>(content.ToString());
            }

            return(importNode);
        }
Пример #8
0
        void ParseImport(FileNode filenode)
        {
            while (TryConsume(TokenType.Import))
            {
                var node = new ImportNode();

                node.Name = FetchToken(TokenType.QuotedString, "require file name").Value;

                if (filenode.Import.Exists(x => x.Name == node.Name))
                {
                    Reporter.Error(ErrorType.Parse, _lexer.Loc, "duplicate import filename");
                }

                if (filenode.Name == node.Name)
                {
                    Reporter.Error(ErrorType.Parse, _lexer.Loc, "can not import self");
                }

                var parser = new ProtobufParser();
                parser.Init(_tool);
                parser.StartParseFile(node.Name);

                filenode.Import.Add(node);
                filenode.Add(node);

                Consume(TokenType.SemiColon);
                Consume(TokenType.EOL);
            }
        }
        public IEnumerable <string> Transform(ImportNode item)
        {
            //{% import 'forms.html' as forms %}
            var importObject = Environment.Evaluation.EvaluateDynamic(item.Template, ExpressionParserTransformer);

            if (!(importObject is string importString))
            {
                throw new NotImplementedException();
            }

            if (Environment.TryGetDynamicTemplate(importString, out var template) == false || template == null)
            {
                throw new NotImplementedException();
            }

            var macros = NodeFinderVisitor.FindNodes <MacroNode>(template.TemplateNode);

            foreach (var macro in macros)
            {
                template.AddUserDefinedFunction(ConvertMacroToUserDefinedFunction(macro));
            }

            Scopes.Current.DefineAndSetVariable(item.As, template);
            yield break;
        }
Пример #10
0
 private void Visit(ImportNode node)
 {
     foreach (var module in node.Modules)
     {
         Console.WriteLine($"Import {module}");
     }
 }
        public virtual Value evaluate(Context cx, ImportNode node)
        {
            System.String id    = node.filespec.value_Renamed;
            QName         qname = new QName(cx.publicNamespace(), id);

            output("<ImportNode value=" + qname + "/>");
            return(null);
        }
Пример #12
0
        public XmlElement Visit(ImportNode n)
        {
            var el = makeNode(n, "import");

            addProperty(el, "path", n.Path);
            addProperty(el, "type", n.Type);
            addProperty(el, "name", n.Name);
            return(el);
        }
Пример #13
0
        public void AstNodeShouldAdoptChild()
        {
            var newAstRoot = new CompilationNode();
            var importNode = new ImportNode();

            newAstRoot.AdoptChildren(importNode);
            Assert.IsNotNull(newAstRoot.GetChildren());
            Assert.IsInstanceOf(typeof(ImportNode), newAstRoot.GetChildren());
        }
Пример #14
0
 public virtual void Visit(ImportNode node)
 {
     if (node != null)
     {
         foreach (var specifier in node.Children)
         {
             specifier.Accept(this);
         }
     }
 }
Пример #15
0
        public void VisitImport(ImportNode node)
        {
            string alias = null;

            if (node.Alias != null)
            {
                alias = node.Alias.Value;
            }
            chunk.Imports.Add(new Import(node.Path.Value, alias));
        }
Пример #16
0
        public ImportNode MockImportJson()
        {
            ImportNode root = jsonParser.Load();

            //_documentTypeImporter.Import(root.DocumentTypes);
            _dataTypeImporter.Import(root.DataTypes);

            _contentImporter.Import(root.Content);

            return(root);
        }
            private Namespace TryGetNamespace(ImportNode arg)
            {
                Namespace ns;

                if (_allNamespaces.TryGetValue(arg.Module, out ns))
                {
                    return(ns);
                }

                throw new NamespaceNotFoundException(arg);
            }
Пример #18
0
    public void ImportFromFile()
    {
        var nodes = StyleParser.Parse(@"
            import ""mypath/to/myfile"" as myconsts;
        ");

        Assert.AreEqual(1, nodes.Count);
        ImportNode importNode = (ImportNode)nodes[0];

        Assert.AreEqual("myconsts", importNode.alias);
        Assert.AreEqual("mypath/to/myfile", importNode.source);
    }
Пример #19
0
            public ImportNode(SettingsExporter.Node node)
            {
                this.parent = null;
                this.node   = node;

                this.instance     = null;
                this.instanceType = null;

                this.children = new ImportNode[node.children.Count];
                for (int i = 0; i < this.children.Length; i++)
                {
                    this.children[i] = new ImportNode(this, node.children[i]);
                }
            }
Пример #20
0
        public ImportNode ImportJson(string json)
        {
            ImportNode root = jsonParser.Load(json);

            _documentTypeImporter.Import(root.DocumentTypes);

            _dataTypeImporter.Import(root.DataTypes);

            _contentImporter.Import(root.Content);

            //var parsed = JsonConvert.SerializeObject(root);
            //return new[] { parsed };
            return(root);
        }
Пример #21
0
        /// <summary>
        ///     Executes a using statement.
        /// </summary>
        public ScopeContext ExecuteUsing(ImportNode node, ScopeContext scopeContext)
        {
            var Object = ExecuteExpression(node.Getter, scopeContext);

            // Add all public variables from object as variables to scope.
            foreach (var property in Object.Properties)
            {
                if ((property.Modifiers & Modifier.Public) != 0)
                {
                    scopeContext.SetVariable(property.Name, property.Value, Modifier.Const);
                }
            }

            return(scopeContext);
        }
Пример #22
0
        public override void Print(ImportNode node, StringBuilder sb, PrintOption opt, params object[] values)
        {
            string fileName;

            if (node.Name.EndsWith(".pf"))
            {
                fileName = node.Name;
            }
            else
            {
                fileName = Path.GetFileNameWithoutExtension(node.Name) + ".pf";
            }


            sb.AppendFormat("import \"{0}\"\n", fileName);
        }
Пример #23
0
        public void MakeSiblingsShouldAssignCorrectParent()
        {
            var newAstRoot = new CompilationNode();
            var node       = new ImportNode();

            newAstRoot.AdoptChildren(node);

            var node2 = new ImportNode();
            var node3 = new ImportNode();

            node = (ImportNode)node.MakeSiblings(node2.MakeSiblings(node3));

            Assert.AreSame(newAstRoot, node.Parent);
            Assert.AreSame(newAstRoot, node2.Parent);
            Assert.AreSame(newAstRoot, node3.Parent);
        }
Пример #24
0
        public void MakeSiblingShouldChainSiblings()
        {
            var newAstRoot = new CompilationNode();
            var node       = new ImportNode();

            newAstRoot.AdoptChildren(node);

            var node2 = new ImportNode();
            var node3 = new ImportNode();

            node = (ImportNode)node.MakeSiblings(node2.MakeSiblings(node3));

            Assert.AreSame(node, node2.LeftMostSibling);
            Assert.AreSame(node2, node.RightSibling);
            Assert.AreSame(node, node3.LeftMostSibling);
            Assert.AreSame(node3, node2.RightSibling);
        }
Пример #25
0
            /// <summary>
            /// Checks if a parent is being added, excluding root, fields and immutables nodes.
            /// </summary>
            /// <returns></returns>
            public bool     HasParentAddImportOption()
            {
                ImportNode n = this.parent;

                while (n != null)
                {
                    if (n.parent != null &&                     // Remove options from root and fields,
                        n.fieldInfo == null &&                  // they can only be overwritten.
                        (n.arrayExportOptions & ExportableAttribute.ArrayOptions.Immutable) == 0 &&
                        n.arrayImportOption == ArrayImportOption.Add)
                    {
                        return(true);
                    }

                    n = n.parent;
                }

                return(false);
            }
Пример #26
0
        private ImportNode ParseImport()
        {
            Expect(TokenType.IMPORT);
            Next();

            var import = new ImportNode(Position(-1), ParseString());

            Expect(TokenType.AS, TokenType.SEMICOLON);
            if (Accept(TokenType.AS))
            {
                Next();
                import.Alias = ParseIdent();
            }

            Expect(TokenType.SEMICOLON);
            Next();

            return(import);
        }
Пример #27
0
        public void ChunkNodesHaveImports()
        {
            var imports = new List <ImportNode>();

            for (var i = 0; i < 5; i++)
            {
                var import = new ImportNode(SourcePosition.NIL, new StringNode(SourcePosition.NIL, "foo/bar" + i));
                import.Alias = new IdentNode(SourcePosition.NIL, "bar" + i);
                imports.Add(import);
            }

            foreach (var import in imports)
            {
                subject.Imports.Add(import);
            }

            for (var i = 0; i < subject.Imports.Count; i++)
            {
                Assert.AreEqual(subject.Imports[i], imports[i]);
            }
        }
Пример #28
0
        /// <summary>The <see cref="ImportNode"/> visit implementation</summary>
        /// <param name="importNode">The attribute AST node</param>
        /// <returns>The modified AST node if modified otherwise the original node</returns>
        public override AstNode VisitImportNode(ImportNode importNode)
        {
            // import
            // : IMPORT_SYM S*
            // [STRING|URI] S* media_list? Semicolon S*
            // ;
            // media_list
            // : medium [ COMMA S* medium]*
            // ;

            // : IMPORT_SYM S* [STRING|URI]
            _printerFormatter.Append(CssConstants.Import);

            switch (importNode.AllowedImportDataType)
            {
            case AllowedImportData.String:
            case AllowedImportData.Uri:
                _printerFormatter.Append(importNode.ImportDataValue);
                break;
            }

            // medium [ COMMA S* medium]*
            if (importNode.MediaQueries.Count > 0)
            {
                _printerFormatter.Append(CssConstants.SingleSpace);
                importNode.MediaQueries.ForEach((mediaQuery, last) =>
                {
                    mediaQuery.Accept(this);
                    if (!last)
                    {
                        _printerFormatter.Append(CssConstants.Comma);
                    }
                });
            }

            // append for: Semicolon S*
            _printerFormatter.AppendLine(CssConstants.Semicolon);

            return(importNode);
        }
Пример #29
0
        private void ImportTreeToConfig(ImportNode tree, RepositoryNode target, OverwriteAction action)
        {
            foreach (var entry in tree.SubNodes)
            {
                if (entry.Type == EntryType.Folder)
                {
                    if (!target.TryGetFolder(entry.Name, out var folderNode))
                    {
                        folderNode = target.AddItem(EntryType.Folder, entry.Name);
                    }

                    ImportTreeToConfig(entry, folderNode, action);
                }
                else if (entry.Type == EntryType.Template)
                {
                    if (target.TryGetFile(entry.Name, out var fileNode))
                    {
                        switch (action)
                        {
                        case OverwriteAction.OverwriteAll:
                            fileNode.Content = File.ReadAllText(entry.Path);
                            break;

                        case OverwriteAction.SkipAll:
                            break;

                        case OverwriteAction.PromptEvery:
                            // TODO: prompt user for file overwriting
                            break;
                        }
                    }
                    else
                    {
                        target.AddItem(EntryType.Template, entry.Name, File.ReadAllText(entry.Path));
                    }
                }
            }
        }
Пример #30
0
        public override ModuleNode Execute(List <Token> tokens)
        {
            int index = 0;

            var module = new ModuleNode();

            while (index < tokens.Count)
            {
                var token = tokens[index];
                index++;

                if (token.text == "using")
                {
                    var node = new ImportNode(module);
                    node.reference = ExpectIdentifier(tokens, ref index, true);
                    ExpectDelimiter(tokens, ref index, ";");
                }
                else
                if (token.text == "namespace")
                {
                    var namespaceID = ExpectIdentifier(tokens, ref index, true);

                    ExpectDelimiter(tokens, ref index, "{");

                    ParseNamespaceContent(tokens, ref index, module);

                    ExpectDelimiter(tokens, ref index, "}");
                }
                else
                {
                    throw new ParserException(token, ParserException.Kind.UnexpectedToken);
                }
            }

            return(module);
        }
		public virtual Value evaluate(Context cx, ImportNode node)
		{
			System.String id = node.filespec.value_Renamed;
			QName qname = new QName(cx.publicNamespace(), id);
			output("<ImportNode value=" + qname + "/>");
			return null;
		}
        private void EmitImportNode(ImportNode node, out AssociativeNode outnode)
        {
            Validity.Assert(node != null);

            ProtoCore.AST.AssociativeAST.ImportNode importNode = null;

            importNode = new ProtoCore.AST.AssociativeAST.ImportNode();
            importNode.ModuleName = node.ModuleName;

            //(AstRootNode as CodeBlockNode).Body.Add(importNode);
            outnode = importNode;
        }