scenic.syntax.pygment

Pygments lexer and style for Scenic.

These work with the Pygments syntax highlighter. The module actually defines several lexers used for the Scenic documentation; the main ScenicLexer and its associated style ScenicStyle are exported by pyproject.toml as plugins to Pygments. This means that if you have the scenic package installed, the Pygments command-line tool and Python API will automatically recognize Scenic files. For example, to highlight a Scenic program as a self-contained HTML or LaTeX file:

$ pygmentize -f html -Ofull,style=scenic prog.scenic > out.html
$ pygmentize -f latex -Ofull,style=scenic prog.scenic > out.tex

If highlighting multiple pieces of code, remove the full option to avoid having the requisite CSS/preamble material duplicated in all your outputs; you can run pygmentize -S scenic -f html (or latex) to generate that material separately.

Summary of Module Members

Classes

BetterPythonLexer

Python lexer with better highlighting of function calls, parameters, etc.

PegenLexer

Lexer for Pegen grammars.

PythonSnippetLexer

Variant PythonLexer for code snippets rather than complete programs.

ScenicGrammarLexer

Lexer for the grammar notation used in the Scenic docs.

ScenicLexer

Lexer for Scenic code.

ScenicPropertyLexer

Silly lexer to color property names consistently with the real lexer.

ScenicRequirementLexer

Further variant lexer for requirements at the top level.

ScenicSnippetLexer

Variant ScenicLexer for code snippets rather than complete programs.

ScenicSpecifierLexer

Further variant lexer for specifiers at the top level.

ScenicStyle

A style providing specialized highlighting for the Scenic language.

Member Details

class BetterPythonLexer(*args, **kwds)[source]

Bases: PythonLexer

Python lexer with better highlighting of function calls, parameters, etc.

OK, ‘better’ is a matter of opinion; but it provides more informative tokens. These tokens will not cause errors under any Pygments style, but require the style to be aware of them in order to actually get better highlighting: use the ScenicStyle below for best results.

Adapted from the PythonLexer and the MagicPython grammar by MagicStack Inc., available at https://github.com/MagicStack/MagicPython.

class ScenicLexer(*args, **kwds)[source]

Bases: BetterPythonLexer

Lexer for Scenic code.

class ScenicSnippetLexer(*args, **kwds)[source]

Bases: ScenicLexer

Variant ScenicLexer for code snippets rather than complete programs.

Specifically, this lexer formats syntactic variables of the form “{name}” as “name” italicized.

class PythonSnippetLexer(*args, **kwds)[source]

Bases: BetterPythonLexer

Variant PythonLexer for code snippets rather than complete programs.

Specifically, this lexer formats syntactic variables of the form “{name}” as “name” italicized.

class ScenicSpecifierLexer(*args, **kwds)[source]

Bases: ScenicSnippetLexer

Further variant lexer for specifiers at the top level.

class ScenicRequirementLexer(*args, **kwds)[source]

Bases: ScenicSnippetLexer

Further variant lexer for requirements at the top level.

class ScenicPropertyLexer(*args, **kwds)[source]

Bases: RegexLexer

Silly lexer to color property names consistently with the real lexer.

class ScenicGrammarLexer(*args, **kwds)[source]

Bases: RegexLexer

Lexer for the grammar notation used in the Scenic docs.

class ScenicStyle[source]

Bases: Style

A style providing specialized highlighting for the Scenic language.

The color scheme is a loose hybrid of that used in the Scenic papers and the ‘Mariana’ color scheme from Sublime Text. The chosen colors all have a contrast ratio of at least 4.5:1 against the background color, per the W3C’s Web Content Accessibility Guidelines.

class PegenLexer(*args, **kwds)[source]

Bases: BetterPythonLexer

Lexer for Pegen grammars.