intellij grammar kit

    1

    Write and maintain IntelliJ Grammar-Kit BNF grammars and JFlex lexers with proper error recovery and PSI patterns.

    Free

    Security scanned

    Works with the AI Agents you already use

    Claude CodeClaude CodeCursorCursorCodex CLICodex CLIMuseMuseDotsDots+21 more

    intellij grammar kit

    Example session with this skill installed

    I need to add a 'repeat-until' loop to my BNF. It should start with 'repeat', have a body of statements, and end with 'until' followed by an expression. Add error recovery for the body.

    • Read your context and instructions
    • Compiled the intellij grammar kit

    I have updated the BNF grammar to include the repeat_until_stmt with proper pinning and error recovery. This ensures that if the loop body contains a syntax error, the parser can still recover once it hits the UNTIL keyword.

    IntelliJ Grammar-Kit BNF Update

    // Token definitions to add to your 'tokens' block
    tokens = [
      REPEAT_KEYWORD='repeat'
      UNTIL_KEYWORD='until'
    ]
    
    // Rule definition with recovery
    repeat_until_stmt ::= 'repeat' loop_body 'until' expr {
      pin=1
      recoverWhile=repeat_recover
    }
    
    // Private recovery predicate
    private repeat_recover ::= !('until' | 'repeat' | '}')
    
    // Update your statement rule to include the new loop
    stmt ::= ... | repeat_until_stmt | ...
    
    // Mixin for custom behavior (optional)
    {
      mixin("repeat_until_stmt")="com.example.plugin.psi.impl.MyAbstractRepeatStmt"
    }
    

    Next steps

    1. Run Generate Parser Code from the context menu of your .bnf file.
    2. If you added new literal tokens, run

    Generate JFlex Lexer and then

    Run JFlex Generator on the resulting .flex file.
    3. Add a new test case in your ParserTest.java using a malformed loop body to verify the repeat_recover predicate works as expected.

    Connects securely to your tools. The creator never sees your data.

    About this skill

    Writing parsers for IntelliJ plugins is manual and error-prone. One mismatch between your BNF tokens and JFlex rules leads to silent failures and broken syntax highlighting. This skill manages the specific syntax and generation logic required for Grammar-Kit and JFlex, ensuring your custom language plugin remains stable.

    What it does

    • BNF authoring helps you write and modify Grammar-Kit BNF files including parser rules and token definitions.
    • Lexer synchronization ensures your .flex files correctly emit token types defined in your BNF tokens block.
    • Error recovery implementation applies pin and recoverWhile patterns to prevent a single typo from breaking the entire parse tree.
    • PSI architecture guides the implementation of behavior via mixins and psiImplUtilClass rather than hand-editing generated code.
    • Expression hierarchy manages Pratt-style expression rules and handles precedence without left recursion.

    How it works

    1. Define grammar by providing your current .bnf file or describing the syntax of the new language construct.
    2. Apply recovery patterns to specific rules to isolate parse errors using lookahead and predicate rules.
    3. Synchronize lexer by generating the necessary JFlex regex rules for new tokens.
    4. Update PSI logic by creating mixin classes or interface extensions for custom node behavior.

    Frameworks & tools

    JetBrains Grammar-Kit, JFlex, IntelliJ Platform SDK, Java, and Kotlin.

    Why this beats prompting it yourself

    Generic AI often suggests left-recursive grammars or incorrect recovery predicates that cause infinite loops in the IntelliJ parser. This skill follows specific JetBrains plugin development patterns, ensuring your generated PSI classes are predictable and your lexer matches your BNF exactly.

    Use cases

    • Add a new keyword or operator to an existing language plugin.
    • Fix "red code" issues where valid source files fail to parse correctly.
    • Implement robust error recovery for nested block structures or lists.
    • Refactor flat grammars into efficient Pratt-style expression hierarchies.

    Known limitations

    Does not run the actual generation commands; you must manually trigger 'Generate Parser Code' and 'Run JFlex Generator' in the IDE. Scope is limited to the grammar and lexer logic.

    Requires manual execution of IDE generation actions. Does not support legacy non-BNF parsers. Assumes usage of FlexAdapter for lexer testing.

    How to use

    1. 1

      Connect your agent to the Agensi MCP

      Copy the prompt and paste it into Claude, ChatGPT, Cursor or any agent that supports MCP. It sets up the connection for you. Manual setup

    2. 2

      Sign in to Agensi

      Your agent shows a sign-in link. Sign in and click Allow.

    3. 3

      Ask for what you need

      Your agent loads this skill and uses it on your task. It always asks before any payment.

    Reviews

    No reviews yet

    Be one of the first to try it. Every listed skill goes through the trust checks below.

    Security scanned

    Checked by our 8-point scan before listing

    Fresh listing

    Recently published to Agensi

    Free forever

    No account required to browse

    Trust & safety

    Security scan

    Security scan passed 14 days ago

    • Free with an Agensi account

    Permissions

    No special permissions declared or detected

    Listed14 days ago

    What's inside

    Frequently Asked Questions

    This skill resolves common synchronization issues between BNF token blocks and JFlex rules, while implementing advanced 'pin' and 'recoverWhile' patterns to prevent syntax highlighting from breaking on minor typos.

    No, while the skill handles the logic, regex, and file structure, you must still trigger the 'Generate Parser Code' and 'Run JFlex Generator' actions within IntelliJ to finalize the build.

    Yes, it is designed to manage complex Pratt-style expression hierarchies, ensuring correct operator precedence and avoiding the left-recursion errors that typically plague manual grammar authoring.

    Upon purchase, you receive the specialized agent instructions optimized for the IntelliJ SDK environment, including templates for recovery predicates and PSI mixins.

    The skill is fully compatible with any LLM-powered agent that supports custom system prompts or skill integration, such as ChatGPT (GPT-4o), Claude 3.5 Sonnet, or specialized IDE AI assistants.

    The skill provides guidance on implementing logic via mixin classes and the psiImplUtilClass, ensuring your custom behaviors aren't overwritten when the parser is re-generated.

    New in Prompt & Skill Engineering