This file describes the grammar of the input files to Pikchr. Keywords and operators are shown in bold. Non-terminal symbols are shown in italic. Special token classes are shown in ALL-CAPS. A grammar symbol followed by "*" means zero-or-more. A grammar symbol followed by "?" means zero-or-one. Parentheses are used for grouping. Two grammar symbols within "(..|..)" means one or the other. Marks of the form "▶info" are links to more information and are not part of the grammar.
The following special token classes are recognized:
NEWLINE → A un-escaped newline character, U+000A. A backslash followed by zero or more whitespace characters and then a U+000A character is interpreted as ordinary whitespace, not as a NEWLINE.
LABEL → An object or place label starting with an upper-case ASCII letter and continuing with zero or more ASCII letters, digits, and/or underscores. A LABEL always starts with an upper-case letter.
VARIABLE → A variable name consisting of a lower-case ASCII letter or "$" or "@" and followed by zero or more ASCII letters, digits, and/or underscores. VARIABLEs may contain upper-case letters, but they never begin with an upper-case. In this way, VARIABLEs are distinct from LABELs.
NUMBER → A numeric literal. The value can be a decimal integer, a floating point value, or a hexadecimal literal starting with "0x". Decimal and floating point values can optionally be followed by a two-character unit designator that is one of: "in", "cm", "px", "pt", "pc", or "mm". There can be no whitespace in between the numeric portion of the constant and the unit.
ORDINAL → A non-zero integer literal followed by one of the suffixes "st", "nd", "rd", or "th". Examples: "1st", "2nd", "3rd", "4th", "5th", and so forth. As a special case, "first" is accepted as an alternative spelling of "1st".
STRING → A string literal that begins and ends with double-quotes (U+0022). Within the string literal, a double-quote character can be escaped using backslash (U+005c). A backslash can also be used to escape a backslash. No other escape sequences are recognized.
COLORNAME → One of the 140 official HTML color names, in any mixture of upper and lower cases. The value of a COLORNAME is an integer which is the 24-bit RGB value of that color. Two additional color names of "None" and "Off" are also recognized and have a value of -1.
CODEBLOCK → All tokens contained within nested {...}. This is only used as the body of a "define" statement.
There are many non-terminals in the grammar, but a few are more important. If you are new to the Pikchr language, begin by focusing on these six:
statement → A Pikchr script is just a list of statements.
attribute → Each graphic object is configured with zero or more attributes.
object → A reference to a prior graphic object.
place → A specific point associated with an object.
position → Any (2-D) point in space. An (x,y) pair.
expr → A scalar expression.
A complete input file to Pikchr consists of a single statement-list.