org.antlr.v4.tool.Grammar.isTokenName()方法的使用及代码示例

x33g5p2x  于2022-01-20 转载在 其他  
字(9.7k)|赞(0)|评价(0)|浏览(169)

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

Grammar.isTokenName介绍

[英]Is id a valid token name? Does id start with an uppercase letter?
[中]id是有效的令牌名称吗?id是否以大写字母开头?

代码示例

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

public boolean isLexerRule() {
  String name = getRuleName();
  return name!=null && Grammar.isTokenName(name);
}

代码示例来源:origin: uk.co.nichesolutions/antlr4

public boolean isLexerRule() {
  String name = getRuleName();
  return name!=null && Grammar.isTokenName(name);
}

代码示例来源:origin: com.impetus.fabric/fabric-jdbc-driver-shaded

public boolean isLexerRule() {
  String name = getRuleName();
  return name!=null && Grammar.isTokenName(name);
}

代码示例来源:origin: com.tunnelvisionlabs/antlr4

public boolean isLexerRule() {
  String name = getRuleName();
  return name!=null && Grammar.isTokenName(name);
}

代码示例来源:origin: io.virtdata/virtdata-lib-realer

public boolean isLexerRule() {
  String name = getRuleName();
  return name!=null && Grammar.isTokenName(name);
}

代码示例来源:origin: antlr/intellij-plugin-v4

public static List<TerminalNode> getAllRuleRefNodes(Parser parser, ParseTree tree, String ruleName) {
  List<TerminalNode> nodes = new ArrayList<TerminalNode>();
  Collection<ParseTree> ruleRefs;
  if ( Grammar.isTokenName(ruleName) ) {
    ruleRefs = XPath.findAll(tree, "//lexerRuleBlock//TOKEN_REF", parser);
  }
  else {
    ruleRefs = XPath.findAll(tree, "//ruleBlock//RULE_REF", parser);
  }
  for (ParseTree node : ruleRefs) {
    TerminalNode terminal = (TerminalNode)node;
    Token rrefToken = terminal.getSymbol();
    String r = rrefToken.getText();
    if ( r.equals(ruleName) ) {
      nodes.add(terminal);
    }
  }
  if ( nodes.size()==0 ) return null;
  return nodes;
}

代码示例来源:origin: antlr/intellij-plugin-v4

public static TerminalNode getRuleDefNameNode(Parser parser, ParseTree tree, String ruleName) {
  Collection<ParseTree> ruleDefRuleNodes;
  if ( Grammar.isTokenName(ruleName) ) {
    ruleDefRuleNodes = XPath.findAll(tree, "//lexerRule/TOKEN_REF", parser);
  }
  else {
    ruleDefRuleNodes = XPath.findAll(tree, "//parserRuleSpec/RULE_REF", parser);
  }
  for (ParseTree node : ruleDefRuleNodes) {
    String r = node.getText(); // always a TerminalNode; just get rule name of this def
    if ( r.equals(ruleName) ) {
      return (TerminalNode)node;
    }
  }
  return null;
}

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

void checkTokenDefinition(Token tokenID) {
  String fileName = tokenID.getInputStream().getSourceName();
  if ( !Grammar.isTokenName(tokenID.getText()) ) {
    g.tool.errMgr.grammarError(ErrorType.TOKEN_NAMES_MUST_START_UPPER,
                  fileName,
                  tokenID,
                  tokenID.getText());
  }
}

代码示例来源:origin: com.tunnelvisionlabs/antlr4

void checkTokenDefinition(Token tokenID) {
  String fileName = tokenID.getInputStream().getSourceName();
  if ( !Grammar.isTokenName(tokenID.getText()) ) {
    g.tool.errMgr.grammarError(ErrorType.TOKEN_NAMES_MUST_START_UPPER,
                  fileName,
                  tokenID,
                  tokenID.getText());
  }
}

代码示例来源:origin: com.impetus.fabric/fabric-jdbc-driver-shaded

void checkTokenDefinition(Token tokenID) {
  String fileName = tokenID.getInputStream().getSourceName();
  if ( !Grammar.isTokenName(tokenID.getText()) ) {
    g.tool.errMgr.grammarError(ErrorType.TOKEN_NAMES_MUST_START_UPPER,
                  fileName,
                  tokenID,
                  tokenID.getText());
  }
}

代码示例来源:origin: io.virtdata/virtdata-lib-realer

void checkTokenDefinition(Token tokenID) {
  String fileName = tokenID.getInputStream().getSourceName();
  if ( !Grammar.isTokenName(tokenID.getText()) ) {
    g.tool.errMgr.grammarError(ErrorType.TOKEN_NAMES_MUST_START_UPPER,
                  fileName,
                  tokenID,
                  tokenID.getText());
  }
}

代码示例来源:origin: uk.co.nichesolutions/antlr4

void checkTokenDefinition(Token tokenID) {
  String fileName = tokenID.getInputStream().getSourceName();
  if ( !Grammar.isTokenName(tokenID.getText()) ) {
    g.tool.errMgr.grammarError(ErrorType.TOKEN_NAMES_MUST_START_UPPER,
                  fileName,
                  tokenID,
                  tokenID.getText());
  }
}

代码示例来源:origin: io.virtdata/virtdata-lib-realer

void checkInvalidRuleDef(Token ruleID) {
  String fileName = null;
  if ( ruleID.getInputStream()!=null ) {
    fileName = ruleID.getInputStream().getSourceName();
  }
  if ( g.isLexer() && Character.isLowerCase(ruleID.getText().charAt(0)) ) {
    g.tool.errMgr.grammarError(ErrorType.PARSER_RULES_NOT_ALLOWED,
                  fileName, ruleID, ruleID.getText());
  }
  if ( g.isParser() &&
    Grammar.isTokenName(ruleID.getText()) )
  {
    g.tool.errMgr.grammarError(ErrorType.LEXER_RULES_NOT_ALLOWED,
                  fileName, ruleID, ruleID.getText());
  }
}

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

void checkInvalidRuleDef(Token ruleID) {
  String fileName = null;
  if ( ruleID.getInputStream()!=null ) {
    fileName = ruleID.getInputStream().getSourceName();
  }
  if ( g.isLexer() && Character.isLowerCase(ruleID.getText().charAt(0)) ) {
    g.tool.errMgr.grammarError(ErrorType.PARSER_RULES_NOT_ALLOWED,
                  fileName, ruleID, ruleID.getText());
  }
  if ( g.isParser() &&
    Grammar.isTokenName(ruleID.getText()) )
  {
    g.tool.errMgr.grammarError(ErrorType.LEXER_RULES_NOT_ALLOWED,
                  fileName, ruleID, ruleID.getText());
  }
}

代码示例来源:origin: com.impetus.fabric/fabric-jdbc-driver-shaded

public void translateLeftRecursiveRules() {
  String language = g.getOptionString("language");
  // translate all recursive rules
  List<String> leftRecursiveRuleNames = new ArrayList<String>();
  for (Rule r : rules) {
    if ( !Grammar.isTokenName(r.name) ) {
      if ( LeftRecursiveRuleAnalyzer.hasImmediateRecursiveRuleRefs(r.ast, r.name) ) {
        boolean fitsPattern = translateLeftRecursiveRule(ast, (LeftRecursiveRule)r, language);
        if ( fitsPattern ) leftRecursiveRuleNames.add(r.name);
      }
    }
  }
  // update all refs to recursive rules to have [0] argument
  for (GrammarAST r : ast.getNodesWithType(ANTLRParser.RULE_REF)) {
    if ( r.getParent().getType()==ANTLRParser.RULE ) continue; // must be rule def
    if ( ((GrammarASTWithOptions)r).getOptionString(PRECEDENCE_OPTION_NAME) != null ) continue; // already has arg; must be in rewritten rule
    if ( leftRecursiveRuleNames.contains(r.getText()) ) {
      // found ref to recursive rule not already rewritten with arg
      ((GrammarASTWithOptions)r).setOption(PRECEDENCE_OPTION_NAME, (GrammarAST)new GrammarASTAdaptor().create(ANTLRParser.INT, "0"));
    }
  }
}

代码示例来源:origin: com.impetus.fabric/fabric-jdbc-driver-shaded

void checkInvalidRuleDef(Token ruleID) {
  String fileName = null;
  if ( ruleID.getInputStream()!=null ) {
    fileName = ruleID.getInputStream().getSourceName();
  }
  if ( g.isLexer() && Character.isLowerCase(ruleID.getText().charAt(0)) ) {
    g.tool.errMgr.grammarError(ErrorType.PARSER_RULES_NOT_ALLOWED,
                  fileName, ruleID, ruleID.getText());
  }
  if ( g.isParser() &&
    Grammar.isTokenName(ruleID.getText()) )
  {
    g.tool.errMgr.grammarError(ErrorType.LEXER_RULES_NOT_ALLOWED,
                  fileName, ruleID, ruleID.getText());
  }
}

代码示例来源:origin: com.tunnelvisionlabs/antlr4

void checkInvalidRuleDef(Token ruleID) {
  String fileName = null;
  if ( ruleID.getInputStream()!=null ) {
    fileName = ruleID.getInputStream().getSourceName();
  }
  if ( g.isLexer() && Character.isLowerCase(ruleID.getText().charAt(0)) ) {
    g.tool.errMgr.grammarError(ErrorType.PARSER_RULES_NOT_ALLOWED,
                  fileName, ruleID, ruleID.getText());
  }
  if ( g.isParser() &&
    Grammar.isTokenName(ruleID.getText()) )
  {
    g.tool.errMgr.grammarError(ErrorType.LEXER_RULES_NOT_ALLOWED,
                  fileName, ruleID, ruleID.getText());
  }
}

代码示例来源:origin: uk.co.nichesolutions/antlr4

void checkInvalidRuleDef(Token ruleID) {
  String fileName = null;
  if ( ruleID.getInputStream()!=null ) {
    fileName = ruleID.getInputStream().getSourceName();
  }
  if ( g.isLexer() && Character.isLowerCase(ruleID.getText().charAt(0)) ) {
    g.tool.errMgr.grammarError(ErrorType.PARSER_RULES_NOT_ALLOWED,
                  fileName, ruleID, ruleID.getText());
  }
  if ( g.isParser() &&
    Grammar.isTokenName(ruleID.getText()) )
  {
    g.tool.errMgr.grammarError(ErrorType.LEXER_RULES_NOT_ALLOWED,
                  fileName, ruleID, ruleID.getText());
  }
}

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

public void translateLeftRecursiveRules() {
  String language = g.getOptionString("language");
  // translate all recursive rules
  List<String> leftRecursiveRuleNames = new ArrayList<String>();
  for (Rule r : rules) {
    if ( !Grammar.isTokenName(r.name) ) {
      if ( LeftRecursiveRuleAnalyzer.hasImmediateRecursiveRuleRefs(r.ast, r.name) ) {
        boolean fitsPattern = translateLeftRecursiveRule(ast, (LeftRecursiveRule)r, language);
        if ( fitsPattern ) {
          leftRecursiveRuleNames.add(r.name);
        }
        else { // better given an error that non-conforming left-recursion exists
          tool.errMgr.grammarError(ErrorType.NONCONFORMING_LR_RULE, g.fileName, ((GrammarAST)r.ast.getChild(0)).token, r.name);
        }
      }
    }
  }
  // update all refs to recursive rules to have [0] argument
  for (GrammarAST r : ast.getNodesWithType(ANTLRParser.RULE_REF)) {
    if ( r.getParent().getType()==ANTLRParser.RULE ) continue; // must be rule def
    if ( ((GrammarASTWithOptions)r).getOptionString(PRECEDENCE_OPTION_NAME) != null ) continue; // already has arg; must be in rewritten rule
    if ( leftRecursiveRuleNames.contains(r.getText()) ) {
      // found ref to recursive rule not already rewritten with arg
      ((GrammarASTWithOptions)r).setOption(PRECEDENCE_OPTION_NAME, (GrammarAST)new GrammarASTAdaptor().create(ANTLRParser.INT, "0"));
    }
  }
}

代码示例来源:origin: uk.co.nichesolutions/antlr4

public void translateLeftRecursiveRules() {
  String language = g.getOptionString("language");
  // translate all recursive rules
  List<String> leftRecursiveRuleNames = new ArrayList<String>();
  for (Rule r : rules) {
    if ( !Grammar.isTokenName(r.name) ) {
      if ( LeftRecursiveRuleAnalyzer.hasImmediateRecursiveRuleRefs(r.ast, r.name) ) {
        boolean fitsPattern = translateLeftRecursiveRule(ast, (LeftRecursiveRule)r, language);
        if ( fitsPattern ) {
          leftRecursiveRuleNames.add(r.name);
        }
        else { // better given an error that non-conforming left-recursion exists
          tool.errMgr.grammarError(ErrorType.NONCONFORMING_LR_RULE, g.fileName, ((GrammarAST)r.ast.getChild(0)).token, r.name);
        }
      }
    }
  }
  // update all refs to recursive rules to have [0] argument
  for (GrammarAST r : ast.getNodesWithType(ANTLRParser.RULE_REF)) {
    if ( r.getParent().getType()==ANTLRParser.RULE ) continue; // must be rule def
    if ( ((GrammarASTWithOptions)r).getOptionString(PRECEDENCE_OPTION_NAME) != null ) continue; // already has arg; must be in rewritten rule
    if ( leftRecursiveRuleNames.contains(r.getText()) ) {
      // found ref to recursive rule not already rewritten with arg
      ((GrammarASTWithOptions)r).setOption(PRECEDENCE_OPTION_NAME, (GrammarAST)new GrammarASTAdaptor().create(ANTLRParser.INT, "0"));
    }
  }
}

相关文章