Package loop.ast.script

Examples of loop.ast.script.RequireDecl


    chewEols();

    Unit unit = new Unit(file, module);
    scope = unit;
    RequireDecl require;
    do {
      require = require();
      chewEols();

      if (null != require) {
        if (unit.imports().contains(require) && require.alias == null) {
          addError("Duplicate module import: " + require.toSymbol(),
              require.sourceLine, require.sourceColumn);
          throw new LoopCompileException();
        }

        unit.declare(require);
View Full Code Here


        addError("Expected newline after require (are you trying to alias Java imports?)",
            tokens.get(i - 1));
        throw new LoopCompileException();
      }

      return new RequireDecl(module.get(0).value).sourceLocation(module);
    }

    if (null == module) {
      addError("Expected module identifier", tokens.get(i - 1));
      throw new LoopCompileException();
    }

    List<String> requires = new ArrayList<String>();
    requires.add(module.get(0).value);

    boolean aliased, javaImport = false;
    while (match(Token.Kind.DOT) != null) {
      module = match(Token.Kind.IDENT);
      if (null == module) {
        module = match(Kind.TYPE_IDENT);
        javaImport = true;
      }

      if (null == module) {
        addError("Expected module identifier part after '.'", tokens.get(i - 1));
        throw new LoopCompileException();
      }

      requires.add(module.get(0).value);
    }

    List<Token> asToken = match(Kind.IDENT);
    aliased = asToken != null && RestrictedKeywords.AS.equals(asToken.get(0).value);

    List<Token> aliasTokens = match(Kind.IDENT);
    if (aliased) {
      if (aliasedModules == null)
        aliasedModules = new HashSet<String>();

      if (aliasTokens == null) {
        addError("Expected module alias after '" + RestrictedKeywords.AS + "'", tokens.get(i - 1));
        throw new LoopCompileException();
      }

      // Cache the aliases for some smart parsing of namespaced function calls.
      aliasedModules.add(aliasTokens.get(0).value);
    }

    if (match(Token.Kind.EOL) == null) {
      addError("Expected newline after require declaration", tokens.get(i - 1));
      throw new LoopCompileException();
    }

    // We also allow java imports outside using the backticks syntax.
    String alias = aliased ? aliasTokens.get(0).value : null;
    if (javaImport) {
      return new RequireDecl(requires.toString().replace(", ", "."), alias)
          .sourceLocation(module);
    }

    return new RequireDecl(requires, alias)
        .sourceLocation(module);
  }
View Full Code Here

TOP

Related Classes of loop.ast.script.RequireDecl

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.