org.antlr.runtime.Token.getTokenIndex()方法的使用及代码示例

x33g5p2x  于2022-01-29 转载在 其他  
字(9.5k)|赞(0)|评价(0)|浏览(111)

本文整理了Java中org.antlr.runtime.Token.getTokenIndex()方法的一些代码示例,展示了Token.getTokenIndex()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Token.getTokenIndex()方法的具体详情如下:
包路径:org.antlr.runtime.Token
类名称:Token
方法名:getTokenIndex

Token.getTokenIndex介绍

[英]An index from 0..n-1 of the token object in the input stream. This must be valid in order to use the ANTLRWorks debugger.
[中]从0开始的索引。。输入流中令牌对象的n-1。这必须有效才能使用ANTLRWorks调试器。

代码示例

代码示例来源:origin: plutext/docx4j

public final XPathEnhancerParser.absoluteLocationPathNoroot_return absoluteLocationPathNoroot() throws RecognitionException {
  XPathEnhancerParser.absoluteLocationPathNoroot_return retval = new XPathEnhancerParser.absoluteLocationPathNoroot_return();
  retval.start = input.LT(1);
     new STAttrMap().put("sharesPrefix",  sharesPrefix(input.toString(retval.start,input.LT(-1)))    ).put("commonPrefix",  prefix                 ).put("index",  index                  ).put("remainingSuffix",  remainingSuffix(input.toString(retval.start,input.LT(-1))) ).put("originalPath",  input.toString(retval.start,input.LT(-1))                  ));
     ((Token)retval.start).getTokenIndex(),
     input.LT(-1).getTokenIndex(),
     retval.st);

代码示例来源:origin: org.eclipse/xtext

protected void appendTrailingHiddenTokens() {
  Token tokenBefore = input.LT(-1);
  int size = input.size();
  if (tokenBefore != null && tokenBefore.getTokenIndex() < size) {
    for (int x = tokenBefore.getTokenIndex() + 1; x < size; x++) {
      Token hidden = input.get(x);
      createLeafNode(hidden, null);
      lastConsumedIndex = hidden.getTokenIndex();
    }
  }
}

代码示例来源:origin: antlr/antlr3

@Override
public String getText() {
  String badText = null;
  if (start != null) {
    int i = start.getTokenIndex();
    int j = stop.getTokenIndex();
    if (stop.getType() == Token.EOF) {
      j = input.size();
    }
    badText = ((TokenStream)input).toString(i, j);
  } else {
    // people should subclass if they alter the tree type so this
    // next one is for sure correct.
    badText = "<unknown>";
  }
  return badText;
}

代码示例来源:origin: org.apache.servicemix.bundles/org.apache.servicemix.bundles.drools

/**
 * Matches a conditional expression
 * 
 * @return
 * @throws RecognitionException
 */
public String conditionalExpression() throws RecognitionException {
  int first = input.index();
  exprParser.conditionalExpression();
  if ( state.failed ) return null;
  if ( state.backtracking == 0 && input.index() > first ) {
    // expression consumed something
    String expr = input.toString( first,
                   input.LT( -1 ).getTokenIndex() );
    return expr;
  }
  return null;
}

代码示例来源:origin: org.apache.servicemix.bundles/org.apache.servicemix.bundles.drools

int first = input.index();
exprParser.getHelper().setHasOperator( false ); // resetting
try{
      if( location == Location.LOCATION_LHS_INSIDE_CONDITION_END ) {
        helper.emit( Location.LOCATION_LHS_INSIDE_CONDITION_ARGUMENT );
      } else if ( input.get(input.index()).getType() != DRLLexer.EOF ) {
        helper.emit( Location.LOCATION_LHS_INSIDE_CONDITION_START );
if ( state.backtracking == 0 && input.index() > first ) {
  int last = input.LT( -1 ).getTokenIndex();
  String expr = toExpression(prefix, first, last);
  pattern.constraint( expr,

代码示例来源:origin: org.apache.servicemix.bundles/org.apache.servicemix.bundles.drools

String typeArguments = "";
try {
  int first = input.index();
  Token token = match( input,
             DRLLexer.LESS,
          DroolsEditorType.SYMBOL );
  if ( state.failed ) return typeArguments;
  typeArguments = input.toString( first,
                  token.getTokenIndex() );

代码示例来源:origin: org.apache.servicemix.bundles/org.apache.servicemix.bundles.drools

int idx = input.index();
final String expr;
try{
  final Token tempToken = helper.getLastTokenOnList(helper.getEditorInterface().getLast().getContent());
  if (tempToken != null){
    for (int i = tempToken.getTokenIndex() + 1; i < input.size(); i++) {
      final Token token = input.get(i);
      if (token.getType() == DRLLexer.EOF){

代码示例来源:origin: org.apache.servicemix.bundles/org.apache.servicemix.bundles.drools

/**
 * Matches a conditional || expression
 * 
 * @return
 * @throws RecognitionException
 */
public String conditionalOrExpression() throws RecognitionException {
  int first = input.index();
  exprParser.conditionalOrExpression();
  if ( state.failed ) return null;
  if ( state.backtracking == 0 && input.index() > first ) {
    // expression consumed something
    String expr = input.toString( first,
                   input.LT( -1 ).getTokenIndex() );
    return expr;
  }
  return null;
}

代码示例来源:origin: org.eclipse/xtext

protected List<ILeafNode> appendSkippedTokens() {
  List<ILeafNode> skipped = new ArrayList<ILeafNode>();
  Token currentToken = input.LT(-1);
  int currentTokenIndex = (currentToken == null) ? -1 : currentToken.getTokenIndex();
  Token tokenBefore = (lastConsumedIndex == -1) ? null : input.get(lastConsumedIndex);
  int indexOfTokenBefore = tokenBefore != null ? tokenBefore.getTokenIndex() : -1;
  if (indexOfTokenBefore + 1 < currentTokenIndex) {
    for (int x = indexOfTokenBefore + 1; x < currentTokenIndex; x++) {
      Token hidden = input.get(x);
      ILeafNode leaf = createLeafNode(hidden, null);
      skipped.add(leaf);
      lastConsumedIndex = x;
    }
  }
  if (lastConsumedIndex < currentTokenIndex && currentToken != null) {
    ILeafNode leaf = createLeafNode(currentToken, null);
    skipped.add(leaf);
    lastConsumedIndex = currentToken.getTokenIndex();
  }
  return skipped;
}

代码示例来源:origin: nativelibs4java/JNAerator

int objCMethodDecl_StartIndex = input.index();
          function.addModifiers(ModifierType.Static); 
          function = mark(function, getLine(tp)); 
          function.setCommentBefore(getCommentBefore(tp.getTokenIndex()));
          function.setCommentBefore(getCommentBefore(tm.getTokenIndex()));
  methodName=(Token)input.LT(1);
     function.setCommentAfter(getCommentAfterOnSameLine(methodName.getTokenIndex(), null));

代码示例来源:origin: org.apache.servicemix.bundles/org.apache.servicemix.bundles.drools

private String getConsequenceCode( int first ) {
  while ( input.LA( 1 ) != DRLLexer.EOF &&
      !helper.validateIdentifierKey( DroolsSoftKeywords.END ) &&
      !helper.validateIdentifierKey( DroolsSoftKeywords.THEN ) ) {
    helper.emit( input.LT(1), DroolsEditorType.CODE_CHUNK );
    input.consume();
  }
  int last = input.LT(1).getTokenIndex();
  if ( last <= first ) {
    return "";
  }
  String chunk = input.toString( first,
                  last );
  if ( chunk.endsWith( DroolsSoftKeywords.END ) ) {
    chunk = chunk.substring( 0,
                 chunk.length() - DroolsSoftKeywords.END.length() );
  } else if ( chunk.endsWith( DroolsSoftKeywords.THEN ) ) {
    chunk = chunk.substring( 0,
                 chunk.length() - DroolsSoftKeywords.THEN.length() );
  }
  return chunk;
}

代码示例来源:origin: antlr/antlr3

@Override
public String getText() {
  String badText = null;
  if (start != null) {
    int i = start.getTokenIndex();
    int j = stop.getTokenIndex();
    if (stop.getType() == Token.EOF) {
      j = input.size();
    }
    badText = ((TokenStream)input).toString(i, j);
  } else {
    // people should subclass if they alter the tree type so this
    // next one is for sure correct.
    badText = "<unknown>";
  }
  return badText;
}

代码示例来源:origin: org.apache.servicemix.bundles/org.apache.servicemix.bundles.drools

int start = input.index();
match( input,
    DRLLexer.ID,
  if ( state.failed ) return;
int end = input.LT( -1 ).getTokenIndex();
                          input.toString( start,
                                  end ) );

代码示例来源:origin: com.atlassian.jira/jira-core

Token currentToken = input.LT(-1);
if(input.get(input.LT(-1).getTokenIndex()-1).getType() == MATCHWS )

代码示例来源:origin: nativelibs4java/JNAerator

retval.start = input.LT(1);
int declaration_StartIndex = input.index();
     retval.startTokenIndex = getTokenStream().index();
     retval.preComment = getCommentBefore(retval.startTokenIndex);
  retval.stop = input.LT(-1);
   if (retval.declaration == null)
   try {
    int i = ((Token)retval.start).getTokenIndex();
    if (i > 0) {
     String s1 = getTokenStream().get(i - 1).getText(), s2 = i > 1 ? getTokenStream().get(i - 2).getText() : null;

代码示例来源:origin: org.docx4j/docx4j

public final XPathEnhancerParser.absoluteLocationPathNoroot_return absoluteLocationPathNoroot() throws RecognitionException {
  XPathEnhancerParser.absoluteLocationPathNoroot_return retval = new XPathEnhancerParser.absoluteLocationPathNoroot_return();
  retval.start = input.LT(1);
     new STAttrMap().put("sharesPrefix",  sharesPrefix(input.toString(retval.start,input.LT(-1)))    ).put("commonPrefix",  prefix                 ).put("index",  index                  ).put("remainingSuffix",  remainingSuffix(input.toString(retval.start,input.LT(-1))) ).put("originalPath",  input.toString(retval.start,input.LT(-1))                  ));
     ((Token)retval.start).getTokenIndex(),
     input.LT(-1).getTokenIndex(),
     retval.st);

代码示例来源:origin: antlr/antlr3

@Override
public String getText() {
  String badText;
  if ( start instanceof Token ) {
    int i = start.getTokenIndex();
    int j = stop.getTokenIndex();
    if ( stop.getType() == Token.EOF ) {
      j = ((TokenStream)input).size();
    }
    badText = ((TokenStream)input).toString(i, j);
  }
  else if ( start instanceof Tree ) {
    badText = ((TreeNodeStream)input).toString(start, stop);
  }
  else {
    // people should subclass if they alter the tree type so this
    // next one is for sure correct.
    badText = "<unknown>";
  }
  return badText;
}

代码示例来源:origin: org.apache.servicemix.bundles/org.apache.servicemix.bundles.drools

String type = "";
try {
  int first = input.index(), last = first;
  match( input,
      DRLLexer.ID,
    if ( state.failed ) return type;
  last = input.LT( -1 ).getTokenIndex();
  type = input.toString( first,
              last );
  type = type.replace( " ",

代码示例来源:origin: org.antlr/ST4

Token templateToken = input.LT(1);
          String msg = "missing template at '"+input.LT(1).getText()+"'";
          NoViableAltException e = new NoViableAltException("", 0, 0, input);
          group.errMgr.groupSyntaxError(ErrorType.SYNTAX_ERROR, getSourceName(), e, msg);
    if ( (name!=null?name.getTokenIndex():0) >= 0 ) { // if ID missing
      template = Misc.strip(template, n);
      String templateName = (name!=null?name.getText():null);

代码示例来源:origin: com.ning.billing/killbill-osgi-bundles-analytics

public String getText() {
  String badText = null;
  if ( start instanceof Token ) {
    int i = ((Token)start).getTokenIndex();
    int j = ((Token)stop).getTokenIndex();
    if ( ((Token)stop).getType() == Token.EOF ) {
      j = ((TokenStream)input).size();
    }
    badText = ((TokenStream)input).toString(i, j);
  }
  else if ( start instanceof Tree ) {
    badText = ((TreeNodeStream)input).toString(start, stop);
  }
  else {
    // people should subclass if they alter the tree type so this
    // next one is for sure correct.
    badText = "<unknown>";
  }
  return badText;
}

相关文章