Merge pull request #11 from esorton/bugfix/add-constexpr-keyword-to-arduino-ctags
[arduino-ctags.git] / lisp.c
blob6fdc4dd649fd0757606da0a33ccfe23c31fa2333
1 /*
2 * $Id: lisp.c 717 2009-07-07 03:40:50Z dhiebert $
4 * Copyright (c) 2000-2002, Darren Hiebert
6 * This source code is released for free distribution under the terms of the
7 * GNU General Public License.
9 * This module contains functions for generating tags for LISP files.
13 * INCLUDE FILES
15 #include "general.h" /* must always come first */
17 #include "parse.h"
18 #include "read.h"
19 #include "vstring.h"
22 * DATA DEFINITIONS
24 typedef enum {
25 K_FUNCTION
26 } lispKind;
28 static kindOption LispKinds [] = {
29 { TRUE, 'f', "function", "functions" }
33 * FUNCTION DEFINITIONS
37 * lisp tag functions
38 * look for (def or (DEF, quote or QUOTE
40 static int L_isdef (const unsigned char *strp)
42 return ( (strp [1] == 'd' || strp [1] == 'D')
43 && (strp [2] == 'e' || strp [2] == 'E')
44 && (strp [3] == 'f' || strp [3] == 'F'));
47 static int L_isquote (const unsigned char *strp)
49 return ( (*(++strp) == 'q' || *strp == 'Q')
50 && (*(++strp) == 'u' || *strp == 'U')
51 && (*(++strp) == 'o' || *strp == 'O')
52 && (*(++strp) == 't' || *strp == 'T')
53 && (*(++strp) == 'e' || *strp == 'E')
54 && isspace (*(++strp)));
57 static void L_getit (vString *const name, const unsigned char *dbp)
59 const unsigned char *p;
61 if (*dbp == '\'') /* Skip prefix quote */
62 dbp++;
63 else if (*dbp == '(' && L_isquote (dbp)) /* Skip "(quote " */
65 dbp += 7;
66 while (isspace (*dbp))
67 dbp++;
69 for (p=dbp ; *p!='\0' && *p!='(' && !isspace ((int) *p) && *p!=')' ; p++)
70 vStringPut (name, *p);
71 vStringTerminate (name);
73 if (vStringLength (name) > 0)
74 makeSimpleTag (name, LispKinds, K_FUNCTION);
75 vStringClear (name);
78 /* Algorithm adapted from from GNU etags.
80 static void findLispTags (void)
82 vString *name = vStringNew ();
83 const unsigned char* p;
86 while ((p = fileReadLine ()) != NULL)
88 if (*p == '(')
90 if (L_isdef (p))
92 while (*p != '\0' && !isspace ((int) *p))
93 p++;
94 while (isspace ((int) *p))
95 p++;
96 L_getit (name, p);
98 else
100 /* Check for (foo::defmumble name-defined ... */
102 p++;
103 while (*p != '\0' && !isspace ((int) *p)
104 && *p != ':' && *p != '(' && *p != ')');
105 if (*p == ':')
108 p++;
109 while (*p == ':');
111 if (L_isdef (p - 1))
113 while (*p != '\0' && !isspace ((int) *p))
114 p++;
115 while (isspace (*p))
116 p++;
117 L_getit (name, p);
123 vStringDelete (name);
126 extern parserDefinition* LispParser (void)
128 static const char *const extensions [] = {
129 "cl", "clisp", "el", "l", "lisp", "lsp", NULL
131 parserDefinition* def = parserNew ("Lisp");
132 def->kinds = LispKinds;
133 def->kindCount = KIND_COUNT (LispKinds);
134 def->extensions = extensions;
135 def->parser = findLispTags;
136 return def;
139 /* vi:set tabstop=4 shiftwidth=4: */