Skip to main content
Glama
natl-set

ANTLR4 MCP Server

by natl-set

extract-fragment

Extract common lexer patterns into reusable fragments to reduce duplication and improve maintainability in ANTLR4 grammars.

Instructions

Extract a reusable fragment rule from a pattern to reduce duplication.

When to use: Share common patterns, improve maintainability, reduce duplication in lexer rules.

Example - Extract digit pattern: fragment_name: "DIGIT" pattern: "[0-9]"

Example - Extract letter pattern: fragment_name: "LETTER" pattern: "[a-zA-Z]"

After extraction, use the fragment in other rules: ID: LETTER (LETTER | DIGIT)*

Benefits:

  • Single source of truth for common patterns

  • Easier maintenance

  • Clearer lexer organization

  • Fragments are not tokens themselves (helper patterns only)

Returns: Modified grammar with fragment added, original pattern preserved in existing rules.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
patternYesThe pattern to extract as a fragment (e.g., "[0-9]", "[a-zA-Z]")
from_fileNoOptional: path to a grammar file to read
fragment_nameYesName for the fragment (must be UPPERCASE, e.g., DIGIT, LETTER, IDENTIFIER_PART)
grammar_contentNoThe ANTLR4 grammar file content
Behavior4/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations provided, the description carries the full burden. It discloses key behavioral traits: the original pattern is preserved in existing rules, fragments are not tokens, and the return value is a modified grammar. It doesn't cover edge cases like duplicate fragment names or interaction between grammar_content and from_file, but overall it provides solid transparency.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness4/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is structured with clear sections ('When to use', 'Example', 'Benefits', 'Returns') and is not excessively long. Each section contributes meaning, though the 'Benefits' bullet list could be condensed without losing much value.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness4/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

The tool has a simple function (extract a fragment) and the description covers its use cases, examples, and return value. It doesn't mention potential parameter conflicts (e.g., providing both grammar_content and from_file), but given the simplicity and the existence of an output-free design, this is acceptable.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters4/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Although the input schema already has 100% coverage with descriptions, the tool description adds value by showing concrete examples of how fragment_name and pattern are used (DIGIT, LETTER) and demonstrating the resulting rule usage. This goes beyond the schema's basic parameter definitions.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the tool's purpose with a specific verb ('Extract a reusable fragment rule from a pattern') and resource (lexer fragments). It also differentiates from sibling tools by clarifying that fragments are helper patterns, not tokens, which distinguishes it from generic rule-addition tools like add-rule.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines4/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description includes an explicit 'When to use' section listing three concrete scenarios: share common patterns, improve maintainability, reduce duplication. However, it does not provide when-not-to-use guidance or explicitly name alternative tools, so it falls short of a 5.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/natl-set/antlr4-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server