当前位置: 首页>>代码示例>>C++>>正文


C++ pANTLR3_BASE_TREE::getToken方法代码示例

本文整理汇总了C++中pANTLR3_BASE_TREE::getToken方法的典型用法代码示例。如果您正苦于以下问题:C++ pANTLR3_BASE_TREE::getToken方法的具体用法?C++ pANTLR3_BASE_TREE::getToken怎么用?C++ pANTLR3_BASE_TREE::getToken使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在pANTLR3_BASE_TREE的用法示例。


在下文中一共展示了pANTLR3_BASE_TREE::getToken方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: dumpNode

void SCsTranslator::dumpNode(pANTLR3_BASE_TREE node, std::ofstream &stream)
{
    StringStream ss;
    ss << node;

    String s_root = ss.str().substr(3);
    pANTLR3_COMMON_TOKEN tok = node->getToken(node);
    if (tok)
    {
        stream << s_root << " [shape=box];" << std::endl;
        String label((const char*) node->getText(node)->chars);
        std::replace(label.begin(), label.end(), '"', '\'');
        stream << s_root << " [label=\"" << label << "\"];" << std::endl;
    }
    else
        stream << s_root << " [shape=circle];" << std::endl;

    uint32 n = node->getChildCount(node);
    for (uint32 i = 0; i < n; ++i)
    {
        pANTLR3_BASE_TREE child = (pANTLR3_BASE_TREE) node->getChild(node, i);
        StringStream s1;
        s1 << child;

        stream << s_root << " -> " << s1.str().substr(3) << ";" << std::endl;
        dumpNode(child, stream);
    }
}
开发者ID:rusetski-k,项目名称:sc-machine,代码行数:28,代码来源:scs_translator.cpp

示例2: emerson_printAST

pANTLR3_STRING emerson_printAST(pANTLR3_BASE_TREE tree, pANTLR3_UINT8* parserTokenNames)
{
  pANTLR3_STRING  string;
  ANTLR3_UINT32   i;
  ANTLR3_UINT32   n;
  pANTLR3_BASE_TREE   t;


  if(tree->children == NULL || tree->children->size(tree->children) == 0)
  {
      return	tree->toString(tree);
  }

  // THis is how you get a new string. The string is blank

  string = tree->strFactory->newRaw(tree->strFactory);

  if(tree->isNilNode(tree) == ANTLR3_FALSE)
  {
      string->append8	(string, "(");
      pANTLR3_COMMON_TOKEN token = tree->getToken(tree);
      ANTLR3_UINT32 type = token->type;

      string->append(string, (const char*)parserTokenNames[type]);
      string->append8(string, " ");
  }

  if(tree->children != NULL)
  {
      n = tree->children->size(tree->children);
      for	(i = 0; i < n; i++)
      {
          t   = (pANTLR3_BASE_TREE) tree->children->get(tree->children, i);

          if  (i > 0)
          {
              string->append8(string, " ");
          }
          string->appendS(string, emerson_printAST(t,parserTokenNames));
      }
  }

  if(tree->isNilNode(tree) == ANTLR3_FALSE)
  {
      string->append8(string,")");
  }

  return  string;
}
开发者ID:LittleForker,项目名称:sirikata,代码行数:49,代码来源:Util.cpp

示例3: dumpTree

std::string MySQLRecognitionBase::dumpTree(pANTLR3_UINT8 *tokenNames, pANTLR3_BASE_TREE tree, const std::string &indentation)
{
  std::string result;

  ANTLR3_UINT32 char_pos = tree->getCharPositionInLine(tree);
  ANTLR3_UINT32 line = tree->getLine(tree);
  pANTLR3_STRING token_text = tree->getText(tree);

  pANTLR3_COMMON_TOKEN token = tree->getToken(tree);
  const char* utf8 = (const char*)token_text->chars;
  if (token != NULL)
  {
    ANTLR3_UINT32 token_type = token->getType(token);

    pANTLR3_UINT8 token_name;
    if (token_type == EOF)
      token_name = (pANTLR3_UINT8)"EOF";
    else
      token_name = tokenNames[token_type];

#ifdef ANTLR3_USE_64BIT
    result = base::strfmt("%s(line: %i, offset: %i, length: %" PRId64 ", index: %" PRId64 ", %s[%i])    %s\n",
                          indentation.c_str(), line, char_pos, token->stop - token->start + 1, token->index, token_name,
                          token_type, utf8);
#else
    result = base::strfmt("%s(line: %i, offset: %i, length: %i, index: %i, %s[%i])    %s\n",
                          indentation.c_str(), line, char_pos, token->stop - token->start + 1, token->index, token_name,
                          token_type, utf8);
#endif

  }
  else
  {
    result = base::strfmt("%s(line: %i, offset: %i, nil)    %s\n", indentation.c_str(), line, char_pos, utf8);
  }

  for (ANTLR3_UINT32 index = 0; index < tree->getChildCount(tree); index++)
  {
    pANTLR3_BASE_TREE child = (pANTLR3_BASE_TREE)tree->getChild(tree, index);
    std::string child_text = dumpTree(tokenNames, child, indentation + "\t");
    result += child_text;
  }
  return result;
}
开发者ID:ThiagoGarciaAlves,项目名称:mysql-workbench,代码行数:44,代码来源:mysql-parser-common.cpp

示例4: determineSentenceType

SCsTranslator::eSentenceType SCsTranslator::determineSentenceType(pANTLR3_BASE_TREE node)
{
    pANTLR3_COMMON_TOKEN tok = node->getToken(node);
    assert(tok);

    if (tok->type == SEP_SIMPLE)
        return SentenceLevel1;

    if (tok->type == CONNECTORS)
        return SentenceLevel2_7;

    if (tok->type == SEP_ASSIGN)
        return SentenceAssign;

    if (tok->type == EOF)
        return SentenceEOF;

    return SentenceUnknown;
}
开发者ID:rusetski-k,项目名称:sc-machine,代码行数:19,代码来源:scs_translator.cpp

示例5:

static	pANTLR3_COMMON_TOKEN    
getToken	(pANTLR3_BASE_TREE_ADAPTOR adaptor, pANTLR3_BASE_TREE t)
{
	return t->getToken(t);
}
开发者ID:jariba,项目名称:europa-pso,代码行数:5,代码来源:antlr3commontreeadaptor.c

示例6: token_text

/**
* Returns the text of the given node. The result depends on the type of the node. If it represents
* a quoted text entity then two consecutive quote chars are replaced by a single one and if
* escape sequence parsing is not switched off (as per sql mode) then such sequences are handled too.
*/
std::string MySQLRecognitionBase::token_text(pANTLR3_BASE_TREE node, bool keepQuotes)
{
  pANTLR3_STRING text = node->getText(node);
  if (text == NULL)
    return "";

  std::string chars;
  pANTLR3_COMMON_TOKEN token = node->getToken(node);
  ANTLR3_UINT32 type = (token != NULL) ? token->type : ANTLR3_TOKEN_INVALID;

  if (type == STRING_TOKEN)
  {
    // STRING is the grouping subtree for multiple consecutive string literals, which
    // must be concatenated.
    for (ANTLR3_UINT32 index = 0; index < node->getChildCount(node); index++)
    {
      pANTLR3_BASE_TREE child = (pANTLR3_BASE_TREE)node->getChild(node, index);
      chars += token_text(child, keepQuotes);
    }

    return chars;
  }

  chars = (const char*)text->chars;
  std::string quote_char;
  switch (type)
  {
  case BACK_TICK_QUOTED_ID:
    quote_char = "`";
    break;
  case SINGLE_QUOTED_TEXT:
    quote_char = "'";
    break;
  case DOUBLE_QUOTED_TEXT:
    quote_char = "\"";
    break;
  default:
    return chars;
  }

  // First unquote then handle escape squences and double quotes.
  if (chars.size() < 3)
  {
    if (keepQuotes)
      return chars;
    return ""; // Also handles an invalid single quote char gracefully.
  }

  // Need to unquote even if keepQuotes is true to avoid trouble with replacing the outer quotes.
  // Add them back below.
  chars = base::unquote(chars);

  if ((d->_sql_mode & SQL_MODE_NO_BACKSLASH_ESCAPES) == 0)
    chars = base::unescape_sql_string(chars, quote_char[0]);
  else
    if (token->user1 > 0)
    {
      // The field user1 is set by the parser to the number of quote char pairs it found.
      // So we can use it to shortcut our handling here.
      base::replace(chars, quote_char + quote_char, quote_char);
    }

  if (keepQuotes)
    return quote_char + chars + quote_char;
  return chars;
}
开发者ID:Sonano,项目名称:mysql-workbench,代码行数:71,代码来源:mysql-parser-common.cpp

示例7: GetToken

 pANTLR3_COMMON_TOKEN GetToken(pANTLR3_BASE_TREE node)
 {
     return node->getToken(node);
 }
开发者ID:ldh9451,项目名称:XLE,代码行数:4,代码来源:InterfaceSignature.cpp


注:本文中的pANTLR3_BASE_TREE::getToken方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。