Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for Rust/Evxcr #351

Merged
merged 5 commits into from
Oct 18, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions HISTORY.rst
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ Release History
- Markdown and raw cells can use multiline comments in the ``py:percent`` format (#305)
- ``jupytext notebook.py --to ipynb`` updates the timestamp of ``notebook.py`` so that the paired notebook still works in Jupyter (#335, #254)
- The Jupyter Notebook extension for Jupytext is compatible with Jupyter Notebook 6.0 (#346)
- Added support for Rust/Evxcr, by Jonas Bushart (#351)

**BugFixes**

Expand Down
3 changes: 2 additions & 1 deletion jupytext/languages.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@
'.pro': {'language': 'idl', 'comment': ';'},
'.js': {'language': 'javascript', 'comment': '//'},
'.ts': {'language': 'typescript', 'comment': '//'},
'.scala': {'language': 'scala', 'comment': '//'}}
'.scala': {'language': 'scala', 'comment': '//'},
'.rs': {'language': 'rust', 'comment': '//'}}

_COMMENT_CHARS = [_SCRIPT_EXTENSIONS[ext]['comment'] for ext in _SCRIPT_EXTENSIONS if
_SCRIPT_EXTENSIONS[ext]['comment'] != '#']
Expand Down
15 changes: 11 additions & 4 deletions jupytext/magics.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@
_SCRIPT_EXTENSIONS[ext]['comment'])) for ext in _SCRIPT_EXTENSIONS}
_LINE_CONTINUATION_RE = re.compile(r'.*\\\s*$')

# Rust magics start with single ':' #351
_MAGIC_RE['rust'] = re.compile(r"^(// |//)*:[a-zA-Z]")
_MAGIC_FORCE_ESC_RE['rust'] = re.compile(r"^(// |//)*:[a-zA-Z](.*)//\s*escape")
_MAGIC_FORCE_ESC_RE['rust'] = re.compile(r"^(// |//)*:[a-zA-Z](.*)//\s*noescape")

# Commands starting with a question or exclamation mark have to be escaped
_PYTHON_HELP_OR_BASH_CMD = re.compile(r"^(# |#)*(\?|!)\s*[A-Za-z]")

Expand All @@ -25,16 +30,18 @@
# windows
['copy', 'ddir', 'echo', 'ls', 'ldir', 'mkdir', 'ren', 'rmdir'])))

_SCRIPT_LANGUAGES = [_SCRIPT_EXTENSIONS[ext]['language'] for ext in _SCRIPT_EXTENSIONS]


def is_magic(line, language, global_escape_flag=True):
"""Is the current line a (possibly escaped) Jupyter magic, and should it be commented?"""
if language in ['octave', 'matlab']:
if language in ['octave', 'matlab'] or language not in _SCRIPT_LANGUAGES:
return False
if _MAGIC_FORCE_ESC_RE.get(language, _MAGIC_FORCE_ESC_RE['python']).match(line):
if _MAGIC_FORCE_ESC_RE[language].match(line):
return True
if not global_escape_flag or _MAGIC_NOT_ESC_RE.get(language, _MAGIC_NOT_ESC_RE['python']).match(line):
if not global_escape_flag or _MAGIC_NOT_ESC_RE[language].match(line):
return False
if _MAGIC_RE.get(language, _MAGIC_RE['python']).match(line):
if _MAGIC_RE[language].match(line):
return True
if language != 'python':
return False
Expand Down
Loading