SyntaxTree* OperatorParser::parse(void) { HMD_ASSERT(m_parser); m_ErrorPos startPos = m_curErrPos(); SyntaxTree* st = m_parser->parse(); const char* n = name(); if (st->isError()) { m_fail(startPos); if (! st->isFatalError()) { char pbuf[128]; gpInp->sprintSourceInfo(pbuf, 128, startPos.parsePos); HMD_PRINTF("%s %s -> ERROR %d\n", n, pbuf, st->errorCutId); } return m_FATAL_PARSER_ERROR; } if (st->isFail()) { if (m_printIntermediateLevel > 2) { char pbuf[128]; gpInp->sprintSourceInfo(pbuf, 128, startPos.parsePos); HMD_PRINTF("%s %s -> fail\n", n, pbuf); } m_fail(startPos); return m_PARSE_FAILED; } if (m_printIntermediateLevel > 1) { char pbuf[128]; gpInp->sprintSourceInfo(pbuf, 128, startPos.parsePos); if (st->isValidTree()) { char b[44]; gpInp->copySummary(b, 40, st->str); HMD_PRINTF("%s %s -> '%s'\n", n, pbuf, b); } else { HMD_PRINTF("%s %s -> (notree)\n", n, pbuf); } } #if 0 if (st->isValidTree()) { if (st->numChild() == 1) { // no operator, so that this node is not needed SyntaxTree* tmp = st->replace(0, NULL); if (! m_bUseMemoize) delete st; return tmp; } } #endif return st; }
SyntaxTree* Parser::m_parse_notPredicate(Parser* p) { m_ErrorPos startPos = m_curErrPos(); SyntaxTree* st = p->parse(); if (st->isFatalError()) { m_fail(startPos); return st; } m_back(startPos); if (! st->isFail()) { if (! m_bUseMemoize) { SyntaxTree::deleteRecursively(st); } return m_PARSE_FAILED; } return m_NO_SYNTAX_TREE; }