A grammar rule is a readable claim about which part of the source starts here.

PEG means Parsing Expression Grammar. Unlike a grammar notation that treats alternatives as unordered sets, a PEG gives ordered choice a meaning: try the first alternative, and consider later alternatives according to the parser's ordered-choice rules. This makes ordering useful for a scanner. A comment or a quoted string should be recognized before the generic identifier and punctuation rules that could otherwise consume part of it.

In this project, a grammar's Token rule is the scanning entry point. It tries token categories in an intentional order and ends with a catch-all rule so every source character can be accounted for. The grammar is not trying to prove that a complete program is valid. Its job is to identify lexical regions that should receive a color in a code sample.

Token <- Comment / DoubleQuotedString / Keyword / Identifier / Whitespace / Other
Comment <- @hash LineCommentBody
Keyword <- ('let' / 'return') !IdentifierContinue
Other <- .
Comment comment
Keyword keyword
Identifier variable

This small scanner reuses DoubleQuotedString, Identifier, Whitespace, LineCommentBody, and IdentifierContinue from the common lexicon. The @hash spelling comes from the shared symbol catalog. The negative lookahead after a keyword checks that a keyword is not merely the prefix of a longer identifier: let is a keyword, while letter remains an identifier.

The grammar describes token boundaries, not their final colors. An adjacent roles file maps rule names such as Comment and Keyword to semantic roles such as comment and keyword. The active theme then supplies the colors for those roles. The same scanner can therefore use different palettes without changing its PEG rules.

A scanner is intentionally smaller than a language parser

Real programming languages contain context-sensitive questions that a simple colorizer does not need to settle. A slash can mean division or begin a regular expression; a word can be a command name in one position and an ordinary identifier in another. A lexical grammar can cover the common forms clearly and document what it leaves ambiguous. It should not claim to validate every language version or every expression.

That limited goal makes grammars easier to compose and review. The existing LiveScript PEG highlights the language used by the framework itself. The separate PowerShell PEG handles the operating-system bridge examples. Both are discovered through the grammar catalog, both reuse the common lexicon, and neither is confused with a literal highlighter that simply finds exact text.