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 b8fde38 commit 9addeda
Show file tree
Hide file tree
Showing 6 changed files with 68 additions and 11 deletions.
2 changes: 2 additions & 0 deletions Tmain/list-fields-with-prefix.d/stdout-expected.txt
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,14 @@ x UCTAGSxpath no NONE s-- no -- xpath for
- UCTAGSproperties no CUDA s-- no -- properties (static, inline, mutable, export,...)
- UCTAGSsection no CUDA s-- no -- the place where the object is placed
- UCTAGSmoduleName yes Elm s-- no -- actual name of renamed module
- UCTAGSdefiner yes EmacsLisp s-- no -- the name of the function or macro that defines the unknown/Y-kind object
- UCTAGSannotations yes GDScript s-- no -- annotations on functions and variables
- UCTAGShowImported no Go s-- no -- how the package is imported ("inline" for `.' or "init" for `_')
- UCTAGSpackage yes Go s-- no -- the real package specified by the package name
- UCTAGSpackageName yes Go s-- no -- the name for referring the package
- UCTAGSimplements yes Inko s-- no -- Trait being implemented
- UCTAGSassignment yes LdScript s-- no -- how a value is assigned to the symbol
- UCTAGSdefiner yes Lisp s-- no -- the name of the function or macro that defines the unknown/Y-kind object
- UCTAGSsectionMarker no Markdown s-- no -- character used for declaring section(#, ##, =, or -)
- UCTAGSwrapping yes Moose s-- no -- how a wrapper wrapping the method (around, after, or before)
- UCTAGSlangid yes NSIS s-- no -- language identifier specified in (License)LangString commands
Expand Down
2 changes: 2 additions & 0 deletions Tmain/list-fields.d/stdout-expected.txt
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,14 @@ z kind no NONE s-- no r- [tags output] prepend "kind:" to k/ (or K/) field outpu
- properties no CUDA s-- no -- properties (static, inline, mutable, export,...)
- section no CUDA s-- no -- the place where the object is placed
- moduleName yes Elm s-- no -- actual name of renamed module
- definer yes EmacsLisp s-- no -- the name of the function or macro that defines the unknown/Y-kind object
- annotations yes GDScript s-- no -- annotations on functions and variables
- howImported no Go s-- no -- how the package is imported ("inline" for `.' or "init" for `_')
- package yes Go s-- no -- the real package specified by the package name
- packageName yes Go s-- no -- the name for referring the package
- implements yes Inko s-- no -- Trait being implemented
- assignment yes LdScript s-- no -- how a value is assigned to the symbol
- definer yes Lisp s-- no -- the name of the function or macro that defines the unknown/Y-kind object
- sectionMarker no Markdown s-- no -- character used for declaring section(#, ##, =, or -)
- wrapping yes Moose s-- no -- how a wrapper wrapping the method (around, after, or before)
- langid yes NSIS s-- no -- language identifier specified in (License)LangString commands
Expand Down
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,9 +1,9 @@
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
%buffer input.lisp /^(defparameter %buffer nil)$/;" kind:parameter
: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 @@ -51,6 +53,16 @@ static kindDefinition LispKinds [] = {
{ true, 'p', "parameter", "parameters" },
};

typedef enum {
F_DEFINER,
} lispField;

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

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

typedef enum {
eF_DEFINER,
} emacsLispField;

static fieldDefinition EmacsLispFields[] = {
{ .name = "definer",
.description = "the name of the function or macro that defines the unknown/Y-kind object",
.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 @@ -320,7 +342,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 @@ -344,8 +368,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 @@ -354,7 +391,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 @@ -376,7 +415,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 @@ -401,7 +441,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 @@ -413,12 +454,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 @@ -435,10 +478,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 @@ -454,8 +502,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 9addeda

Please sign in to comment.