Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

main: introduce --_makeTagEntryReflection-<LANG> option to filter tags #3027

Draft
wants to merge 5 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions Tmain/common-prelude.d/endwith.expected
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
true
false
false
false
true
true
true
Binary file added Tmain/common-prelude.d/endwith.ps
Binary file not shown.
1 change: 1 addition & 0 deletions Tmain/common-prelude.d/stdout-expected.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ buildstring.ps...0
chop.ps...0
dedup.ps...0
dedup_spaces.ps...0
endwith.ps...0
ndup.ps...0
normalize_spaces.ps...0
putlast.ps...0
Expand Down
2 changes: 1 addition & 1 deletion Tmain/optscript.d/error-undefined-if-if.expected
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ top| |bottom
Execution stack:
top| a {a} --if-- {true {a} if} --if-- |bottom
Dictionary stack:
top| -dict:1- -dict:89- |bottom
top| -dict:1- -dict:90- |bottom
2 changes: 1 addition & 1 deletion Tmain/optscript.d/error-undefined-if.expected
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ top| |bottom
Execution stack:
top| a {a} --if-- |bottom
Dictionary stack:
top| -dict:1- -dict:89- |bottom
top| -dict:1- -dict:90- |bottom
37 changes: 37 additions & 0 deletions Tmain/optscript.d/string.expected
Original file line number Diff line number Diff line change
Expand Up @@ -74,3 +74,40 @@ true
false
(a.b;c)
(\(a.b;c\) false ->)
(--------------- _strrpbrk ---------------)
x/abc.d|./
true
5
(x/abc.d)
x/abc.|./
true
5
(x/abc.)
x.abc/d|./
true
5
(x.abc/d)
x.abc/|./
true
5
(x.abc/)
x.abc.d|./
true
5
(x.abc.d)
x.abc.|./
true
5
(x.abc.)
abc|./
false
(abc)
|./
false
()
abc|
false
(abc)
|
false
()
Binary file modified Tmain/optscript.d/string.ps
Binary file not shown.
79 changes: 79 additions & 0 deletions Units/option-makeTagEntryReflection.d/args.ctags
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
# See #3020 and #3027.

--sort=no
--extras=+q

--_extradef-Markdown=withfname,appending input filename
--extras-Markdown=+{withfname}

--_prelude-Markdown={{
% You can customize the string combining the original name
% and the basen name of input file.
/SEP (@) def

% dict<original-index:int, withfname-index:int>
/scope-remapping-table 31 dict def

% (abc/input.d) dropext => (abc/input)
% (abc.d/input) dropext => (abc.d/input)
/dropext {
(/.) _strrpbrk {
% string offset
2 copy get ?/ eq {
pop
} {
0 exch 0 string _copyinterval
} ifelse
} if
} def

% (abc/efg) basename => (efg)
/basename {
?/ _strrchr {
1 add dup 2 index length exch sub
0 string _copyinterval
} if
} def
}}

--_sequel-Markdown={{
% Fill the scope field of withfname extra tags.
scope-remapping-table {
% Make the original tag invisible
exch dup _markplaceholder
:scope dup
% withfname-index:int original-scope:int original-scope:int
0 eq {
pop pop
} {
% withfname-index:int original-scope:int
scope-remapping-table exch get
% withfname-index:int withfname-scope:int
scope:
} ifelse
} forall
}}

--_makeTagEntryReflection-Markdown={{
/Markdown.withfname _extraenabled {
. :extras {
/Markdown.withfname _amember not
} {
true
} ifelse
{
mark
. :name
SEP
. :input dropext basename
_buildstring

. :kind
. _tagloc _tag dup /Markdown.withfname _markextra
_commit
% Record the pair of original-index:int and withfname-index:int.
scope-remapping-table . 3 -1 roll put
} if

} if
}}
7 changes: 7 additions & 0 deletions Units/option-makeTagEntryReflection.d/expected.tags
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
ABC@input input.md /^# ABC$/;" c
DEF@input input.md /^## DEF$/;" s chapter:ABC@input
GHI@input input.md /^### GHI$/;" S section:ABC@input""DEF@input
HIJ@input input.md /^### HIJ$/;" S section:ABC@input""DEF@input
KLM@input input.md /^## KLM$/;" s chapter:ABC@input
OPQ@input input.md /^# OPQ$/;" c
RST@input input.md /^### RST$/;" S chapter:OPQ@input
13 changes: 13 additions & 0 deletions Units/option-makeTagEntryReflection.d/input.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# ABC

## DEF

### GHI

### HIJ

## KLM

# OPQ

### RST
25 changes: 23 additions & 2 deletions dsl/optscript.c
Original file line number Diff line number Diff line change
Expand Up @@ -338,6 +338,7 @@ declop(_strrstr);
declop(_strchr);
declop(_strrchr);
declop(_strpbrk);
declop(_strrpbrk);

/* Relation, logical, and bit operators
tested in relalogbit.ps */
Expand Down Expand Up @@ -554,6 +555,8 @@ opt_init (void)
"string chr _STRRCHR string false");
defop (opt_system_dict, _strpbrk, 2, "string accept _STRPBRK string offset true%"
"string accept _STRPBRK string false");
defop (opt_system_dict, _strrpbrk, 2, "string accept _STRRPBRK string offset true%"
"string accept _STRRPBRK string false");

defop (opt_system_dict, exec, 1, "any EXEC -");
defop (opt_system_dict, if, 2, "bool proc IF -");
Expand Down Expand Up @@ -687,6 +690,12 @@ opt_dict_known_and_get_cstr (EsObject *dict, const char* name, EsObject **val)
return dict_op_known_and_get (dict, sym, val);
}

bool
opt_dict_known_and_get (EsObject *dict, EsObject *key, EsObject **val)
{
return dict_op_known_and_get (dict, key, val);
}

bool
opt_dict_foreach (EsObject *dict, bool (* fn) (EsObject *, EsObject *, void*), void *data)
{
Expand Down Expand Up @@ -3388,7 +3397,7 @@ op__strrchr (OptVM *vm, EsObject *name)
}

static EsObject*
op__strpbrk (OptVM *vm, EsObject *name)
op__strpbrk_common (OptVM *vm, EsObject *name, bool from_tail)
{
EsObject *acceptobj = ptrArrayLast (vm->ostack);
EsObject *strobj = ptrArrayItemFromLast (vm->ostack, 1);
Expand All @@ -3402,7 +3411,7 @@ op__strpbrk (OptVM *vm, EsObject *name)
vString *acceptv = es_pointer_get (acceptobj);

const char *str = vStringValue (strv);
char *p = strpbrk (str, vStringValue (acceptv));
char *p = (from_tail? strrpbrk: strpbrk) (str, vStringValue (acceptv));
if (p)
{
int d = p - str;
Expand All @@ -3423,6 +3432,18 @@ op__strpbrk (OptVM *vm, EsObject *name)
}
}

static EsObject*
op__strpbrk (OptVM *vm, EsObject *name)
{
return op__strpbrk_common (vm, name, false);
}

static EsObject*
op__strrpbrk (OptVM *vm, EsObject *name)
{
return op__strpbrk_common (vm, name, true);
}


/*
* Relation, logical, and bit operators
Expand Down
1 change: 1 addition & 0 deletions dsl/optscript.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ unsigned int opt_vm_ostack_count (OptVM *vm);

EsObject *opt_dict_new (unsigned int size);
bool opt_dict_known_and_get_cstr (EsObject *dict, const char* name, EsObject **val);
bool opt_dict_known_and_get (EsObject *dict, EsObject *key, EsObject **val);
bool opt_dict_foreach (EsObject *dict, bool (* fn) (EsObject *, EsObject *, void*), void *data);
void opt_dict_def (EsObject *dict, EsObject *sym, EsObject *val);
bool opt_dict_undef (EsObject *dict, EsObject *sym);
Expand Down
24 changes: 24 additions & 0 deletions main/CommonPrelude.c
Original file line number Diff line number Diff line change
Expand Up @@ -265,4 +265,28 @@ const char ctagsCommonPrelude []=
" _foreignreftag\n"
" } ifelse\n"
"} __bddef\n"
"\n"
"(string end:string _ENDWITH boolean)\n"
"/_endwith {\n"
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

_strendwith may be better name.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using _strrstr is one of the ways to shorten the proc.
Writing in C is another choice.

" 2 copy length exch length exch\n"
" % str endstr strlen endstrlen\n"
" 2 copy\n"
" ge {\n"
" % str endstr strlen endstrlen\n"
" dup 3 1 roll\n"
" % str endstr endstrlen strlen endstrlen\n"
" sub\n"
" % str endstr endstrlen offset\n"
" exch\n"
" % str endstr offset endstrlen\n"
" 4 -1 roll\n"
" % endstr offset endstrlen str\n"
" 3 1 roll\n"
" % str endstr str offset endstrlen\n"
" 0 string _copyinterval eq\n"
" } {\n"
" pop pop pop pop false\n"
" } ifelse\n"
"} __bddef\n"
"% (input.md) (.md) _endwith ==\n"
;
Binary file modified main/CommonPrelude.ps
Binary file not shown.
13 changes: 9 additions & 4 deletions main/dependency.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

#include "debug.h"
#include "dependency.h"
#include "entry.h"
#include "options.h"
#include "parse_p.h"
#include "read.h"
Expand Down Expand Up @@ -184,14 +185,18 @@ extern void notifyMakeTagEntry (const tagEntryInfo *tag, int corkIndex)
{
subparser *s;

/* running optscript code attaching to --makeTagEntryReflection-<LANG> */
langType lang = tag->langType;
notifyLanguageRegexMakeTagEntry (lang, corkIndex);

foreachSubparser(s, false)
{
enterSubparser(s);
if (s->makeTagEntryNotify)
{
enterSubparser(s);
s->makeTagEntryNotify (s, tag, corkIndex);
leaveSubparser();
}
/* propagate the event recursively */
notifyMakeTagEntry (tag, corkIndex);
leaveSubparser();
}
}

Expand Down
5 changes: 5 additions & 0 deletions main/dependency.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,9 @@ struct sSlaveParser {
slaveParser *next;
};

/* These are for CPreProcessor.
* Don't use in the other parsers. */
extern void notifyInputStart (void);
extern void notifyInputEnd (void);

#endif /* CTAGS_MAIN_DEPENDENCY_H */
11 changes: 11 additions & 0 deletions main/lregex.c
Original file line number Diff line number Diff line change
Expand Up @@ -2249,6 +2249,17 @@ extern void notifyRegexInputEnd (struct lregexControlBlock *lcb)
fillEndLineFieldOfUpperScopes (lcb, endline);
}

extern void notifyRegexMakeTagEntry (struct lregexControlBlock *lcb,
int corkIndex)
{
if (ptrArrayCount (lcb->hook[SCRIPT_HOOK_MAKE_TAG_ENTRY_REFLECTION]) > 0)
{
optscriptSetup (optvm, lcb->local_dict, corkIndex);
scriptEvalHook (optvm, lcb, SCRIPT_HOOK_MAKE_TAG_ENTRY_REFLECTION);
optscriptTeardown (optvm, lcb->local_dict);
}
}

extern void findRegexTagsMainloop (int (* driver)(void))
{
/* merely read all lines of the file */
Expand Down
1 change: 1 addition & 0 deletions main/lregex_p.h
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ extern bool matchMultitableRegex (struct lregexControlBlock *lcb, const vString*

extern void notifyRegexInputStart (struct lregexControlBlock *lcb);
extern void notifyRegexInputEnd (struct lregexControlBlock *lcb);
extern void notifyRegexMakeTagEntry (struct lregexControlBlock *lcb, int corkIndex);

extern void addRegexTable (struct lregexControlBlock *lcb, const char *name);
extern void extendRegexTable (struct lregexControlBlock *lcb, const char *src, const char *dist);
Expand Down
4 changes: 4 additions & 0 deletions main/options.c
Original file line number Diff line number Diff line change
Expand Up @@ -378,6 +378,8 @@ static optionDescription LongOptionDescription [] = {
{1,1," Define new extra for <LANG>. --extras-<LANG>=+{name} enables it."},
{1,1," --_fielddef-<LANG>=<name>,<description>"},
{1,1," Define new field for <LANG>."},
{1,1," --_makeTagEntryReflection-<LANG>={{ optscript-code }}"},
{1,1," Specify code run when <LANG> parser makes a tag."},
{1,1," --_mtable-extend-<LANG>=disttable+srctable."},
{1,1," Copy patterns of a regex table to another regex table."},
{1,1," --_mtable-regex-<LANG>=<table>/<line_pattern>/<name_pattern>/[<flags>]"},
Expand Down Expand Up @@ -3363,6 +3365,8 @@ static void processLongOption (
;
else if (processSequelOption (option, parameter))
;
else if (processMakeTagEntryReflectionOption (option, parameter))
;
else if (processPretendOption (option, parameter))
;
else if (processRolesOption (option, parameter))
Expand Down
1 change: 1 addition & 0 deletions main/options_p.h
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,7 @@ extern bool processRoledefOption (const char *const option, const char *const pa
extern bool processScopesepOption (const char *const option, const char *const parameter);
extern bool processPreludeOption (const char *const option, const char *const parameter);
extern bool processSequelOption (const char *const option, const char *const parameter);
extern bool processMakeTagEntryReflectionOption (const char *const option, const char *const parameter);
extern bool processPretendOption (const char *const option, const char *const parameter);
extern bool processRolesOption (const char *const option, const char *const parameter);

Expand Down
10 changes: 10 additions & 0 deletions main/parse.c
Original file line number Diff line number Diff line change
Expand Up @@ -4110,6 +4110,11 @@ extern void notifyLanguageRegexInputEnd (langType language)
notifyRegexInputEnd(pobj->lregexControlBlock);
}

extern void notifyLanguageRegexMakeTagEntry (langType language, int corkIndex)
{
notifyRegexMakeTagEntry((LanguageTable + language)->lregexControlBlock, corkIndex);
}

static unsigned int parserCorkFlags (parserDefinition *parser)
{
subparser *tmp;
Expand Down Expand Up @@ -5418,6 +5423,11 @@ extern bool processSequelOption (const char *const option, const char *const par
return processHookOption (option, parameter, "_sequel-", SCRIPT_HOOK_SEQUEL);
}

extern bool processMakeTagEntryReflectionOption (const char *const option, const char *const parameter)
{
return processHookOption (option, parameter, "_makeTagEntryReflection-", SCRIPT_HOOK_MAKE_TAG_ENTRY_REFLECTION);
}

extern bool processPretendOption (const char *const option, const char *const parameter)
{
langType new_language, old_language;
Expand Down
1 change: 1 addition & 0 deletions main/parse.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ typedef enum {
enum scriptHook {
SCRIPT_HOOK_PRELUDE,
SCRIPT_HOOK_SEQUEL,
SCRIPT_HOOK_MAKE_TAG_ENTRY_REFLECTION,
SCRIPT_HOOK_MAX,
};

Expand Down
Loading
Loading