Skip to content

Commit eede06b

Browse files
committed
Scheme: rewrite as a x-lisp based parser
Add "unknown" kind and "definer" field. Signed-off-by: Masatake YAMATO <[email protected]>
1 parent c7ecad3 commit eede06b

File tree

10 files changed

+161
-72
lines changed

10 files changed

+161
-72
lines changed

Tmain/list-fields-with-prefix.d/stdout-expected.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ x UCTAGSxpath no NONE s-- no -- xpath for
4848
- UCTAGSoverline no ReStructuredText --b no -- whether using overline & underline for declaring section
4949
- UCTAGSsectionMarker no ReStructuredText s-- no -- character used for declaring section
5050
- UCTAGSmixin yes Ruby s-- no -- how the class or module is mixed in (mixin:HOW:MODULE)
51+
- UCTAGSdefiner yes Scheme s-- no -- the name of the function or macro that defines the unknown/Y-kind object
5152
- UCTAGSparameter no SystemVerilog --b no -- parameter whose value can be overridden.
5253
- UCTAGStarget yes Thrift s-- no -- the target language specified at "namespace"
5354
- UCTAGSthrows yes Thrift s-- no -- throws list of function

Tmain/list-fields.d/stdout-expected.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ z kind no NONE s-- no r- [tags output] prepend "kind:" to k/ (or K/) field outpu
6666
- overline no ReStructuredText --b no -- whether using overline & underline for declaring section
6767
- sectionMarker no ReStructuredText s-- no -- character used for declaring section
6868
- mixin yes Ruby s-- no -- how the class or module is mixed in (mixin:HOW:MODULE)
69+
- definer yes Scheme s-- no -- the name of the function or macro that defines the unknown/Y-kind object
6970
- parameter no SystemVerilog --b no -- parameter whose value can be overridden.
7071
- target yes Thrift s-- no -- the target language specified at "namespace"
7172
- throws yes Thrift s-- no -- throws list of function

Units/option-regex-attaching-role.r/extending-existing-parser.d/expected.tags

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
foo input.scm /^(define-module foo$/;" function language:Scheme roles:def
1+
foo input.scm /^(define-module foo$/;" unknown language:Scheme roles:def definer:DEFINE-MODULE
22
foobar input.scm /^(define (foobar)$/;" function language:Scheme roles:def
33
foo input.scm /^(define-module foo$/;" module language:myGauche roles:def
44
bar input.scm /^ (use bar)$/;" module language:myGauche scope:module:foo roles:used

docs/man-pages.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ Man pages
4242
ctags-lang-python(7) <man/ctags-lang-python.7.rst>
4343
ctags-lang-r(7) <man/ctags-lang-r.7.rst>
4444
ctags-lang-rmarkdown(7) <man/ctags-lang-rmarkdown.7.rst>
45+
ctags-lang-scheme(7) <man/ctags-lang-scheme.7.rst>
4546
ctags-lang-scss(7) <man/ctags-lang-scss.7.rst>
4647
ctags-lang-sql(7) <man/ctags-lang-sql.7.rst>
4748
ctags-lang-systemtap(7) <man/ctags-lang-systemtap.7.rst>

docs/man/ctags-lang-scheme.7.rst

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
.. _ctags-lang-scheme(7):
2+
3+
==============================================================
4+
ctags-lang-scheme
5+
==============================================================
6+
7+
Random notes about tagging Scheme source code with Universal Ctags
8+
9+
:Version: 6.1.0
10+
:Manual group: Universal Ctags
11+
:Manual section: 7
12+
13+
SYNOPSIS
14+
--------
15+
| **ctags** ... --languages=+Scheme ...
16+
| **ctags** ... --language-force=Scheme ...
17+
| **ctags** ... --map-Scheme=+.SCM ...
18+
| **ctags** ... --map-Scheme=+.SM ...
19+
| **ctags** ... --map-Scheme=+.sch ...
20+
| **ctags** ... --map-Scheme=+.scheme ...
21+
| **ctags** ... --map-Scheme=+.scm ...
22+
| **ctags** ... --map-Scheme=+.sm ...
23+
| **ctags** ... --map-Scheme=+.rkt ...
24+
25+
DESCRIPTION
26+
-----------
27+
This man page gathers random notes about tagging Scheme source code.
28+
29+
VERSIONS
30+
--------
31+
32+
Change since "0.0"
33+
~~~~~~~~~~~~~~~~~~
34+
35+
* Add ``unknown`` kind.
36+
37+
* Add ``definer`` field.
38+
39+
SEE ALSO
40+
--------
41+
:ref:`ctags(1) <ctags(1)>`

man/GNUmakefile.am

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ GEN_IN_MAN_FILES = \
5353
ctags-lang-python.7 \
5454
ctags-lang-r.7 \
5555
ctags-lang-rmarkdown.7 \
56+
ctags-lang-scheme.7 \
5657
ctags-lang-scss.7 \
5758
ctags-lang-sql.7 \
5859
ctags-lang-systemtap.7 \

man/ctags-lang-scheme.7.rst.in

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
.. _ctags-lang-scheme(7):
2+
3+
==============================================================
4+
ctags-lang-scheme
5+
==============================================================
6+
---------------------------------------------------------------------
7+
Random notes about tagging Scheme source code with Universal Ctags
8+
---------------------------------------------------------------------
9+
:Version: @VERSION@
10+
:Manual group: Universal Ctags
11+
:Manual section: 7
12+
13+
SYNOPSIS
14+
--------
15+
| **@CTAGS_NAME_EXECUTABLE@** ... --languages=+Scheme ...
16+
| **@CTAGS_NAME_EXECUTABLE@** ... --language-force=Scheme ...
17+
| **@CTAGS_NAME_EXECUTABLE@** ... --map-Scheme=+.SCM ...
18+
| **@CTAGS_NAME_EXECUTABLE@** ... --map-Scheme=+.SM ...
19+
| **@CTAGS_NAME_EXECUTABLE@** ... --map-Scheme=+.sch ...
20+
| **@CTAGS_NAME_EXECUTABLE@** ... --map-Scheme=+.scheme ...
21+
| **@CTAGS_NAME_EXECUTABLE@** ... --map-Scheme=+.scm ...
22+
| **@CTAGS_NAME_EXECUTABLE@** ... --map-Scheme=+.sm ...
23+
| **@CTAGS_NAME_EXECUTABLE@** ... --map-Scheme=+.rkt ...
24+
25+
DESCRIPTION
26+
-----------
27+
This man page gathers random notes about tagging Scheme source code.
28+
29+
VERSIONS
30+
--------
31+
32+
Change since "0.0"
33+
~~~~~~~~~~~~~~~~~~
34+
35+
* Add ``unknown`` kind.
36+
37+
* Add ``definer`` field.
38+
39+
SEE ALSO
40+
--------
41+
ctags(1)

parsers/lisp.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ static kindDefinition EmacsLispKinds [] = {
134134
* lisp tag functions
135135
* look for (def or (DEF, quote or QUOTE
136136
*/
137-
static bool lisp_is_def (struct lispDialect *dialect, const unsigned char *strp)
137+
bool lispIsDef (struct lispDialect *dialect, const unsigned char *strp)
138138
{
139139
bool cis = dialect->case_insensitive; /* Renaming for making code short */
140140
bool is_def = ( (strp [1] == 'd' || (cis && strp [1] == 'D'))
@@ -478,7 +478,7 @@ static void findLispTags (void)
478478
.definer_field = LispFields + F_DEFINER,
479479
.skip_initial_spaces = false,
480480
.lambda_syntax_sugar = false,
481-
.is_def = lisp_is_def,
481+
.is_def = lispIsDef,
482482
.get_it = lispGetIt,
483483
.scope = CORK_NIL,
484484
};
@@ -496,7 +496,7 @@ static void findEmacsLispTags (void)
496496
.definer_field = EmacsLispFields + eF_DEFINER,
497497
.skip_initial_spaces = false,
498498
.lambda_syntax_sugar = false,
499-
.is_def = lisp_is_def,
499+
.is_def = lispIsDef,
500500
.get_it = lispGetIt,
501501
.scope = CORK_NIL,
502502
};

parsers/scheme.c

Lines changed: 70 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -13,21 +13,34 @@
1313
*/
1414
#include "general.h" /* must always come first */
1515

16-
#include <string.h>
17-
16+
#include "entry.h"
1817
#include "parse.h"
19-
#include "read.h"
20-
#include "routines.h"
21-
#include "vstring.h"
18+
19+
#include "x-lisp.h"
20+
21+
#include <ctype.h>
22+
#include <string.h>
2223

2324
/*
2425
* DATA DEFINITIONS
2526
*/
2627
typedef enum {
28+
K_UNKNOWN,
2729
K_FUNCTION, K_SET
2830
} schemeKind;
2931

32+
typedef enum {
33+
F_DEFINER,
34+
} schemeField;
35+
36+
static fieldDefinition SchemeFields[] = {
37+
{ .name = "definer",
38+
.description = "the name of the function or macro that defines the unknown/Y-kind object",
39+
.enabled = true },
40+
};
41+
3042
static kindDefinition SchemeKinds [] = {
43+
{ true, 'Y', "unknown", "unknown type of definitions" },
3144
{ true, 'f', "function", "functions" },
3245
{ true, 's', "set", "sets" }
3346
};
@@ -36,76 +49,60 @@ static kindDefinition SchemeKinds [] = {
3649
* FUNCTION DEFINITIONS
3750
*/
3851

39-
/* Algorithm adapted from from GNU etags.
40-
* Scheme tag functions
41-
* look for (def... xyzzy
42-
* look for (def... (xyzzy
43-
* look for (def ... ((... (xyzzy ....
44-
* look for (set! xyzzy
45-
*/
46-
static void readIdentifier (vString *const name, const unsigned char *cp)
52+
/*
53+
* FUNCTION DEFINITIONS
54+
*/
55+
static bool scheme_is_def (struct lispDialect *dialect, const unsigned char *strp)
4756
{
48-
const unsigned char *p;
49-
vStringClear (name);
50-
/* Go till you get to white space or a syntactic break */
51-
for (p = cp; *p != '\0' && *p != '(' && *p != ')' && !isspace (*p); p++)
52-
vStringPut (name, *p);
57+
bool cis = dialect->case_insensitive; /* Renaming for making code short */
58+
59+
bool is_set = ( (strp [1] == 's' || (cis && strp [1] == 'S'))
60+
&& (strp [2] == 'e' || (cis && strp [2] == 'E'))
61+
&& (strp [3] == 't' || (cis && strp [3] == 'T'))
62+
&& (strp [4] == '!'));
63+
if (is_set)
64+
return true;
65+
66+
return lispIsDef (dialect, strp);
5367
}
5468

55-
static void findSchemeTags (void)
69+
static int scheme_hint2kind (const vString *const hint, const char *namespace CTAGS_ATTR_UNUSED)
5670
{
57-
vString *name = vStringNew ();
58-
const unsigned char *line;
71+
int k = K_UNKNOWN;
72+
int n = vStringLength (hint) - 4;
5973

60-
while ((line = readLineFromInputFile ()) != NULL)
74+
if (strncmp (vStringValue (hint) + 1, "SET!", 4) == 0)
75+
return K_SET;
76+
77+
/* 4 means strlen("(def"). */
78+
#define EQN(X) strncmp(vStringValue (hint) + 4, &X[3], n) == 0
79+
switch (n)
6180
{
62-
const unsigned char *cp = line;
63-
64-
if (cp [0] == '(' &&
65-
(cp [1] == 'D' || cp [1] == 'd') &&
66-
(cp [2] == 'E' || cp [2] == 'e') &&
67-
(cp [3] == 'F' || cp [3] == 'f'))
68-
{
69-
while (*cp != '\0' && !isspace (*cp))
70-
cp++;
71-
/* Skip over open parens and white space */
72-
do {
73-
while (*cp != '\0' && (isspace (*cp) || *cp == '('))
74-
cp++;
75-
if (*cp == '\0')
76-
cp = line = readLineFromInputFile ();
77-
else
78-
break;
79-
} while (line);
80-
if (line == NULL)
81-
break;
82-
readIdentifier (name, cp);
83-
makeSimpleTag (name, K_FUNCTION);
84-
}
85-
if (cp [0] == '(' &&
86-
(cp [1] == 'S' || cp [1] == 's') &&
87-
(cp [2] == 'E' || cp [2] == 'e') &&
88-
(cp [3] == 'T' || cp [3] == 't') &&
89-
(cp [4] == '!') &&
90-
(isspace (cp [5]) || cp[5] == '\0'))
91-
{
92-
cp += 5;
93-
/* Skip over white space */
94-
do {
95-
while (*cp != '\0' && isspace (*cp))
96-
cp++;
97-
if (*cp == '\0')
98-
cp = line = readLineFromInputFile ();
99-
else
100-
break;
101-
} while (line);
102-
if (line == NULL)
103-
break;
104-
readIdentifier (name, cp);
105-
makeSimpleTag (name, K_SET);
106-
}
81+
case 3:
82+
if (EQN("DEFINE"))
83+
k = K_FUNCTION;
84+
break;
85+
10786
}
108-
vStringDelete (name);
87+
return k;
88+
}
89+
90+
static void findSchemeTags (void)
91+
{
92+
struct lispDialect scheme_dialect = {
93+
.definer2kind = scheme_hint2kind,
94+
.case_insensitive = true,
95+
.namespace_sep = 0,
96+
.unknown_kind = K_UNKNOWN,
97+
.definer_field = SchemeFields + F_DEFINER,
98+
.skip_initial_spaces = false,
99+
.lambda_syntax_sugar = true,
100+
.is_def = scheme_is_def,
101+
.get_it = lispGetIt,
102+
.scope = CORK_NIL,
103+
};
104+
105+
findLispTagsCommon (&scheme_dialect);
109106
}
110107

111108
extern parserDefinition* SchemeParser (void)
@@ -119,8 +116,13 @@ extern parserDefinition* SchemeParser (void)
119116
parserDefinition* def = parserNew ("Scheme");
120117
def->kindTable = SchemeKinds;
121118
def->kindCount = ARRAY_SIZE (SchemeKinds);
119+
def->fieldTable = SchemeFields;
120+
def->fieldCount = ARRAY_SIZE (SchemeFields);
122121
def->extensions = extensions;
123122
def->aliases = aliases;
124123
def->parser = findSchemeTags;
124+
def->useCork = CORK_QUEUE;
125+
def->versionCurrent = 0;
126+
def->versionAge = 1;
125127
return def;
126128
}

parsers/x-lisp.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,5 +34,6 @@ void findLispTagsCommon (struct lispDialect *dialect);
3434
int lispGetIt (struct lispDialect *dialect,
3535
vString *const name, const unsigned char *dbp, vString *kind_hint,
3636
const char *namespace);
37+
bool lispIsDef (struct lispDialect *dialect, const unsigned char *strp);
3738

3839
#endif /* CTAGS_LISP_H */

0 commit comments

Comments
 (0)