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

RMarkdown: new parser #3309

Merged
merged 6 commits into from
Mar 15, 2022
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 Tmain/list-subparsers-all.d/stdout-expected.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ PlistXML XML base <> sub {bidirectional}
PythonLoggingConfig Iniconf base <> sub {bidirectional}
QtMoc C++ base <> sub {bidirectional}
R6Class R base <> sub {bidirectional}
RMarkdown Markdown base <= sub {dedicated}
RSpec Ruby base => sub {shared}
RelaxNG XML base <> sub {bidirectional}
S4Class R base <> sub {bidirectional}
Expand Down
2 changes: 2 additions & 0 deletions Units/parser-markdown.r/footnotes.d/args.ctags
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
--sort=no
--fields=+nK
2 changes: 2 additions & 0 deletions Units/parser-markdown.r/footnotes.d/expected.tags
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
1 input.md /^[^1]: This is the first footnote.$/;" footnote line:4
bignote input.md /^[^bignote]: Here's one with multiple paragraphs and code.$/;" footnote line:6
12 changes: 12 additions & 0 deletions Units/parser-markdown.r/footnotes.d/input.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<!-- Taken from https://www.markdownguide.org/extended-syntax/#footnotes -->
Here's a simple footnote,[^1] and here's a longer one.[^bignote]

[^1]: This is the first footnote.

[^bignote]: Here's one with multiple paragraphs and code.

Indent paragraphs to include them in the footnote.

`{ my code }`

Add as many paragraphs as you like.
3 changes: 3 additions & 0 deletions Units/parser-rmarkdown.r/simple-rmarkdown.d/args.ctags
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
--sort=no
--extras=+g
--fields=+KenlE
11 changes: 11 additions & 0 deletions Units/parser-rmarkdown.r/simple-rmarkdown.d/expected.tags
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
S1 input.rmd /^# S1$/;" chapter line:1 language:Markdown end:14
xyX input.rmd /^```{r xyX}$/;" chunklabel line:3 language:RMarkdown extras:subparser
S2 input.rmd /^# S2$/;" chapter line:15 language:Markdown end:25
__anon4a45a9700100 input.rmd /^```{r, cache = TRUE, dependson = "xyX"}$/;" chunklabel line:17 language:RMarkdown extras:subparser,anonymous
__anon4a45a9700200 input.rmd /^```{python}$/;" chunklabel line:21 language:RMarkdown extras:subparser,anonymous
S3 input.rmd /^# S3$/;" chapter line:26 language:Markdown end:27
x input.rmd /^x <- 1$/;" globalVar line:5 language:R extras:guest end:5
foo input.rmd /^foo <- function () {$/;" function line:6 language:R extras:guest end:9
y input.rmd /^ y <- 2$/;" functionVar line:7 language:R function:foo extras:guest end:7
X input.rmd /^X <- func()$/;" globalVar line:11 language:R extras:guest end:11
f input.rmd /^def f():$/;" function line:22 language:Python extras:guest end:24
27 changes: 27 additions & 0 deletions Units/parser-rmarkdown.r/simple-rmarkdown.d/input.rmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# S1

```{r xyX}

x <- 1
foo <- function () {
y <- 2
return(y)
}

X <- func()

```

# S2

```{r, cache = TRUE, dependson = "xyX"}
mean(X)
```

```{python}
def f():
g()
return 3
```
# S3

8 changes: 4 additions & 4 deletions docs/man/ctags-lang-iPythonCell.7.rst
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,20 @@ The man page of the iPythonCell parser for Universal Ctags

SYNOPSIS
--------
| **ctags** ... --extras={subparser} --languages=+iPythonCell,Python \\
| **ctags** ... --extras=+{subparser} --languages=+iPythonCell,Python \\
| [--extras-IPythonCell=+{doubleSharps}] \\
| [--regex-IPythonCell=/<PATTERN>/\\n/c/] ...

DESCRIPTION
-----------
iPythonCell is a subparser stacked on top of the Python parser.
iPythonCell parser is a subparser stacked on top of the Python parser.
It works when:

* The Python parser is enabled,
* the Python parser is enabled,
* the ``subparser`` extra is enabled, and
* the iPythonCell parser itself is enabled.

iPythonCell extracts cells explained as in vim-ipython-cell
The iPythonCell parser extracts cells explained as in vim-ipython-cell
(https://github.com/hanschen/vim-ipython-cell/blob/master/README.md).

KIND(S)
Expand Down
98 changes: 98 additions & 0 deletions docs/man/ctags-lang-rmarkdown.7.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
.. _ctags_lang-rmarkdown(7):

======================================================================
ctags-lang-rmarkdown
======================================================================

Random notes about tagging R Markdown source code with Universal Ctags

:Version: 5.9.0
:Manual group: Universal Ctags
:Manual section: 7

SYNOPSIS
--------
| **ctags** ...--extras=+{subparser}{guest} --languages=+RMarkdown ...
| **ctags** ...--extras=+{subparser}{guest} --language-force=RMarkdown ...
| **ctags** ...--extras=+{subparser}{guest} --map-RMarkdown=+.rmd ...

DESCRIPTION
-----------
RMarkdown parser is an exclusive subparser stacked on top of the Markdown parser.
It works when:

* the Markdown parser is enabled,
* the ``subparser`` extra is enabled, and
* the RMarkdown parser itself is enabled.

The RMarkdown parser extends the way of detecting **codeblocks** from the
Markdown parser for running guest parsers on **code chunks**.

The Markdown parser expects the following syntax for codeblocks

.. code-block::

```language-name
...
```

For an example

.. code-block::

```r
...
```

The RMarkdown parser accepts the following syntax for code chunks
as the markdown parser accepts codeblocks

.. code-block::

```{language-name chunk-label, ...}
...
```

For an example

.. code-block::

```{r precalc fig.height=4}
...
```

Give `--extras=+{guest}` for enabling ``guest`` to command line if you
want to run proper parsers on inside code chunks.

The parser extrats chunk labels coming after `language-name` as
`chunklabel` kind objcts. The kind is enabled by default.

EXAMPLES
--------
"input.rmd"

.. code-block:: RMarkdown

# Section 1

```{r myblock}
zero_fun <- function () {
return 0
}
```

# Section 2

"output.tags"
with "--options=NONE --extras=+{guest} --fields=+KZln -o - input.rmd"

.. code-block:: tags

Section 1 input.rmd /^# Section 1$/;" chapter line:1 language:Markdown
Section 2 input.rmd /^# Section 2$/;" chapter line:9 language:Markdown
myblock input.rmd /^```{r myblock}$/;" chunklabel line:3 language:RMarkdown
zero_fun input.rmd /^ zero_fun <- function () {$/;" function line:4 language:R

SEE ALSO
--------
:ref:`ctags(1) <ctags(1)>`, :ref:`ctags-client-tools(7) <ctags-client-tools(7)>`, `R Markdown: The Definitive Guide <https://bookdown.org/yihui/rmarkdown/>`_
1 change: 1 addition & 0 deletions docs/news.rst
Original file line number Diff line number Diff line change
Expand Up @@ -455,6 +455,7 @@ The following parsers have been added:
* R6Class *R based subparser*
* RelaxNG *libxml*
* ReStructuredText
* RMarkdown *Markdown based subparser*
* Robot
* RpmMacros *optlib*
* RpmSpec
Expand Down
1 change: 1 addition & 0 deletions main/parsers_p.h
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@
PythonLoggingConfigParser, \
QemuHXParser, \
QtMocParser, \
RMarkdownParser, \
RParser, \
R6ClassParser, \
RSpecParser, \
Expand Down
1 change: 1 addition & 0 deletions man/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ GEN_IN_MAN_FILES = \
ctags-lang-verilog.7 \
ctags-lang-inko.7 \
ctags-lang-r.7 \
ctags-lang-rmarkdown.7 \
ctags-lang-sql.7 \
\
readtags.1 \
Expand Down
8 changes: 4 additions & 4 deletions man/ctags-lang-iPythonCell.7.rst.in
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,20 @@ The man page of the iPythonCell parser for Universal Ctags

SYNOPSIS
--------
| **@CTAGS_NAME_EXECUTABLE@** ... --extras={subparser} --languages=+iPythonCell,Python \\
| **@CTAGS_NAME_EXECUTABLE@** ... --extras=+{subparser} --languages=+iPythonCell,Python \\
| [--extras-IPythonCell=+{doubleSharps}] \\
| [--regex-IPythonCell=/<PATTERN>/\\n/c/] ...

DESCRIPTION
-----------
iPythonCell is a subparser stacked on top of the Python parser.
iPythonCell parser is a subparser stacked on top of the Python parser.
It works when:

* The Python parser is enabled,
* the Python parser is enabled,
* the ``subparser`` extra is enabled, and
* the iPythonCell parser itself is enabled.

iPythonCell extracts cells explained as in vim-ipython-cell
The iPythonCell parser extracts cells explained as in vim-ipython-cell
(https://github.com/hanschen/vim-ipython-cell/blob/master/README.md).

KIND(S)
Expand Down
98 changes: 98 additions & 0 deletions man/ctags-lang-rmarkdown.7.rst.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
.. _ctags_lang-rmarkdown(7):

======================================================================
ctags-lang-rmarkdown
======================================================================
-----------------------------------------------------------------------
Random notes about tagging R Markdown source code with Universal Ctags
-----------------------------------------------------------------------
:Version: @VERSION@
:Manual group: Universal Ctags
:Manual section: 7

SYNOPSIS
--------
| **@CTAGS_NAME_EXECUTABLE@** ...--extras=+{subparser}{guest} --languages=+RMarkdown ...
| **@CTAGS_NAME_EXECUTABLE@** ...--extras=+{subparser}{guest} --language-force=RMarkdown ...
| **@CTAGS_NAME_EXECUTABLE@** ...--extras=+{subparser}{guest} --map-RMarkdown=+.rmd ...

DESCRIPTION
-----------
RMarkdown parser is an exclusive subparser stacked on top of the Markdown parser.
It works when:

* the Markdown parser is enabled,
* the ``subparser`` extra is enabled, and
* the RMarkdown parser itself is enabled.

The RMarkdown parser extends the way of detecting **codeblocks** from the
Markdown parser for running guest parsers on **code chunks**.

The Markdown parser expects the following syntax for codeblocks

.. code-block::

```language-name
...
```

For an example

.. code-block::

```r
...
```

The RMarkdown parser accepts the following syntax for code chunks
as the markdown parser accepts codeblocks

.. code-block::

```{language-name chunk-label, ...}
...
```

For an example

.. code-block::

```{r precalc fig.height=4}
...
```

Give `--extras=+{guest}` for enabling ``guest`` to command line if you
want to run proper parsers on inside code chunks.

The parser extrats chunk labels coming after `language-name` as
`chunklabel` kind objcts. The kind is enabled by default.

EXAMPLES
--------
"input.rmd"

.. code-block:: RMarkdown

# Section 1

```{r myblock}
zero_fun <- function () {
return 0
}
```

# Section 2

"output.tags"
with "--options=NONE --extras=+{guest} --fields=+KZln -o - input.rmd"

.. code-block:: tags

Section 1 input.rmd /^# Section 1$/;" chapter line:1 language:Markdown
Section 2 input.rmd /^# Section 2$/;" chapter line:9 language:Markdown
myblock input.rmd /^```{r myblock}$/;" chunklabel line:3 language:RMarkdown
zero_fun input.rmd /^ zero_fun <- function () {$/;" function line:4 language:R

SEE ALSO
--------
ctags(1), ctags-client-tools(7), `R Markdown: The Definitive Guide <https://bookdown.org/yihui/rmarkdown/>`_
Loading