- * If not, generate an error, eat the current statement,
- * and goto the error_label label.
- */
-#define expect(expected, error_label) \
- do { \
- if (UNLIKELY(token.kind != (expected))) { \
- parse_error_expected(NULL, (expected), NULL); \
- add_anchor_token(expected); \
- eat_until_anchor(); \
- rem_anchor_token(expected); \
- if (token.kind != (expected)) \
- goto error_label; \
- } \
- next_token(); \
- } while (0)
+ * If not, generate an error and skip until the next anchor.
+ */
+static void expect(token_kind_t const expected)
+{
+ if (UNLIKELY(token.kind != expected)) {
+ parse_error_expected(NULL, expected, NULL);
+ add_anchor_token(expected);
+ eat_until_anchor();
+ rem_anchor_token(expected);
+ if (token.kind != expected)
+ return;
+ }
+ eat(expected);
+}
+
+static symbol_t *expect_identifier(char const *const context, source_position_t *const pos)
+{
+ if (token.kind != T_IDENTIFIER) {
+ parse_error_expected(context, T_IDENTIFIER, NULL);
+ add_anchor_token(T_IDENTIFIER);
+ eat_until_anchor();
+ rem_anchor_token(T_IDENTIFIER);
+ if (token.kind != T_IDENTIFIER)
+ return NULL;
+ }
+ symbol_t *const sym = token.identifier.symbol;
+ if (pos)
+ *pos = *HERE;
+ eat(T_IDENTIFIER);
+ return sym;
+}