Skip to content

Commit a6f4f47

Browse files
authored
Merge pull request #3289 from masatake/basic--decl
Basic: extract declarations as reference tags (partially derived from #3276)
2 parents 37a4b36 + a503ac7 commit a6f4f47

File tree

7 files changed

+99
-4
lines changed

7 files changed

+99
-4
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ depcomp
4949
gdb-backtrace.txt
5050
install-sh
5151
libctags.a
52+
libutil.a
5253
Makefile.in
5354
mini-geany
5455
mini-geany.exe

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ Automake d/directory ltlibrary on directory for LTLIBR
1616
Automake d/directory man on directory for MANS primary
1717
Automake d/directory program on directory for PROGRAMS primary
1818
Automake d/directory script on directory for SCRIPTS primary
19+
Basic f/function decl on declared
1920
C d/macro condition off used in part of #if/#ifdef/#elif conditions
2021
C d/macro undef on undefined
2122
C h/header local on local header
@@ -120,6 +121,7 @@ Automake d/directory ltlibrary on directory for LTLIBR
120121
Automake d/directory man on directory for MANS primary
121122
Automake d/directory program on directory for PROGRAMS primary
122123
Automake d/directory script on directory for SCRIPTS primary
124+
Basic f/function decl on declared
123125
C d/macro condition off used in part of #if/#ifdef/#elif conditions
124126
C d/macro undef on undefined
125127
C h/header local on local header
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
--sort=no
2+
--fields=+rE
3+
--extras=+r
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
curses input.bas /^namespace curses 'public use this$/;" n roles:def
2+
win input.bas /^ type win as curses.curses_priv._win_st$/;" t namespace:curses roles:def
3+
_Init input.bas /^ declare function _Init alias "initscr" () as win ptr$/;" f namespace:curses roles:decl extras:reference
4+
GetMaxX input.bas /^ declare function GetMaxX alias "getmaxx" (byval as win ptr) as integer$/;" f namespace:curses roles:decl extras:reference
5+
GetMaxY input.bas /^ declare function GetMaxY alias "getmaxy" (byval as win ptr) as integer$/;" f namespace:curses roles:decl extras:reference
6+
CreateWindow input.bas /^ declare function CreateWindow alias "newwin" (byval as integer, byval as integer, byval as int/;" f namespace:curses roles:decl extras:reference
7+
CreateSubWindow input.bas /^ declare function CreateSubWindow alias "subwin" (byval as win ptr, byval as integer, byval as /;" f namespace:curses roles:decl extras:reference
8+
GetChar input.bas /^ declare function GetChar alias "getch" () as UByte$/;" f namespace:curses roles:decl extras:reference
9+
CBreak input.bas /^ declare function CBreak alias "cbreak" () as integer$/;" f namespace:curses roles:decl extras:reference
10+
EreaseTerm input.bas /^ declare function EreaseTerm alias "erase" () as integer$/;" f namespace:curses roles:decl extras:reference
11+
ClearTerm input.bas /^ declare function ClearTerm alias "clear" () as integer$/;" f namespace:curses roles:decl extras:reference
12+
EreaseWindow input.bas /^ declare function EreaseWindow alias "werase" (byval as win ptr) as integer$/;" f namespace:curses roles:decl extras:reference
13+
ClearWindow input.bas /^ declare function ClearWindow alias "wclear" (byval as win ptr) as integer$/;" f namespace:curses roles:decl extras:reference
14+
DeleteWindow input.bas /^ declare function DeleteWindow alias "delwin" (byval as win ptr) as integer$/;" f namespace:curses roles:decl extras:reference
15+
_Exit input.bas /^ declare function _Exit alias "endwin" () as integer$/;" f namespace:curses roles:decl extras:reference
16+
RefresTerm input.bas /^ declare function RefresTerm alias "refresh" () as integer$/;" f namespace:curses roles:decl extras:reference
17+
RefreshWindow input.bas /^ declare function RefreshWindow alias "wrefresh" (byval as win ptr) as integer$/;" f namespace:curses roles:decl extras:reference
18+
PrintTerm input.bas /^ declare function PrintTerm alias "printw" (byval as zstring ptr, ... ) as integer$/;" f namespace:curses roles:decl extras:reference
19+
PrintWindow input.bas /^ declare function PrintWindow alias "wprintw" (byval as win ptr, byval as zstring ptr, ... ) as/;" f namespace:curses roles:decl extras:reference
20+
SetCursorPositionTerm input.bas /^ declare function SetCursorPositionTerm alias "move" (byval as integer,byval as integer) as int/;" f namespace:curses roles:decl extras:reference
21+
SetCursorPositionWindow input.bas /^ declare function SetCursorPositionWindow alias "wmove" (byval as win ptr, byval as integer, by/;" f namespace:curses roles:decl extras:reference
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
' Taken from https://termbin.com/x9wo submitted by @Glog78
2+
namespace curses 'public use this
3+
#include "curses_priv.bi"
4+
#inclib "curses"
5+
6+
extern "c"
7+
8+
type win as curses.curses_priv._win_st
9+
10+
declare function _Init alias "initscr" () as win ptr
11+
declare function GetMaxX alias "getmaxx" (byval as win ptr) as integer
12+
declare function GetMaxY alias "getmaxy" (byval as win ptr) as integer
13+
declare function CreateWindow alias "newwin" (byval as integer, byval as integer, byval as integer, byval as integer) as win
14+
declare function CreateSubWindow alias "subwin" (byval as win ptr, byval as integer, byval as integer, byval as integer, byval as integer) as win ptr
15+
declare function GetChar alias "getch" () as UByte
16+
declare function CBreak alias "cbreak" () as integer
17+
declare function EreaseTerm alias "erase" () as integer
18+
declare function ClearTerm alias "clear" () as integer
19+
declare function EreaseWindow alias "werase" (byval as win ptr) as integer
20+
declare function ClearWindow alias "wclear" (byval as win ptr) as integer
21+
declare function DeleteWindow alias "delwin" (byval as win ptr) as integer
22+
declare function _Exit alias "endwin" () as integer
23+
declare function RefresTerm alias "refresh" () as integer
24+
declare function RefreshWindow alias "wrefresh" (byval as win ptr) as integer
25+
declare function PrintTerm alias "printw" (byval as zstring ptr, ... ) as integer
26+
declare function PrintWindow alias "wprintw" (byval as win ptr, byval as zstring ptr, ... ) as integer
27+
declare function SetCursorPositionTerm alias "move" (byval as integer,byval as integer) as integer
28+
declare function SetCursorPositionWindow alias "wmove" (byval as win ptr, byval as integer, byval as integer) as integer
29+
30+
end extern
31+
32+
end namespace 'curses
33+
34+
' vim: bs=2 sw=2 ss=2 ts=2 nu noet ft=basic

parsers/basic.c

Lines changed: 37 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,18 @@ typedef enum {
4141
K_NAMESPACE,
4242
} BasicKind;
4343

44+
typedef enum {
45+
BASIC_FUNCTION_DECL,
46+
} basciFunctionRole;
47+
48+
static roleDefinition BasicFunctionRoles [] = {
49+
{ true, "decl", "declared" },
50+
};
51+
4452
static kindDefinition BasicKinds[] = {
4553
{true, 'c', "constant", "constants"},
46-
{true, 'f', "function", "functions"},
54+
{true, 'f', "function", "functions",
55+
.referenceOnly = false, ATTACH_ROLES(BasicFunctionRoles)},
4756
{true, 'l', "label", "labels"},
4857
{true, 't', "type", "types"},
4958
{true, 'v', "variable", "variables"},
@@ -63,6 +72,7 @@ enum eKeywordID {
6372
KEYWORD_NAMESPACE,
6473
KEYWORD_END,
6574
KEYWORD_ACCESS,
75+
KEYWORD_DECLARE,
6676
};
6777
typedef int keywordId; /* to allow KEYWORD_NONE */
6878

@@ -82,6 +92,7 @@ static const keywordTable BasicKeywordTable[] = {
8292
{"enum", KEYWORD_ENUM},
8393
{"namespace", KEYWORD_NAMESPACE},
8494
{"end", KEYWORD_END},
95+
{"declare", KEYWORD_DECLARE},
8596

8697
/* blitzbasic, purebasic */
8798
{"global", KEYWORD_VARIABLE},
@@ -123,11 +134,15 @@ struct BasicKeywordAttr {
123134
[KEYWORD_ACCESS] = {
124135
.kind = KIND_GHOST_INDEX,
125136
},
137+
[KEYWORD_DECLARE] = {
138+
.kind = KIND_GHOST_INDEX,
139+
},
126140
};
127141

128142
struct matchState {
129143
const char *access;
130144
bool end;
145+
bool declaration;
131146
};
132147

133148
static int currentScope;
@@ -214,15 +229,20 @@ static bool isIdentChar (char c)
214229
return c && !isspace (c) && c != '(' && c != ',' && c != '=';
215230
}
216231

217-
static int makeBasicTag (vString *name, int kindIndex)
232+
static int makeBasicRefTag (vString *name, int kindIndex, int roleIndex)
218233
{
219-
int r = makeSimpleTag (name, kindIndex);
234+
int r = makeSimpleRefTag (name, kindIndex, roleIndex);
220235
tagEntryInfo *e = getEntryInCorkQueue (r);
221236
if (e)
222237
e->extensionFields.scopeIndex = currentScope;
223238
return r;
224239
}
225240

241+
static int makeBasicTag (vString *name, int kindIndex)
242+
{
243+
return makeBasicRefTag (name, kindIndex, ROLE_DEFINITION_INDEX);
244+
}
245+
226246
/* Match the name of a dim or const starting at pos. */
227247
static void extract_dim (char const *pos, BasicKind kind)
228248
{
@@ -298,7 +318,13 @@ static int extract_name (char const *pos, BasicKind kind, struct matchState *sta
298318
vString *name = vStringNew ();
299319
for (; isIdentChar (*pos); pos++)
300320
vStringPut (name, *pos);
301-
r = makeBasicTag (name, kind);
321+
if (state && state->declaration)
322+
{
323+
if (kind == K_FUNCTION)
324+
r = makeBasicRefTag (name, kind, BASIC_FUNCTION_DECL);
325+
}
326+
else
327+
r = makeBasicTag (name, kind);
302328
vStringDelete (name);
303329

304330
tagEntryInfo *e = getEntryInCorkQueue (r);
@@ -313,6 +339,7 @@ static void match_state_reset (struct matchState *state)
313339
{
314340
state->access = NULL;
315341
state->end = false;
342+
state->declaration =false;
316343
}
317344

318345
static bool match_keyword (const char **cp, vString *buf,
@@ -346,6 +373,12 @@ static bool match_keyword (const char **cp, vString *buf,
346373
*cp = p;
347374
return true;
348375
}
376+
else if (kw == KEYWORD_DECLARE)
377+
{
378+
state->declaration = true;
379+
*cp = p;
380+
return true;
381+
}
349382

350383
int kind = keywordToKind (kw);
351384
int index = CORK_NIL;

peg/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
varlink.[ch]
22
kotlin.[ch]
3+
thrift.[ch]

0 commit comments

Comments
 (0)