feat: Add grammar fetch and comparison tooling
- Add fetch_bind_grammar.py for MCP-based grammar file retrieval - Add compare_bind_versions.py for version differences analysis - Add process_mcp_result.py for handling base64-encoded MCP output - Create upstream directory structure with fetching instructions - Document grammar file locations and structure
This commit is contained in:
37
scripts/save_grammar_file.py
Normal file
37
scripts/save_grammar_file.py
Normal file
@@ -0,0 +1,37 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Helper script to save base64-encoded grammar file from MCP tool output."""
|
||||
|
||||
import base64
|
||||
import json
|
||||
import sys
|
||||
from pathlib import Path
|
||||
|
||||
def main():
|
||||
if len(sys.argv) != 3:
|
||||
print("Usage: save_grammar_file.py <json_file> <output_path>")
|
||||
sys.exit(1)
|
||||
|
||||
json_file = Path(sys.argv[1])
|
||||
output_path = Path(sys.argv[2])
|
||||
|
||||
# Read JSON from MCP tool output
|
||||
with open(json_file, 'r') as f:
|
||||
data = json.load(f)
|
||||
|
||||
# Extract and decode base64 content
|
||||
if 'Result' in data and 'content' in data['Result']:
|
||||
content_b64 = data['Result']['content']
|
||||
content = base64.b64decode(content_b64).decode('utf-8')
|
||||
|
||||
# Save to output path
|
||||
output_path.parent.mkdir(parents=True, exist_ok=True)
|
||||
with open(output_path, 'w', encoding='utf-8') as f:
|
||||
f.write(content)
|
||||
|
||||
print(f"✓ Saved: {output_path}")
|
||||
else:
|
||||
print(f"✗ Error: No content found in JSON", file=sys.stderr)
|
||||
sys.exit(1)
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
Reference in New Issue
Block a user