Selathco 0.91 Documentation Previous Next

4. Parser

The Selathco built-in parser performs an analysis of the input and tries to match the longest registred text sequence (a sequence is an arbitrary string). If no sequence can be matched, the text is just copied to the output. The registration of a sequence assignes a sequence listener to it and causes calling of the listener each time this sequence is matched.

Example: handling the LaTeX commands
  1. The backslash ("\") is registered as a sequence for the CommandListener.
  2. When the backslash is matched, CommandListener's sequenceFound() method is called - it reads the command name, parses its parameters and verifies its definition (according to the "LatexParser.def" file).
  3. The control is returned to the parser.

The sequence listeners can be added/removed dynamically. Recursive calls of the same sequence listener are prevented. See the Selathco API for more info.

4.1 The LaTeX grammar

The Selathco parser is more pedantic than LaTeX and requires all LaTeX commands to fit the grammar:

      
LaTeX_command: '\' commandName parameters

parameters: /* empty - or "free" (TeX) parameters */
            | mandatory
	    | non_mandatory
	    | parameters

mandatory: '{' text '}'

non_mandatory: '[' text ']'
Notes:

  • Any number of whitespaces is allowed around each token.
  • Free (TeX) parameters must be parsed manually by the command handler.