Syntax Reference

Below are syntax diagrams for Paxter language.

  • Document: Starting rule of Paxter language grammar. It is a special case of FragmentList rule, and thus the result is always a FragmentList node whose children are non-empty Text interleaving with the result produced by AtExpression rule.

    _images/Document.png

     

  • AtExpression: Rule for parsing right after encountering @-switch symbol.

    _images/AtExpression.png

     

    Note

    The red else box in this diagram indicates that such path can be followed only if the next token does not match any other possible paths. Pursuing this else path does not consume anything.

    There are 2 possible scenarios.

    1. A normal Command node consisting of 3 sections: starter, options, and main argument, respectively.

      The starter section is resulted from parsing either greedily for an identifier or non-greedily for a text enclosed by a pair of bars plus and an equal number of zero or more hashes at both ends.

      Following the starter section, if a left square bracket is found, then the option section as a list of tokens must be parsed and it will result in a TokenList node. Otherwise (if the left square bracket is absent), this option section will be represented by None.

      Finally, the main argument section. (a) If there is zero or more hashes followed by a left brace, then the FragmentList parse rule must be followed and thus yields FragmentList as the result.

      Warning

      There is a restriction imposed on parsing the FragmentList rule, which is that the child text node may not contain a right brace followed by the same number of hashes as the preceding part. Otherwise, the parsing of FragmentList rule would have terminated earlier.

      However, (b) if there is zero or more hashes followed by a quotation mark, then the text is parsed non-greedily until the another quotation mark followed by the same number of hashes is found.

      Well, if both conditions (a) and (b) do not hold, then the main argument would be None.

    2. A special SingleSymbol node where a single symbol follows the @-switch.

  • FragmentList: Consists of an interleaving of non-empty texts and results produced by AtExpression rule.

    Note that the parsing of AtExpression rule at the previous level may put some restriction on the parsing of Text nodes. For example, if preceding the fragment list is an opening brace pattern ###{, then each Text node may contain }###.

    In other words, we non-greedily parses text within the fragment list.

    _images/FragmentList.png

     

  • TokenList: A sequence of zero or more tokens Each token either a command, an identifier, an operator, a number following JSON specification, a wrapped fragment list, a wrapped text, or a nested token list enclosed by a pair of square brackets []. The result is a TokenList node type.

    _images/TokenList.png

     

    Note

    The option section (or the token list) is the only place where whitespaces are ignored (when they appear between tokens).

     

  • Identifier: Generally follows Python rules for greedily parsing an identifier token (with some extreme exceptions). The result is an Identifier node type.

    _images/Identifier.png

     

  • Operator: Greedily consumes as many operator character as possible (with two notable exceptions: a comma and a semicolon, which has to appear on their own). A whitespace may be needed to separate two consecutive, multi-character operator tokens. The result is an Operator node type.

    _images/Operator.png