#define parse_enter() \
(printf("%*c-> %s\n", ++Indent * 2, ' ', __func__))
#define parse_exit() \
- (printf("%*c<- %s\n", --Indent * 2, ' ', __func__))
+ Indent--
+// (printf("%*c<- %s\n", --Indent * 2, ' ', __func__))
#else
#define parse_enter()
#define parse_exit()
/* Grammar Definition
*****************************************************************************/
-void import_list(Parser* p)
+static void import_list(Parser* p)
{
parse_enter();
expect(p, IMPORT);
parse_exit();
}
+static void declaration_seq(Parser* p)
+{
+ (void)p;
+}
+
+static void statement_seq(Parser* p)
+{
+ (void)p;
+}
+
void module(Parser* p)
{
parse_enter();
{
import_list(p);
}
-// declaration_seq(p);
+ declaration_seq(p);
if (accept(p, BEGIN))
{
-// statement_seq(p);
+ statement_seq(p);
}
expect(p, END);
char* ename = expect_text(p, IDENT);
Parser Ctx = {0};
-void parse_module(char* fname, char* string)
+void parse_init(char* fname, char* string)
{
memset(&Ctx, 0, sizeof(Ctx));
LexFile* file = calloc(sizeof(LexFile), 1u);
file->fbeg = file->fpos = strdup(string);
file->next = Ctx.file;
Ctx.file = file;
+}
+
+static void parse_rule(void (*rule)(Parser*), char* string)
+{
+ parse_init("test_input", string);
+ rule(&Ctx);
+}
+
+static void parse_module(char* fname, char* string)
+{
+ parse_init(fname, string);
module(&Ctx);
}
"module Empty; end Empty;");
parse_module("ModA",
"module ModA; import ModB; end ModA;");
- parse_module("ModA",
- "module ModA; import ModB, ModC; end ModA;");
- parse_module("ModA",
- "module ModA; import B = ModB, C = ModC; end ModA;");
+ }
+
+ TEST(Should parse imports)
+ {
+ parse_rule(import_list,
+ "import A;");
+ parse_rule(import_list,
+ "import A = ModA;");
+ parse_rule(import_list,
+ "import A, B;");
+ parse_rule(import_list,
+ "import A, B = ModB, C;");
}
}
#endif