示例#1
0
 public FromImportStatement(ModuleName root, SymbolId[] names, SymbolId[] asNames, bool fromFuture, bool forceAbsolute) {
     _root = root;
     _names = names;
     _asNames = asNames;
     _fromFuture = fromFuture;
     _forceAbsolute = forceAbsolute;
 }
示例#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
 // module: (identifier '.')* identifier
 private ModuleName ParseModuleName() {
     var start = GetStart();
     ModuleName ret = new ModuleName(ReadNames());
     ret.SetLoc(_globalParent, start, GetEnd());
     return ret;
 }
示例#4
0
 // module: (identifier '.')* identifier
 private ModuleName ParseModuleName() {
     SourceLocation start = GetStart();
     ModuleName ret = new ModuleName(ReadNames());
     ret.SetLoc(start, GetEnd());
     return ret;
 }
示例#5
0
 public override void PostWalk(ModuleName node)
 {
     CommonPostWalk(node);
 }
示例#6
0
 public override bool Walk(ModuleName node)
 {
     CommonWalk(node);
     return true;
 }
示例#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;
        }
示例#8
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);
            }
示例#9
0
文件: _ast.cs 项目: TerabyteX/main
 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
 }
示例#10
0
 public ImportStatement(ModuleName[] names, string[] asNames, bool forceAbsolute) {
     _names = names;
     _asNames = asNames;
     _forceAbsolute = forceAbsolute;
 }
示例#11
0
 // 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);
 }
示例#13
0
 public void Visit(PyAst.ModuleName node) => throw CreateNotImplementedEx();