()
| 8 | * @returns A comprehensive grammar description suitable for LLM prompts |
| 9 | */ |
| 10 | export function generateGrammarDescription(): string { |
| 11 | const sections: string[] = []; |
| 12 | |
| 13 | sections.push("# Graph Query Language Grammar"); |
| 14 | sections.push(""); |
| 15 | sections.push( |
| 16 | "This is a declarative query language for traversing and querying graph data structures.", |
| 17 | ); |
| 18 | sections.push(""); |
| 19 | |
| 20 | // Core Structure |
| 21 | sections.push("## Query Structure"); |
| 22 | sections.push(""); |
| 23 | sections.push("Every query follows this fixed structure:"); |
| 24 | sections.push(""); |
| 25 | sections.push("```"); |
| 26 | sections.push("MATCH <pattern>"); |
| 27 | sections.push("[WHERE <condition>]"); |
| 28 | sections.push("RETURN <items>"); |
| 29 | sections.push("[ORDER BY <expression> [ASC|DESC]]"); |
| 30 | sections.push("[SKIP <number>]"); |
| 31 | sections.push("[LIMIT <number>]"); |
| 32 | sections.push("```"); |
| 33 | sections.push(""); |
| 34 | sections.push("- `MATCH` is required and defines the graph pattern to find"); |
| 35 | sections.push("- `WHERE` is optional and filters the matched results"); |
| 36 | sections.push("- `RETURN` is required and specifies what data to return"); |
| 37 | sections.push("- `ORDER BY`, `SKIP`, and `LIMIT` are optional result modifiers"); |
| 38 | sections.push(""); |
| 39 | |
| 40 | // Pattern Matching |
| 41 | sections.push("## Pattern Matching (MATCH)"); |
| 42 | sections.push(""); |
| 43 | sections.push("Patterns describe the shape of graph structures to find:"); |
| 44 | sections.push(""); |
| 45 | |
| 46 | sections.push("### Node Patterns"); |
| 47 | sections.push(""); |
| 48 | sections.push("Nodes are written using parentheses with a variable and optional label:"); |
| 49 | sections.push(""); |
| 50 | sections.push("- `(n)` - Any node, bound to variable `n`"); |
| 51 | sections.push('- `(n:Person)` - Node with label "Person", bound to variable `n`'); |
| 52 | sections.push('- `(user:User)` - Node with label "User", bound to variable `user`'); |
| 53 | sections.push(""); |
| 54 | |
| 55 | sections.push("### Edge Patterns"); |
| 56 | sections.push(""); |
| 57 | sections.push("Edges connect nodes and use arrow syntax to indicate direction:"); |
| 58 | sections.push(""); |
| 59 | sections.push("**Outgoing (left to right):**"); |
| 60 | sections.push('- `(a)-[:follows]->(b)` - Node `a` has outgoing "follows" edge to node `b`'); |
| 61 | sections.push("- `(a)-[r:likes]->(b)` - Same, but edge is bound to variable `r`"); |
| 62 | sections.push(""); |
| 63 | sections.push("**Incoming (right to left):**"); |
| 64 | sections.push('- `(a)<-[:follows]-(b)` - Node `a` has incoming "follows" edge from node `b`'); |
| 65 | sections.push(""); |
| 66 | sections.push("**Bidirectional (either direction):**"); |
| 67 | sections.push( |
no test coverage detected