public FromImportStatement(ModuleName root, SymbolId[] names, SymbolId[] 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;
            while (MaybeEat(TokenKind.Dot)) {
                dotCount++;
            }

            string[] names = ArrayUtils.EmptyStrings;
            if (PeekToken() is NameToken) {
                names = ReadNames();
            }

            ModuleName ret;
            if (dotCount > 0) {
                ret = new RelativeModuleName(names, dotCount);
            } else {
                if (names.Length == 0) {
                    ReportSyntaxError(_lookahead.Span.Start, _lookahead.Span.End, "invalid syntax");
                }
                ret = new ModuleName(names);
            }

            ret.SetLoc(_globalParent, start, GetEnd());
            return ret;
        }
Beispiel #3
0
 // module: (identifier '.')* identifier
 private ModuleName ParseModuleName() {
     var start = GetStart();
     ModuleName ret = new ModuleName(ReadNames());
     ret.SetLoc(_globalParent, start, GetEnd());
     return ret;
 }
Beispiel #4
0
 // module: (identifier '.')* identifier
 private ModuleName ParseModuleName() {
     SourceLocation start = GetStart();
     ModuleName ret = new ModuleName(ReadNames());
     ret.SetLoc(start, GetEnd());
     return ret;
 }
Beispiel #5
0
 public override void PostWalk(ModuleName node)
 {
     CommonPostWalk(node);
 }
Beispiel #6
0
 public override bool Walk(ModuleName node)
 {
     CommonWalk(node);
     return true;
 }
Beispiel #7
0
        // relative_module: "."* module | "."+
        private ModuleName ParseRelativeModuleName() {
            SourceLocation start = GetStart();

            int dotCount = 0;
            while (MaybeEat(TokenKind.Dot)) {
                dotCount++;
            }

            SymbolId[] names = SymbolId.EmptySymbols;
            if (PeekToken() is NameToken) {
                names = ReadNames();
            }

            ModuleName ret;
            if (dotCount > 0) {
                ret = new RelativeModuleName(names, dotCount);
            } else {
                if (names.Length == 0) {
                    ReportSyntaxError(_lookahead.Span.Start, _lookahead.Span.End, "invalid syntax");
                }
                ret = new ModuleName(names);
            }
            
            ret.SetLoc(start, GetEnd());
            return ret;
        }
Beispiel #8
0
            internal override Statement Revert()
            {
                ModuleName root = null;
                bool absolute = false; // TODO: absolute import appears in ModuleOptions, not sure how it should work together
                if (module != null)
                    if (module[0] == '.') // relative module
                        root = new RelativeModuleName(module.Split(MODULE_NAME_SPLITTER), level);
                    else {
                        root = new ModuleName(module.Split(MODULE_NAME_SPLITTER));
                        absolute = true;
                    }

                if (names.Count == 1 && ((alias)names[0]).name == "*")
                    return new FromImportStatement(root, (string[])FromImportStatement.Star, null, false, absolute);

                String[] newNames = new String[names.Count];
                String[] asNames = new String[names.Count];
                for (int i = 0; i < names.Count; i++) {
                    alias alias = (alias)names[i];
                    newNames[i] = alias.name;
                    asNames[i] = alias.asname;
                }
                return new FromImportStatement(root, newNames, asNames, false, absolute);
            }
Beispiel #9
0
 internal override Statement Revert()
 {
     ModuleName[] moduleNames = new ModuleName[names.Count];
     String[] asNames = new String[names.Count];
     for (int i = 0; i < names.Count; i++) {
         alias alias = (alias)names[i];
         moduleNames[i] = new ModuleName(alias.name.Split(MODULE_NAME_SPLITTER));
         asNames[i] = alias.asname;
     }
     return new ImportStatement(moduleNames, asNames, false);  // TODO: not so sure about the relative/absolute argument here
 }
Beispiel #10
0
 public ImportStatement(ModuleName[] names, string[] asNames, bool forceAbsolute) {
     _names = names;
     _asNames = asNames;
     _forceAbsolute = forceAbsolute;
 }
 // ModuleName
 public override bool Walk(ModuleName node)
 {
     node.Parent = _currentScope;
     return(base.Walk(node));
 }
 // ModuleName
 public override bool Walk(ModuleName node) {
     node.Parent = _currentScope;
     return base.Walk(node);
 }
 public void Visit(PyAst.ModuleName node) => throw CreateNotImplementedEx();