Install & Compatibility
Where this runs
tested against v1.0.0 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
muslpy 3.10–3.95 runs
installs and imports cleanly · install 0.0s · import 0.000s · 17.9MB
glibcpy 3.10–3.95 runs
installs and imports cleanly · install 1.5s · import 0.000s · 18MB
16MB installed
● package 16MB
Code
Verified usage
Verified import paths — ran on the pinned version, not inferred.
Token
✓ from pygmars import Token
✗ from pygmars import Lexer
as_token_label
✓ from pygmars import as_token_label
convert_pygments_token_to_label
✓ from pygmars import convert_pygments_token_to_label
Create a lexer for arithmetic expressions, define a grammar, and parse a simple expression.
from pygmars import Lexer, Grammar, Parser
# Define a simple grammar for arithmetic expressions
lexer = Lexer()
lexer.add_token('NUM', r'\d+')
lexer.add_token('PLUS', r'\+')
lexer.add_token('MINUS', r'-')
lexer.add_token('TIMES', r'\*')
lexer.add_token('DIVIDE', r'/')
lexer.add_token('LPAREN', r'\(')
lexer.add_token('RPAREN', r'\)')
lexer.add_ignore(' ')
grammar = Grammar()
grammar.add_production('E', ['E', 'PLUS', 'T'])
grammar.add_production('E', ['T'])
grammar.add_production('T', ['T', 'TIMES', 'F'])
grammar.add_production('T', ['F'])
grammar.add_production('F', ['LPAREN', 'E', 'RPAREN'])
grammar.add_production('F', ['NUM'])
parser = Parser(grammar)
tokens = lexer.tokenize('2+3*4')
parse_tree = parser.parse(tokens)
print(parse_tree.pformat())
Upgrade
Version history
1.0.0latest on PyPI · released Jul 16, 2025
Audit
Dependencies
pygmentsoptionalPygmars accepts Pygments lexers as input