forked from universal-ctags/ctags
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
FrontMatter: new subparser parser run from Markdown parser
In this version, just extracting "foo" in "title: foo" written in Yaml. JSON(;;;) and TOML(+++) are not supported yet. Close universal-ctags#3032. Signed-off-by: Masatake YAMATO <[email protected]>
- Loading branch information
Showing
13 changed files
with
375 additions
and
1 deletion.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
--sort=no | ||
--extras=+g | ||
--fields=+KenlE |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
S1 input.rmd /^# S1$/;" chapter line:4 language:Markdown end:17 | ||
xyX input.rmd /^```{r xyX}$/;" chunklabel line:6 language:RMarkdown extras:subparser | ||
S2 input.rmd /^# S2$/;" chapter line:18 language:Markdown end:28 | ||
__anon9d4e183a0100 input.rmd /^```{r, cache = TRUE, dependson = "xyX"}$/;" chunklabel line:20 language:RMarkdown extras:subparser,anonymous | ||
__anon9d4e183a0200 input.rmd /^```{python}$/;" chunklabel line:24 language:RMarkdown extras:subparser,anonymous | ||
S3 input.rmd /^# S3$/;" chapter line:29 language:Markdown end:30 | ||
x input.rmd /^x <- 1$/;" globalVar line:8 language:R extras:guest end:8 | ||
foo input.rmd /^foo <- function () {$/;" function line:9 language:R extras:guest end:12 | ||
y input.rmd /^ y <- 2$/;" functionVar line:10 language:R function:foo extras:guest end:10 | ||
X input.rmd /^X <- func()$/;" globalVar line:14 language:R extras:guest end:14 | ||
f input.rmd /^def f():$/;" function line:25 language:Python extras:guest end:27 | ||
example for u-ctags input.rmd /^title: example for u-ctags$/;" title line:2 language:FrontMatter extras:subparser |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
--- | ||
title: example for u-ctags | ||
--- | ||
# 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 | ||
|
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Yaml |
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
/* | ||
* | ||
* Copyright (c) 2022, Masatake YAMATO | ||
* Copyright (c) 2022, Red Hat, K.K. | ||
* | ||
* This source code is released for free distribution under the terms of the | ||
* GNU General Public License version 2 or (at your option) any later version. | ||
* | ||
* This module contains functions for extracting language objects in FrontMatter. | ||
* | ||
* https://gohugo.io/content-management/front-matter | ||
*/ | ||
|
||
/* | ||
* INCLUDE FILES | ||
*/ | ||
#include "general.h" /* must always come first */ | ||
|
||
#include "frontmatter.h" | ||
|
||
#include "entry.h" | ||
#include "parse.h" | ||
#include "promise.h" | ||
#include "read.h" | ||
|
||
#include <string.h> | ||
|
||
/* | ||
* DATA DEFINITIONS | ||
*/ | ||
static kindDefinition FrontMatterKinds [] = { | ||
{ true, 't', "title", "titles", }, | ||
}; | ||
|
||
/* | ||
* FUNCTION DEFINITIONS | ||
*/ | ||
static void findFrontMatterTags (void) | ||
{ | ||
const unsigned char *line = readLineFromInputFile (); | ||
|
||
if (line == NULL) | ||
return; | ||
|
||
#ifdef HAVE_LIBYAML | ||
if (strcmp("---", (const char *)line) == 0) | ||
{ | ||
line = readLineFromInputFile (); | ||
unsigned long endOffset = strlen((const char *)line); | ||
if (line) | ||
{ | ||
long startLineNum = getInputLineNumber (); | ||
while ((line = readLineFromInputFile())) | ||
endOffset = strlen((const char *)line); | ||
|
||
long endLineNum = getInputLineNumber (); | ||
|
||
makePromise ("YamlFrontMatter", startLineNum, 0, | ||
endLineNum, endOffset, startLineNum); | ||
} | ||
return; | ||
} | ||
#endif | ||
} | ||
|
||
extern parserDefinition* FrontMatterParser (void) | ||
{ | ||
parserDefinition* def = parserNew ("FrontMatter"); | ||
def->kindTable = FrontMatterKinds; | ||
def->kindCount = ARRAY_SIZE (FrontMatterKinds); | ||
|
||
def->parser = findFrontMatterTags; | ||
|
||
return def; | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
/* | ||
* Copyright (c) 2022, Masatake YAMATO <[email protected]> | ||
* | ||
* This source code is released for free distribution under the terms of the | ||
* GNU General Public License version 2 or (at your option) any later version. | ||
* | ||
* Frontmatter parser interface exported to the other parsers | ||
*/ | ||
|
||
#ifndef CTAGS_FRONTMATTER_H | ||
#define CTAGS_FRONTMATTER_H | ||
|
||
#include "general.h" | ||
|
||
typedef enum { | ||
FRONTMATTER_TITLE_KIND, | ||
} frontmatterKind; | ||
|
||
#endif |
This file contains 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
Oops, something went wrong.