MCPcopy Create free account
hub / github.com/GJDuck/e9patch / parseMatchExpr

Function parseMatchExpr

src/e9tool/e9action.cpp:802–853  ·  view source on GitHub ↗

* Parse a match expr. */

Source from the content-addressed store, hash-verified

800 * Parse a match expr.
801 */
802static MatchExpr *parseMatchExpr(Parser &parser, int prec = 99)
803{
804 MatchExpr *expr = nullptr;
805 int t = parser.peekToken();
806 switch (t)
807 {
808 case '(':
809 (void)parser.getToken();
810 expr = parseMatchExpr(parser);
811 parser.expectToken(')');
812 break;
813 case '!': case TOKEN_NOT:
814 (void)parser.getToken();
815 expr = parseMatchExpr(parser, 10);
816 expr = new MatchExpr(MATCH_OP_NOT, expr);
817 break;
818 case TOKEN_NONE:
819 (void)parser.getToken();
820 expr = parseMatchExpr(parser, 0);
821 break;
822 case '~': case '-':
823 (void)parser.getToken();
824 expr = parseMatchExpr(parser, 0);
825 expr = new MatchExpr((t == '-'? MATCH_OP_NEG: MATCH_OP_BIT_NOT),
826 expr);
827 break;
828 case TOKEN_DEFINED:
829 (void)parser.getToken();
830 parser.expectToken('(');
831 expr = parseMatchExpr(parser);
832 parser.expectToken(')');
833 expr = new MatchExpr(MATCH_OP_DEFINED, expr);
834 break;
835 default:
836 {
837 auto arg = parseMatchArg(parser);
838 expr = new MatchExpr(MATCH_OP_ARG, arg);
839 break;
840 }
841 }
842 while (true)
843 {
844 int t = parser.peekToken();
845 const MatchOpInfo *info = parseMatchOp(t);
846 if (info == nullptr || info->prec > prec)
847 break;
848 (void)parser.getToken();
849 MatchExpr *arg = parseMatchExpr(parser, info->prec-1);
850 expr = new MatchExpr(info->op, expr, arg);
851 }
852 return expr;
853}
854
855/*
856 * Parse a match expr.

Callers 1

parseMatchFunction · 0.85

Calls 5

parseMatchArgFunction · 0.85
parseMatchOpFunction · 0.85
peekTokenMethod · 0.80
getTokenMethod · 0.80
expectTokenMethod · 0.80

Tested by

no test coverage detected