示例#1
0
  public void importVocab(Grammar importG) {
    for (String tokenName : importG.tokenNameToTypeMap.keySet()) {
      defineTokenName(tokenName, importG.tokenNameToTypeMap.get(tokenName));
    }
    for (String tokenName : importG.stringLiteralToTypeMap.keySet()) {
      defineStringLiteral(tokenName, importG.stringLiteralToTypeMap.get(tokenName));
    }
    for (Map.Entry<String, Integer> channel : importG.channelNameToValueMap.entrySet()) {
      defineChannelName(channel.getKey(), channel.getValue());
    }
    //		this.tokenNameToTypeMap.putAll( importG.tokenNameToTypeMap );
    //		this.stringLiteralToTypeMap.putAll( importG.stringLiteralToTypeMap );
    int max = Math.max(this.typeToTokenList.size(), importG.typeToTokenList.size());
    Utils.setSize(typeToTokenList, max);
    for (int ttype = 0; ttype < importG.typeToTokenList.size(); ttype++) {
      maxTokenType = Math.max(maxTokenType, ttype);
      this.typeToTokenList.set(ttype, importG.typeToTokenList.get(ttype));
    }

    max = Math.max(this.channelValueToNameList.size(), importG.channelValueToNameList.size());
    Utils.setSize(channelValueToNameList, max);
    for (int channelValue = 0;
        channelValue < importG.channelValueToNameList.size();
        channelValue++) {
      maxChannelType = Math.max(maxChannelType, channelValue);
      this.channelValueToNameList.set(
          channelValue, importG.channelValueToNameList.get(channelValue));
    }
  }
示例#2
0
 public void setTokenForType(int ttype, String text) {
   if (ttype >= typeToTokenList.size()) {
     Utils.setSize(typeToTokenList, ttype + 1);
   }
   String prevToken = typeToTokenList.get(ttype);
   if (prevToken == null || prevToken.charAt(0) == '\'') {
     // only record if nothing there before or if thing before was a literal
     typeToTokenList.set(ttype, text);
   }
 }
示例#3
0
  /**
   * Sets the channel name associated with a particular channel value.
   *
   * <p>If a name has already been assigned to the channel with constant value {@code channelValue},
   * this method does nothing.
   *
   * @param channelValue The constant value for the channel.
   * @param name The channel name.
   */
  public void setChannelNameForValue(int channelValue, String name) {
    if (channelValue >= channelValueToNameList.size()) {
      Utils.setSize(channelValueToNameList, channelValue + 1);
    }

    String prevChannel = channelValueToNameList.get(channelValue);
    if (prevChannel == null) {
      channelValueToNameList.set(channelValue, name);
    }
  }
示例#4
0
 // can be multi-line
 // error(29): A.g:2:11: unknown attribute reference a in $a
 // error(29): A.g:2:11: unknown attribute reference a in $a
 String stripErrorNum(String errs) {
   String[] lines = errs.split("\n");
   for (int i = 0; i < lines.length; i++) {
     String s = lines[i];
     int lp = s.indexOf("error(");
     int rp = s.indexOf(')', lp);
     if (lp >= 0 && rp >= 0) {
       lines[i] = s.substring(0, lp) + s.substring(rp + 1, s.length());
     }
   }
   return Utils.join(lines, "\n");
 }
示例#5
0
  public int defineStringLiteral(String lit, int ttype) {
    if (!stringLiteralToTypeMap.containsKey(lit)) {
      stringLiteralToTypeMap.put(lit, ttype);
      // track in reverse index too
      if (ttype >= typeToStringLiteralList.size()) {
        Utils.setSize(typeToStringLiteralList, ttype + 1);
      }
      typeToStringLiteralList.set(ttype, lit);

      setTokenForType(ttype, lit);
      return ttype;
    }
    return Token.INVALID_TYPE;
  }
示例#6
0
  public void setTokenForType(int ttype, String text) {
    if (ttype == Token.EOF) {
      // ignore EOF, it will be reported as an error separately
      return;
    }

    if (ttype >= typeToTokenList.size()) {
      Utils.setSize(typeToTokenList, ttype + 1);
    }
    String prevToken = typeToTokenList.get(ttype);
    if (prevToken == null || prevToken.charAt(0) == '\'') {
      // only record if nothing there before or if thing before was a literal
      typeToTokenList.set(ttype, text);
    }
  }
示例#7
0
 public void importVocab(Grammar importG) {
   for (String tokenName : importG.tokenNameToTypeMap.keySet()) {
     defineTokenName(tokenName, importG.tokenNameToTypeMap.get(tokenName));
   }
   for (String tokenName : importG.stringLiteralToTypeMap.keySet()) {
     defineStringLiteral(tokenName, importG.stringLiteralToTypeMap.get(tokenName));
   }
   //		this.tokenNameToTypeMap.putAll( importG.tokenNameToTypeMap );
   //		this.stringLiteralToTypeMap.putAll( importG.stringLiteralToTypeMap );
   int max = Math.max(this.typeToTokenList.size(), importG.typeToTokenList.size());
   Utils.setSize(typeToTokenList, max);
   for (int ttype = 0; ttype < importG.typeToTokenList.size(); ttype++) {
     maxTokenType = Math.max(maxTokenType, ttype);
     this.typeToTokenList.set(ttype, importG.typeToTokenList.get(ttype));
   }
 }