Skip to content

Latest commit

 

History

History
63 lines (44 loc) · 2.77 KB

README.md

File metadata and controls

63 lines (44 loc) · 2.77 KB

Tree-sitter grammar for the PIC language

License Build Status

Pic is a domain-specific language by Brian W. Kernighan for specifying diagrams. It is mostly used in combination with the groff typesetting system but is also a valid input format for some programs found in the plotutils package.

A typical document preparation workflow using the PIC preprocessor could look like this:

PIC demo

The following input was used to create this picture:

.PS
ellipse "document"
arrow
box "PIC"
arrow
box "TBL/EQN" "(optional)" dashed
arrow
box "TROFF"
arrow
ellipse "typesetter"
.PE

Limitations

The following limitations are known.

Macros definitions and macro parameters may be parsed incorrectly

Macros are not part of the Pic language. When the scanner finds a macro call, it does a simple text replacement using the macro parameters. Neither the macro definition nor the macro call needs to be a correct Pic statement or expression. This makes is impossible to parse all macros correctly.

See the following example which is perfectly legal code for pic:

define foo { circle at $1 $2 }
foo((2,2), diam 1)
foo((3,5), rad 1)

The copy thru statement may be parsed incorrectly

Consider the following piece of code:

copy thru X
  box "$1"
X
10

When GNU pic parses this code, it checks if X has been defined as a macro. If it is a macro, then it is called using the following three lines as data. If X is not defined as a macro, then it is parsed as a character delimiter and the block between the two X characters is used as an inline macro.

The tree-sitter implementation doesn't record the defined macros and may therefore parse this specific piece of code differently. You can use longer macro names and non-alphabetic letters as inline macro delimiters to avoid this ambiguity.

References

  1. Brian W. Kernighan, PIC - A Graphics Language for Typesetting - User Manual
  2. Eric S. Raymond, Making Pictures with GNU PIC
  3. W. Richard Stevens, Examples of pic Macros