Example #1
0
        // import_stmt: 'import' module ['as' name"] (',' module ['as' name])*
        // name: identifier
        private ImportStatement ParseImportStmt()
        {
            Eat(TokenKind.KeywordImport);
            string whitespace = _tokenWhiteSpace;
            var start = GetStart();

            List<string> asNameWhiteSpace = MakeWhiteSpaceList();
            List<ModuleName> l = new List<ModuleName>();
            List<NameExpression> las = new List<NameExpression>();
            var modName = ParseModuleName();
            var commaWhiteSpace = MakeWhiteSpaceList();
            if (modName.Names.Count > 0) {
                l.Add(modName);
                las.Add(MaybeParseAsName(asNameWhiteSpace));
                while (MaybeEat(TokenKind.Comma)) {
                    if (commaWhiteSpace != null) {
                        commaWhiteSpace.Add(_tokenWhiteSpace);
                    }
                    l.Add(ParseModuleName());
                    las.Add(MaybeParseAsName(asNameWhiteSpace));
                }
            }
            ModuleName[] names = l.ToArray();
            var asNames = las.ToArray();

            ImportStatement ret = new ImportStatement(names, asNames, AbsoluteImports);
            if (_verbatim) {
                AddListWhiteSpace(ret, commaWhiteSpace.ToArray());
                AddNamesWhiteSpace(ret, asNameWhiteSpace.ToArray());
                AddPreceedingWhiteSpace(ret, whitespace);
            }
            ret.SetLoc(start, GetEnd());
            return ret;
        }
Example #2
0
 public UpdatedImportStatement(ImportStatement import)
 {
     _import = import;
 }
Example #3
0
 // ImportStmt
 public override bool Walk(ImportStatement node)
 {
     for (int i = 0; i < node.Names.Count; i++) {
         if (node.AsNames[i] != null) {
             Define(node.AsNames[i].Name);
         } else if (node.Names[i].Names.Count > 0) {
             Define(node.Names[i].Names[0].Name);
         }
     }
     return true;
 }
Example #4
0
 public override bool Walk(ImportStatement node)
 {
     if (InTargetScope && !(_scopes[_scopes.Count - 1] is ClassDefinition)) {
         for (int i = 0; i < node.Names.Count; i++) {
             if (node.AsNames != null && node.AsNames[i] != null) {
                 var name = node.AsNames[i].Name;
                 TrackImport(node, name);
             } else {
                 // only the first name becomes available
                 TrackImport(node, node.Names[i].Names[0].Name);
             }
         }
     }
     return base.Walk(node);
 }
Example #5
0
 public RemovedImportStatement(ImportStatement removed)
 {
     _import = removed;
 }
Example #6
0
        public override bool Walk(ImportStatement node)
        {
            for (int i = 0; i < node.Names.Count; i++) {
                NameExpression name = null;
                if (i < node.AsNames.Count && node.AsNames[i] != null) {
                    name = node.AsNames[i];
                } else if (node.Names[i].Names.Count > 0) {
                    name = node.Names[i].Names[0];
                }

                if (name != null) {
                    CreateVariableInDeclaredScope(name);
                }
            }

            UpdateChildRanges(node);
            return base.Walk(node);
        }
Example #7
0
 // ImportStatement
 public override bool Walk(ImportStatement node)
 {
     return ShouldWalkWorker(node);
 }
Example #8
0
 public override void PostWalk(ImportStatement node)
 {
     PostWalkWorker(node);
 }
Example #9
0
 public override bool Walk(ImportStatement node)
 {
     var vars = node.Variables;
     var refs = node.GetReferences(_root);
     for (int i = 0; i < vars.Length; i++) {
         if (vars[i] != null) {
             _allWrites.Add(refs[i]);
             _allWrittenVariables.Add(vars[i]);
         }
     }
     return base.Walk(node);
 }
Example #10
0
        /// <summary>
        /// Removes the import at the specified index (which must be in the range of
        /// the Names property) and returns a new ImportStatement which is the same
        /// as this one minus the imported name.  Preserves all round-tripping metadata
        /// in the process.
        /// 
        /// New in 1.1.
        /// </summary>
        public ImportStatement RemoveImport(JAst ast, int index)
        {
            if (index < 0 || index >= _names.Length) {
                throw new ArgumentOutOfRangeException("index");
            }
            if (ast == null) {
                throw new ArgumentNullException("ast");
            }

            ModuleName[] names = new ModuleName[_names.Length - 1];
            NameExpression[] asNames = _asNames == null ? null : new NameExpression[_asNames.Length - 1];
            var asNameWhiteSpace = this.GetNamesWhiteSpace(ast);
            var itemWhiteSpace = this.GetListWhiteSpace(ast);
            List<string> newAsNameWhiteSpace = new List<string>();
            List<string> newListWhiteSpace = new List<string>();
            int asIndex = 0;
            for (int i = 0, write = 0; i < _names.Length; i++) {
                bool includingCurrentName = i != index;

                // track the white space, this needs to be kept in sync w/ ToCodeString and how the
                // parser creates the white space.
                if (i > 0 && itemWhiteSpace != null) {
                    if (includingCurrentName) {
                        newListWhiteSpace.Add(itemWhiteSpace[i - 1]);
                    }
                }

                if (includingCurrentName) {
                    names[write] = _names[i];

                    if (_asNames != null) {
                        asNames[write] = _asNames[i];
                    }

                    write++;
                }

                if (AsNames[i] != null && includingCurrentName) {
                    if (asNameWhiteSpace != null) {
                        newAsNameWhiteSpace.Add(asNameWhiteSpace[asIndex++]);
                    }

                    if (_asNames[i].Name.Length != 0) {
                        if (asNameWhiteSpace != null) {
                            newAsNameWhiteSpace.Add(asNameWhiteSpace[asIndex++]);
                        }
                    }
                }
            }

            var res = new ImportStatement(names, asNames, _forceAbsolute);
            ast.CopyAttributes(this, res);
            ast.SetAttribute(res, NodeAttributes.NamesWhiteSpace, newAsNameWhiteSpace.ToArray());
            ast.SetAttribute(res, NodeAttributes.ListWhiteSpace, newListWhiteSpace.ToArray());

            return res;
        }