Status

From BorielWiki
Jump to: navigation, search

If you're familiar with LEX/YACC environment, you will know (F)Lex uses start conditions which will tell the scanner under which conditions (status) the pattern definitions should be ignored or taken into consideration.

In Blex, these are referred as Status, but in practice they're the same. A Status is an object which stores information about an start condition.

The Status Class

The status class contains which patterns are to be recognized when the scanner enters it. It has the following properties:

  • name: It's just a string identifying the status. E.g. 'BEGIN' or 'COMMENT'.
  • patterns: A dictionary (hash) which maps regular expression strings (e.g. '[a-zA-Z]+') against pattern objects. This property is useful to look up pattern objects by its regular expression.
  • pattern_table: A list containing the regular expression strings already defined. This list is ordered, so newer defined patterns appears first. This is used by the Blex instance when the pattern definition order is important. See Blex operation modes for more information. When the Blex instance enter a given status, only the patterns defined in its pattern table are matched against the input.

To create or switch Blex status, see Blex add_status and set_status methods respectively.

Reserved Status Names

The following status names are reserved:

  • YY_INITIAL: This is the status the Blex instance enter when it's created. It can be also referred by the constant YY_STATUS_INITIAL (desirable).
  • YY_ERROR: Reserved for internal use (currently unused). Can be referred by the constant YY_STATUS_ERROR (desirable).
  • YY_NONE: An undefined stated (internal, currently unused). Can be referred by the constant YY_STATUS_NONE (desirable).