- /* LINTED */
- for (n = mdoc->last; n; n = n->parent) {
- if (MDOC_BODY != n->type)
- continue;
- if (tt == n->data.head.tok)
- break;
- if ( ! (MDOC_EXPLICIT & mdoc_macros[tt].flags))
- continue;
- return(mdoc_err(mdoc, tok, ppos, ERR_SCOPE_BREAK));
+
+static int
+rewind_dohalt(int tok, enum mdoc_type type, const struct mdoc_node *p)
+{
+
+ if (MDOC_ROOT == p->type)
+ return(REWIND_HALT);
+ if (MDOC_TEXT == p->type)
+ return(REWIND_NOHALT);
+ if (MDOC_ELEM == p->type)
+ return(REWIND_NOHALT);
+
+ switch (tok) {
+ /* One-liner implicit-scope. */
+ case (MDOC_Aq):
+ /* FALLTHROUGH */
+ case (MDOC_Bq):
+ /* FALLTHROUGH */
+ case (MDOC_D1):
+ /* FALLTHROUGH */
+ case (MDOC_Dl):
+ /* FALLTHROUGH */
+ case (MDOC_Dq):
+ /* FALLTHROUGH */
+ case (MDOC_Op):
+ /* FALLTHROUGH */
+ case (MDOC_Pq):
+ /* FALLTHROUGH */
+ case (MDOC_Ql):
+ /* FALLTHROUGH */
+ case (MDOC_Qq):
+ /* FALLTHROUGH */
+ case (MDOC_Sq):
+ assert(MDOC_BODY != type);
+ assert(MDOC_TAIL != type);
+ if (type == p->type && tok == p->tok)
+ return(REWIND_REWIND);
+ break;
+
+ /* Multi-line implicit-scope. */
+ case (MDOC_It):
+ assert(MDOC_TAIL != type);
+ if (type == p->type && tok == p->tok)
+ return(REWIND_REWIND);
+ if (MDOC_BODY == p->type && MDOC_Bl == p->tok)
+ return(REWIND_HALT);
+ break;
+ case (MDOC_Sh):
+ if (type == p->type && tok == p->tok)
+ return(REWIND_REWIND);
+ break;
+ case (MDOC_Ss):
+ assert(MDOC_TAIL != type);
+ if (type == p->type && tok == p->tok)
+ return(REWIND_REWIND);
+ if (MDOC_BODY == p->type && MDOC_Sh == p->tok)
+ return(REWIND_HALT);
+ break;
+
+ /* Multi-line explicit scope start. */
+ case (MDOC_Ao):
+ /* FALLTHROUGH */
+ case (MDOC_Bd):
+ /* FALLTHROUGH */
+ case (MDOC_Bf):
+ /* FALLTHROUGH */
+ case (MDOC_Bk):
+ /* FALLTHROUGH */
+ case (MDOC_Bl):
+ /* FALLTHROUGH */
+ case (MDOC_Bo):
+ /* FALLTHROUGH */
+ case (MDOC_Do):
+ /* FALLTHROUGH */
+ case (MDOC_Eo):
+ /* FALLTHROUGH */
+ case (MDOC_Fo):
+ /* FALLTHROUGH */
+ case (MDOC_Oo):
+ /* FALLTHROUGH */
+ case (MDOC_Po):
+ /* FALLTHROUGH */
+ case (MDOC_Qo):
+ /* FALLTHROUGH */
+ case (MDOC_Rs):
+ /* FALLTHROUGH */
+ case (MDOC_So):
+ /* FALLTHROUGH */
+ case (MDOC_Xo):
+ if (type == p->type && tok == p->tok)
+ return(REWIND_REWIND);
+ break;
+
+ /* Multi-line explicit scope close. */
+ case (MDOC_Ac):
+ /* FALLTHROUGH */
+ case (MDOC_Bc):
+ /* FALLTHROUGH */
+ case (MDOC_Dc):
+ /* FALLTHROUGH */
+ case (MDOC_Ec):
+ /* FALLTHROUGH */
+ case (MDOC_Ed):
+ /* FALLTHROUGH */
+ case (MDOC_Ek):
+ /* FALLTHROUGH */
+ case (MDOC_El):
+ /* FALLTHROUGH */
+ case (MDOC_Fc):
+ /* FALLTHROUGH */
+ case (MDOC_Ef):
+ /* FALLTHROUGH */
+ case (MDOC_Oc):
+ /* FALLTHROUGH */
+ case (MDOC_Pc):
+ /* FALLTHROUGH */
+ case (MDOC_Qc):
+ /* FALLTHROUGH */
+ case (MDOC_Re):
+ /* FALLTHROUGH */
+ case (MDOC_Sc):
+ /* FALLTHROUGH */
+ case (MDOC_Xc):
+ if (type == p->type && rewind_alt(tok) == p->tok)
+ return(REWIND_REWIND);
+ break;
+ default:
+ abort();
+ /* NOTREACHED */