Skip to content

Add ggsql as a bundled language for input_code_editor#1291

Merged
cpsievert merged 17 commits intomainfrom
feat/ggsql-language
Apr 16, 2026
Merged

Add ggsql as a bundled language for input_code_editor#1291
cpsievert merged 17 commits intomainfrom
feat/ggsql-language

Conversation

@cpsievert
Copy link
Copy Markdown
Collaborator

@cpsievert cpsievert commented Mar 7, 2026

Summary

  • Adds ggsql as a first-class language in prism-code-editor, so input_code_editor(language="ggsql") works natively
  • The grammar extends SQL with ggsql-specific tokens: clause keywords (VISUALISE, DRAW, SCALE, etc.), geom types, aesthetic names, theme names, project types, and an extended SQL function list
  • Grammar derived from the TextMate grammar

Files changed

  • inst/lib/prism-code-editor/prism/languages/ggsql.js — new Prism grammar file that imports sql.js and extends it
  • tools/yarn_install.R — added "ggsql" to code_editor_bundled_languages
  • R/versions.R — added "ggsql" to the generated allowlist

Test plan

  • devtools::load_all(); shinyApp(page_fluid(input_code_editor("test", language = "ggsql", value = "SELECT * FROM t VISUALISE x AS x DRAW point")), function(input, output, session) {}) — verify VISUALISE, DRAW, point get distinct highlighting

🤖 Generated with Claude Code

cpsievert and others added 4 commits March 7, 2026 09:59
Add ggsql (SQL + visualization grammar) as a first-class language in
prism-code-editor. The grammar extends SQL with ggsql-specific tokens:
clause keywords (VISUALISE, DRAW, SCALE, etc.), geom types, aesthetic
names, theme names, project types, and an extended SQL function list.

Derived from the TextMate grammar at:
https://github.com/posit-dev/ggsql/blob/main/ggsql-vscode/syntaxes/ggsql.tmLanguage.json

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Rscript tools/build_ggsql_grammar.R fetches the TextMate grammar from
posit-dev/ggsql, extracts token patterns, and generates the Prism
grammar file. The generated ggsql.js should be copied to py-shiny
after regeneration.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Instead of hardcoding clause keywords, extract them from the begin
captures and keyword.other patterns of all *-clause repository entries.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@cpsievert cpsievert force-pushed the feat/ggsql-language branch from d8e4bcd to f084f5a Compare March 7, 2026 15:59
@cpsievert cpsievert requested a review from gadenbuie March 9, 2026 16:10
cpsievert and others added 2 commits March 9, 2026 16:11
Copy link
Copy Markdown
Member

@gadenbuie gadenbuie left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me, just one comment about the translation script looking a little brittle

Comment thread tools/build_ggsql_grammar.R Outdated
Comment thread tools/build_ggsql_grammar.R Outdated
Comment thread tools/build_ggsql_grammar.R Outdated
cpsievert and others added 3 commits April 16, 2026 12:21
Address PR feedback:
- Extract repeated token extraction into extract_token_group() with
  validation that fails loudly if upstream grammar structure changes
- Use named `flags` argument in format_word_regex() calls
- Use raw string templates for JS output blocks
- Remove theme-clause support (removed upstream)
- Regenerate ggsql.js against latest upstream grammar

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- Fix accumulation bug: extract_token_group now collects words across
  all matching patterns instead of only keeping the last match
  (aesthetics went from 3 to 32 words)
- Accept multiple repo keys so draw-clause and place-clause geoms are
  merged (adds `rect`)
- Add scale type values (linear, log, viridis, etc.)
- Add property names from scale/facet/project/label clauses

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

This comment was marked as resolved.

cpsievert and others added 4 commits April 16, 2026 17:36
Filter prism/languages copy with file.exists() so ggsql.js (which is
generated locally, not from upstream) doesn't cause warnings. Add a
reminder to regenerate ggsql.js after yarn_install.R runs.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@cpsievert cpsievert merged commit d9b20fe into main Apr 16, 2026
1 check passed
@cpsievert cpsievert deleted the feat/ggsql-language branch April 16, 2026 17:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants