private object GetLevel()
        {
            RelativeModuleName rmn = _root as RelativeModuleName;

            if (rmn != null)
            {
                return(rmn.DotCount);
            }

            return(0);
        }
示例#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;
        }
示例#3
0
 // RelativeModuleName
 public override bool Walk(RelativeModuleName node)
 {
     node.Parent = _currentScope;
     return(base.Walk(node));
 }
示例#4
0
 public override void PostWalk(RelativeModuleName node)
 {
     CommonPostWalk(node);
 }
示例#5
0
 public override bool Walk(RelativeModuleName node)
 {
     CommonWalk(node);
     return true;
 }
示例#6
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;
        }
示例#7
0
文件: _ast.cs 项目: TerabyteX/main
            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);
            }
 // RelativeModuleName
 public override bool Walk(RelativeModuleName node) {
     node.Parent = _currentScope;
     return base.Walk(node);
 }
 public void Visit(PyAst.RelativeModuleName node) => throw CreateNotImplementedEx();