Skip to content

Commit

Permalink
Lisp,EmacsLisp: add definer: field to record defX in "(defX foo..."
Browse files Browse the repository at this point in the history
Increment the age of the parsers: 0.1

Signed-off-by: Masatake YAMATO <[email protected]>
  • Loading branch information
masatake committed Nov 19, 2024
1 parent 7928699 commit 9ae8d4c
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 11 deletions.
2 changes: 1 addition & 1 deletion Units/parser-emacsLisp.r/definitions.d/expected.tags
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
a0 input.el /^(defun a0 (n) (+ 1 n))$/;" function
b0 input.el /^(defvar b0 3)$/;" variable
c0 input.el /^(defconstant c0 5)$/;" unknown
c0 input.el /^(defconstant c0 5)$/;" unknown definer:defconstant
defunknown0 input.el /^(defmacro defunknown0 (s)$/;" macro
defunknown1 input.el /^(defmacro* defunknown1 (s)$/;" macro
e0 input.el /^(defalias 'e0 'a0)$/;" alias
Expand Down
4 changes: 2 additions & 2 deletions Units/parser-lisp.r/more-defsomething.d/expected.tags
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
url input.lisp /^(defmethod url ((url quri:uri))$/;" kind:method
url-designator input.lisp /^(deftype url-designator ()$/;" kind:type
renderer-scheme input.lisp /^(defclass renderer-scheme ()$/;" kind:class
scheme input.lisp /^(define-class scheme (renderer-scheme)$/;" kind:unknown
scheme input.lisp /^(define-class scheme (renderer-scheme)$/;" kind:unknown definer:DEFINE-CLASS
browser-schemes input.lisp /^(defgeneric browser-schemes (browser)$/;" kind:generic
:nyxt/renderer/gtk input.lisp /^(nyxt:define-package :nyxt\/renderer\/gtk$/;" kind:unknown
:nyxt/renderer/gtk input.lisp /^(nyxt:define-package :nyxt\/renderer\/gtk$/;" kind:unknown definer:DEFINE-PACKAGE
renderer-history-entry input.lisp /^(defstruct renderer-history-entry$/;" kind:struct
local-p input.lisp /^(defmethod (setf local-p) (value (scheme gtk-scheme))$/;" kind:method
2 changes: 1 addition & 1 deletion Units/parser-lisp.r/simple-lisp.d/expected.tags
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ c0 input.l /^(defconstant c0 5)$/;" c
C1 input.l /^(DEFCONSTANT C1 6)$/;" c
defunknown0 input.l /^(defmacro defunknown0 (s)$/;" m
DEFUNKNOWN1 input.l /^(DEFMACRO DEFUNKNOWN1 (s)$/;" m
unknown input.l /^(defunknown1 unknown)$/;" Y
unknown input.l /^(defunknown1 unknown)$/;" Y definer:DEFUNKNOWN1
67 changes: 60 additions & 7 deletions parsers/lisp.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
*/
#include "general.h" /* must always come first */

#include "entry.h"
#include "field.h"
#include "parse.h"
#include "read.h"
#include "routines.h"
Expand Down Expand Up @@ -49,6 +51,16 @@ static kindDefinition LispKinds [] = {
{ true, 'G', "generic", "generic" },
};

typedef enum {
F_DEFINER,
} lispField;

static fieldDefinition LispFields[] = {
{ .name = "definer",
.description = "the name of the function or the macro that defines unknown/Y kind tags",
.enabled = true },
};

typedef enum {
eK_UNKNOWN,
eK_FUNCTION,
Expand All @@ -69,6 +81,16 @@ typedef enum {
eK_THEME,
} emacsLispKind;

typedef enum {
eF_DEFINER,
} emacsLispField;

static fieldDefinition EmacsLispFields[] = {
{ .name = "definer",
.description = "the name of the function or the macro that defines unknown/Y kind tags",
.enabled = true },
};

/* Following macro/builtin doesn't define a name appeared
* at car. So this parser doesn't handle it well.
* -----------------------------------------------------
Expand Down Expand Up @@ -314,7 +336,9 @@ static int elisp_hint2kind (const vString *const hint)
static void L_getit (vString *const name, const unsigned char *dbp,
bool case_insensitive,
int (*hint2kind) (const vString *),
const vString *const kind_hint)
const vString *const kind_hint,
int unknown_kind,
fieldDefinition *definer_field)
{
const unsigned char *p;

Expand All @@ -338,8 +362,21 @@ static void L_getit (vString *const name, const unsigned char *dbp,
if (vStringLength (name) > 0)
{
int kind = hint2kind (kind_hint);
const char *definer = NULL;

if (kind == unknown_kind)
{
definer = vStringValue(kind_hint);
if (definer[0] == '(')
definer++;
}

if (kind != KIND_GHOST_INDEX)
makeSimpleTag (name, kind);
{
int index = makeSimpleTag (name, kind);
if (definer_field && definer_field->enabled && definer && index != CORK_NIL)
attachParserFieldToCorkEntry (index, definer_field->ftype, definer);
}
}
vStringClear (name);
}
Expand All @@ -348,7 +385,9 @@ static void L_getit (vString *const name, const unsigned char *dbp,
*/
static void findLispTagsCommon (bool case_insensitive,
bool has_namespace,
int (*hint2kind) (const vString *))
int (*hint2kind) (const vString *),
int unknown_kind,
fieldDefinition *definer_field)
{
vString *name = vStringNew ();
vString *kind_hint = vStringNew ();
Expand All @@ -370,7 +409,8 @@ static void findLispTagsCommon (bool case_insensitive,
}
while (isspace (*p))
p++;
L_getit (name, p, case_insensitive, hint2kind, kind_hint);
L_getit (name, p, case_insensitive, hint2kind, kind_hint,
unknown_kind, definer_field);
}
else if (has_namespace)
{
Expand All @@ -395,7 +435,8 @@ static void findLispTagsCommon (bool case_insensitive,
}
while (isspace (*p))
p++;
L_getit (name, p, case_insensitive, hint2kind, kind_hint);
L_getit (name, p, case_insensitive, hint2kind, kind_hint,
unknown_kind, definer_field);
}
}
}
Expand All @@ -407,12 +448,14 @@ static void findLispTagsCommon (bool case_insensitive,

static void findLispTags (void)
{
findLispTagsCommon (true, true, lisp_hint2kind);
findLispTagsCommon (true, true, lisp_hint2kind,
K_UNKNOWN, LispFields + F_DEFINER);
}

static void findEmacsLispTags (void)
{
findLispTagsCommon (false, false, elisp_hint2kind);
findLispTagsCommon (false, false, elisp_hint2kind,
eK_UNKNOWN, EmacsLispFields + eF_DEFINER);
}

extern parserDefinition* LispParser (void)
Expand All @@ -429,10 +472,15 @@ extern parserDefinition* LispParser (void)
parserDefinition* def = parserNew ("Lisp");
def->kindTable = LispKinds;
def->kindCount = ARRAY_SIZE (LispKinds);
def->fieldTable = LispFields;
def->fieldCount = ARRAY_SIZE (LispFields);
def->extensions = extensions;
def->aliases = aliases;
def->parser = findLispTags;
def->selectLanguage = selectors;
def->useCork = CORK_QUEUE;
def->versionCurrent = 0;
def->versionAge = 1;
return def;
}

Expand All @@ -448,8 +496,13 @@ extern parserDefinition* EmacsLispParser (void)
parserDefinition* def = parserNew ("EmacsLisp");
def->kindTable = EmacsLispKinds;
def->kindCount = ARRAY_SIZE (EmacsLispKinds);
def->fieldTable = EmacsLispFields;
def->fieldCount = ARRAY_SIZE (EmacsLispFields);
def->extensions = extensions;
def->aliases = aliases;
def->parser = findEmacsLispTags;
def->useCork = CORK_QUEUE;
def->versionCurrent = 0;
def->versionAge = 1;
return def;
}

0 comments on commit 9ae8d4c

Please sign in to comment.