Beispiel #1
0
 public FromImportStatement(ModuleName root, NameExpression/*!*/[] names, NameExpression[] asNames, bool fromFuture, bool forceAbsolute)
 {
     _root = root;
     _names = names;
     _asNames = asNames;
     _fromFuture = fromFuture;
     _forceAbsolute = forceAbsolute;
 }
Beispiel #2
0
        // relative_module: "."* module | "."+
        private ModuleName ParseRelativeModuleName()
        {
            var start = GetStart();

            int dotCount = 0;
            List<string> dotWhiteSpace = MakeWhiteSpaceList();
            for (; ; ) {
                if (MaybeEat(TokenKind.Dot)) {
                    if (dotWhiteSpace != null) {
                        dotWhiteSpace.Add(_tokenWhiteSpace);
                    }
                    dotCount++;
                } else if (MaybeEat(TokenKind.Ellipsis)) {
                    if (dotWhiteSpace != null) {
                        dotWhiteSpace.Add(_tokenWhiteSpace);
                        dotWhiteSpace.Add("");
                        dotWhiteSpace.Add("");
                    }
                    dotCount += 3;
                } else {
                    break;
                }
            }

            List<string> nameWhiteSpace = null;
            NameExpression[] names = EmptyNames;
            if (PeekToken() is NameToken) {
                names = ReadDottedName(out nameWhiteSpace);
            }

            ModuleName ret;
            if (dotCount > 0) {
                ret = new RelativeModuleName(names, dotCount);
                if (_verbatim) {
                    if (nameWhiteSpace != null) {
                        AddNamesWhiteSpace(ret, nameWhiteSpace.ToArray());
                    }
                    AddListWhiteSpace(ret, dotWhiteSpace.ToArray());
                }
            } else {
                if (names.Length == 0) {
                    ReportSyntaxError(_lookahead.Span.Start, _lookahead.Span.End, "missing module name");
                }
                ret = new ModuleName(names);
                if (nameWhiteSpace != null) {
                    AddNamesWhiteSpace(ret, nameWhiteSpace.ToArray());
                }
            }

            ret.SetLoc(start, GetEnd());
            return ret;
        }
Beispiel #3
0
 // module: (identifier '.')* identifier
 private ModuleName ParseModuleName()
 {
     var start = GetStart();
     List<string> dotWhiteSpace;
     ModuleName ret = new ModuleName(ReadDottedName(out dotWhiteSpace));
     if (_verbatim) {
         AddNamesWhiteSpace(ret, dotWhiteSpace.ToArray());
     }
     ret.SetLoc(start, GetEnd());
     return ret;
 }
Beispiel #4
0
 // ModuleName
 public override bool Walk(ModuleName node)
 {
     return ShouldWalkWorker(node);
 }
Beispiel #5
0
 public override void PostWalk(ModuleName node)
 {
     PostWalkWorker(node);
 }
Beispiel #6
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;
        }
Beispiel #7
0
 public ImportStatement(ModuleName[] names, NameExpression[] asNames, bool forceAbsolute)
 {
     _names = names;
     _asNames = asNames;
     _forceAbsolute = forceAbsolute;
 }