6.17.5.2 Recognizer order

You may prefer to use a different recognizer sequence, but with (some of the) existing recognizers. You can use the following words for that:

rec-forth ( c-addr u – translation  ) gforth-experimental

The system recognizer: rec-forth is a deferred word that contains a recognizer (sequence). The system’s text interpreter calls rec-forth.

rec-sequence: ( xtu .. xt1 u "name" –  ) gforth-experimental “rec-sequence-colon”

Define a recognizer sequence name. xtu..xt1 are xts of recognizers, and are the initial contents of the recognizer sequence, with xt1 searched first. The order of operands is inspired by get-order and set-order.
name execution: ( c-addr u – translation )
Execute the first xt in the recognizer sequence name. If the resulting translation has a translation token other than translate-none, this is the result of name and no further recognizers are tried. Otherwise, the stacks are restored to the initial state (c-addr u), and the next xt is tried. If all xts produce translate-none, translation is translate-none. name is a recognizer itself, which makes recognizer sequences nestable.

get-recs ( recs-xt – xtu .. xt1 u  ) gforth-experimental

Recs-xt is the execution token of a recognizer sequence. xt1 is the first recognizer searched by this sequence, xtu is the last one. If recs-xt refers to a deferred word, perform defer@ get-recs.

set-recs ( xtu .. xt1 u recs-xt –  ) gforth-experimental

rec-xt is the execution token of a recognizer sequence. Replace the contents of this sequence with xtu...xt_1, where xt1 is searched first, and xtu is searched last. If recs-xt refers to a deferred word, perform defer@ set-recs.

You probably don’t want to create a new recognizer sequence every time you want to change the system recognizer sequence. There are several ways to change an existing recognizer sequence:

rec-none ( c-addr u – translate-none  ) gforth-experimental

This recognizer recognizes nothing. It can be useful as a placeholder.

Here is an example of adding rec-none as last recognizer to the system recognizers:

' rec-none action-of rec-forth get-recs 1+ action-of rec-forth set-recs

\ alternative
' rec-none action-of rec-forth >body >back