Add SAS language support - #5494
Open
Allan Bowe (allanbowe) wants to merge 2 commits into
Open
Allan Bowe (allanbowe) wants to merge 2 commits into
Allan Bowe (allanbowe) wants to merge 2 commits into
Conversation
Statement-position-aware Monarch grammar for SAS, with vocabulary resolved from the SAS language data published with the SAS extension for Visual Studio Code (Apache-2.0). Keywords only match in statement position, so a variable named x, means, lib or output stays plain while the X statement, PROC names, functions and system options are still coloured. The word lists are generated by keywords.js and reproducible from the upstream data.
Author
|
@microsoft-github-policy-service agree |
The four files added by this PR open with a Microsoft copyright and MIT license header, which misattributes code written for this contribution. The headers are removed with no replacement notice; the vocabulary provenance comment in sas.ts and keywords.js still names the SAS extension data and its Apache-2.0 license, and the reference to a ThirdPartyNotices.txt entry that this PR does not add is dropped.
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #2613 and implemented in https://github.com/sasjs/server
Summary
Adds a Monarch grammar and language configuration for SAS. The issue has been open since 2021, and the maintainer's position there was:
This is tokenization only. It registers no language server and adds no runtime dependency.
Files
src/languages/definitions/sas/sas.tssrc/languages/definitions/sas/register.tsregisterLanguagefor idsas, extension.sassrc/languages/definitions/sas/keywords.jssas.tssrc/languages/definitions/sas/sas.test.tssrc/languages/definitions/register.all.tswebsite/src/website/data/home-samples/sample.sas.txtbuild/check-samplesDesign: keywords match in statement position only
SAS is case-insensitive and its statements are bare words, so a grammar that matches keywords anywhere mis-colours ordinary variables.
x,means,lib,outputandmissingare each both a statement and a very common variable name, andx = 1is far more common in real SAS code than the X statement.The grammar therefore keeps two states:
rootis statement position. The first word of a statement resolves against the statement list, sodata,proc,run,ifandx 'dir';are keywords.bodyis the inside of a statement. Here a bare word resolves against options, control keywords and function names, and a statement keyword is no longer special.if x then output;givesxplain,thenandoutputas control keywords, whileoutput = 1;leavesoutputplain.An assignment target is excluded by a lookahead (
[a-z_]\w*(?=\s*=)), which is what keepsx = 1andoutput = 1uncoloured without losing the X and OUTPUT statements.Separate states cover the parts of the language with their own vocabulary:
sqlfor PROC SQL and PROC FEDSQL, entered byproc sqland left byquitorrunodsandoptions, which carry tagset, style and system option listsdatalinesanddatalines4, which render instream data as a string until the terminating semicolon&inside single quotes is not a macro reference), a block-comment state and a statement-comment stateVocabulary
The word lists are resolved from the SAS language data published with the SAS extension for Visual Studio Code (sassoftware/vscode-sas-extension), so the grammar colours the words SAS actually documents rather than a hand-written sample. 2096 words in 13 groups:
keywords.jsregenerates them, matching the convention insqlandmysql:Tests
sas.test.tsfollows the existingtestTokenizationstyle, with 8 stateful groups covering statement position, macro statements, comments and strings, PROC SQL, ODS and OPTIONS, and instream data.Notes for review
CONTRIBUTING.mddescribes the older layout (src/basic-languages/{lang}/andmonaco.contribution.ts). The current layout issrc/languages/definitions/{lang}/with the list indefinitions/register.all.ts, which is what this change follows.build/check-samplesrequires a sample file per language directory, hencewebsite/src/website/data/home-samples/sample.sas.txt.noprinton PROC MEANS are not in the flat vocabulary. Recognising them needs a state per procedure, so they are left out of this change rather than approximated.npx tsc -p ./srcreports no new errors. The two it does report (src/index.tscannot resolve@vscode/monaco-lsp-client, and a regex flag inwgsl.tsunder thees5target) are present onmainbefore this change.Checklist
npm testpasses