]> ocean-lang.org Git - ocean/commitdiff
parsergen: split out heart-of-the-parser code
authorNeilBrown <neil@brown.name>
Wed, 10 Mar 2021 00:12:50 +0000 (11:12 +1100)
committerNeilBrown <neil@brown.name>
Wed, 10 Mar 2021 01:01:03 +0000 (12:01 +1100)
This finishes the break up of the core parser code.

Signed-off-by: NeilBrown <neil@brown.name>
csrc/parsergen.mdc

index 4708e0c01c6ce80f7665ae2f02e1a9f9260acdab..554e63c37c921faea604399f7a9dd1f968b7cc84 100644 (file)
@@ -2724,6 +2724,28 @@ Now we have the parser.  For each token we might shift it, trigger a
 reduction, or start error handling.  2D tokens (IN, OUT, EOL) also need
 to be handled.
 
+###### parser vars
+
+       struct parser p = { 0 };
+       struct token *tk = NULL;
+       int accepted = 0;
+
+###### heart of parser
+
+       shift(&p, TK_eof, NULL, states);
+       while (!accepted && p.tos > 0) {
+               struct frame *tos = &p.stack[p.tos-1];
+               if (!tk)
+                       tk = tok_copy(token_next(tokens));
+               parser_trace(trace, &p,
+                            tk, states, non_term, config->known_count);
+
+               ## try shift or ignore
+               ## try reduce
+               ## handle error
+       }
+
+
 We return whatever `asn` was returned by reducing production zero.
 
 When we find `TK_in` and `TK_out` tokens which report indents we need
@@ -2899,23 +2921,10 @@ dropping tokens until either we manage to shift one, or reach end-of-file.
                         FILE *trace, const char *non_term[],
                         struct token_config *config)
        {
-               struct parser p = { 0 };
-               struct token *tk = NULL;
-               int accepted = 0;
                ## parser vars
 
-               shift(&p, TK_eof, NULL, states);
-               while (!accepted && p.tos > 0) {
-                       struct frame *tos = &p.stack[p.tos-1];
-                       if (!tk)
-                               tk = tok_copy(token_next(tokens));
-                       parser_trace(trace, &p,
-                                    tk, states, non_term, config->known_count);
+               ## heart of parser
 
-                       ## try shift or ignore
-                       ## try reduce
-                       ## handle error
-               }
                free(tk);
                pop(&p, p.tos, do_free);
                free(p.asn_stack);