Skip to content

Commit

Permalink
Adding SAS languague support
Browse files Browse the repository at this point in the history
  • Loading branch information
alawrenc authored and mwouts committed Feb 25, 2023
1 parent edad0f3 commit 2f24c6c
Show file tree
Hide file tree
Showing 10 changed files with 312 additions and 2 deletions.
1 change: 1 addition & 0 deletions docs/languages.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ Jupytext works with notebooks in any of the following languages:
- Robot Framework
- Rust/Evxcr
- Sage
- SAS
- Scala
- Scheme
- Script of Script
Expand Down
10 changes: 9 additions & 1 deletion jupytext/languages.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
"octave",
"idl",
"robotframework",
"sas",
"spark",
"sql",
"cython",
Expand Down Expand Up @@ -84,6 +85,11 @@
}, # Maxima only has block comments
".gp": {"language": "gnuplot", "comment": "#"},
".do": {"language": "stata", "comment": "//"},
".sas": {
"language": "sas",
"comment": "/*",
"comment_suffix": "*/",
},
}

_COMMENT_CHARS = [
Expand Down Expand Up @@ -121,7 +127,7 @@ def default_language_from_metadata_and_ext(metadata, ext, pop_main_language=Fals
):
metadata["jupytext"].pop("main_language")

if language is None or language == "R":
if language is None or language in ["R", "sas"]:
return language

if language.startswith("C++"):
Expand All @@ -143,6 +149,8 @@ def usual_language_name(language):
return "csharp"
if language in ["fs", "f#"]:
return "fsharp"
if language == "sas":
return "SAS"
return language


Expand Down
2 changes: 1 addition & 1 deletion jupytext/magics.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ def get_comment(ext):
def is_magic(line, language, global_escape_flag=True, explicitly_code=False):
"""Is the current line a (possibly escaped) Jupyter magic, and should it be commented?"""
language = usual_language_name(language)
if language in ["octave", "matlab"] or language not in _SCRIPT_LANGUAGES:
if language in ["octave", "matlab", "sas"] or language not in _SCRIPT_LANGUAGES:
return False
if _MAGIC_FORCE_ESC_RE[language].match(line):
return True
Expand Down
81 changes: 81 additions & 0 deletions tests/notebooks/ipynb_sas/sas.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
{
"cells": [
{
"cell_type": "markdown",
"id": "14a71cf0-4339-4ae6-982d-7dda15f3810e",
"metadata": {},
"source": [
"# SAS Notebooks with jupytext"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "47346888-e79f-4205-82fd-3a5fdfde9b4d",
"metadata": {},
"outputs": [],
"source": [
"proc sql;\n",
" select *\n",
" from sashelp.cars (obs=10)\n",
" ;\n",
"quit; "
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "c96b0faf-26fe-4245-a1d9-78dee30b19c3",
"metadata": {},
"outputs": [],
"source": [
"%let name = \"Jupytext\";"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "56cafffb-e397-4c3b-97ab-c6970149b6bc",
"metadata": {},
"outputs": [],
"source": [
"%put &name;"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "bbc273c9-8690-450d-bd9b-2d075d512437",
"metadata": {},
"outputs": [],
"source": [
"/* Note when defining macros \"%macro\" cannot be the first line of text in the cell */\n",
"%macro test;\n",
" data temp;\n",
" set sashelp.cars;\n",
" name = \"testx\";\n",
" run; \n",
" proc print data = temp (obs=10);\n",
" run; \n",
"%mend test;\n",
"\n",
"%test"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "SAS",
"language": "sas",
"name": "sas"
},
"language_info": {
"codemirror_mode": "sas",
"file_extension": ".sas",
"mimetype": "text/x-sas",
"name": "sas"
}
},
"nbformat": 4,
"nbformat_minor": 5
}
39 changes: 39 additions & 0 deletions tests/notebooks/mirror/ipynb_to_Rmd/sas.Rmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
---
jupyter:
kernelspec:
display_name: SAS
language: sas
name: sas
---

# SAS Notebooks with jupytext

```{sas}
proc sql;
select *
from sashelp.cars (obs=10)
;
quit;
```

```{sas}
%let name = "Jupytext";
```

```{sas}
%put &name;
```

```{sas}
/* Note when defining macros "%macro" cannot be the first line of text in the cell */
%macro test;
data temp;
set sashelp.cars;
name = "testx";
run;
proc print data = temp (obs=10);
run;
%mend test;
%test
```
36 changes: 36 additions & 0 deletions tests/notebooks/mirror/ipynb_to_hydrogen/sas.sas
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/* --- */
/* jupyter: */
/* kernelspec: */
/* display_name: SAS */
/* language: sas */
/* name: sas */
/* --- */

/* %% [markdown] */
/* # SAS Notebooks with jupytext */

/* %% */
proc sql;
select *
from sashelp.cars (obs=10)
;
quit;

/* %% */
%let name = "Jupytext";

/* %% */
%put &name;

/* %% */
/* Note when defining macros "%macro" cannot be the first line of text in the cell */
%macro test;
data temp;
set sashelp.cars;
name = "testx";
run;
proc print data = temp (obs=10);
run;
%mend test;

%test
39 changes: 39 additions & 0 deletions tests/notebooks/mirror/ipynb_to_md/sas.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
---
jupyter:
kernelspec:
display_name: SAS
language: sas
name: sas
---

# SAS Notebooks with jupytext

```sas
proc sql;
select *
from sashelp.cars (obs=10)
;
quit;
```

```sas
%let name = "Jupytext";
```

```sas
%put &name;
```

```sas
/* Note when defining macros "%macro" cannot be the first line of text in the cell */
%macro test;
data temp;
set sashelp.cars;
name = "testx";
run;
proc print data = temp (obs=10);
run;
%mend test;
%test
```
38 changes: 38 additions & 0 deletions tests/notebooks/mirror/ipynb_to_myst/sas.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
---
kernelspec:
display_name: SAS
language: sas
name: sas
---

# SAS Notebooks with jupytext

```{code-cell}
proc sql;
select *
from sashelp.cars (obs=10)
;
quit;
```

```{code-cell}
%let name = "Jupytext";
```

```{code-cell}
%put &name;
```

```{code-cell}
/* Note when defining macros "%macro" cannot be the first line of text in the cell */
%macro test;
data temp;
set sashelp.cars;
name = "testx";
run;
proc print data = temp (obs=10);
run;
%mend test;
%test
```
36 changes: 36 additions & 0 deletions tests/notebooks/mirror/ipynb_to_percent/sas.sas
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/* --- */
/* jupyter: */
/* kernelspec: */
/* display_name: SAS */
/* language: sas */
/* name: sas */
/* --- */

/* %% [markdown] */
/* # SAS Notebooks with jupytext */

/* %% */
proc sql;
select *
from sashelp.cars (obs=10)
;
quit;

/* %% */
%let name = "Jupytext";

/* %% */
%put &name;

/* %% */
/* Note when defining macros "%macro" cannot be the first line of text in the cell */
%macro test;
data temp;
set sashelp.cars;
name = "testx";
run;
proc print data = temp (obs=10);
run;
%mend test;

%test
32 changes: 32 additions & 0 deletions tests/notebooks/mirror/ipynb_to_script/sas.sas
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/* --- */
/* jupyter: */
/* kernelspec: */
/* display_name: SAS */
/* language: sas */
/* name: sas */
/* --- */

/* # SAS Notebooks with jupytext */

proc sql;
select *
from sashelp.cars (obs=10)
;
quit;

%let name = "Jupytext";

%put &name;

/* +
/* Note when defining macros "%macro" cannot be the first line of text in the cell */
%macro test;
data temp;
set sashelp.cars;
name = "testx";
run;
proc print data = temp (obs=10);
run;
%mend test;

%test

0 comments on commit 2f24c6c

Please sign in to comment.