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

Pascal: extract type #3212

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
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
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
TTest input.pas /^ TTest=class$/;" t
Test1 input.pas /^ procedure Test1;$/;" p
Test2 input.pas /^ procedure Test2;$/;" p
Test3 input.pas /^ procedure Test3;$/;" p
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fun1 input.pas /^function {} Fun1: integer;$/;" f typeref:typename:integer
10 changes: 10 additions & 0 deletions Units/parser-pascal.r/comment-after-keyword.d/input.pas
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
program hello;

function {} Fun1: integer;
begin
Fun1 := 1;
end;

begin
Fun1();
end.
1 change: 1 addition & 0 deletions Units/parser-pascal.r/simple-pascal.d/expected.tags
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
simpletype input.pas /^ simpletype = RECORD$/;" t
helloproc input.pas /^PROCEDURE helloproc(param1: STRING; param2: BYTE);$/;" p signature:(param1: STRING; param2: BYTE)
max input.pas /^FUNCTION max(num1, num2: INTEGER): INTEGER;$/;" f typeref:typename:INTEGER signature:(num1, num2: INTEGER)
noargs input.pas /^FUNCTION noargs: STRING;$/;" f typeref:typename:STRING signature:()
Expand Down
38 changes: 32 additions & 6 deletions parsers/pascal.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,12 @@
* DATA DEFINITIONS
*/
typedef enum {
K_FUNCTION, K_PROCEDURE
K_FUNCTION, K_TYPE, K_PROCEDURE
} pascalKind;

static kindDefinition PascalKinds [] = {
{ true, 'f', "function", "functions"},
{ true, 't', "type", "types"},
{ true, 'p', "procedure", "procedures"}
};

Expand Down Expand Up @@ -145,7 +146,7 @@ static void parseArglist(const char *buf, vString *arglist, vString *vartype)
}

/* Algorithm adapted from from GNU etags.
* Locates tags for procedures & functions. Doesn't do any type- or
* Locates tags for procedures & functions. Doesn't do full type- or
* var-definitions. It does look for the keyword "extern" or "forward"
* immediately following the procedure statement; if found, the tag is
* skipped.
Expand All @@ -159,7 +160,7 @@ static void findPascalTags (void)
pascalKind kind = K_FUNCTION;
/* each of these flags is true iff: */
bool incomment = false; /* point is inside a comment */
int comment_char = '\0'; /* type of current comment */
int comment_char = '\0'; /* type of current comment */
bool inquote = false; /* point is inside '..' string */
bool get_tagname = false;/* point is after PROCEDURE/FUNCTION
keyword, so next item = potential tag */
Expand Down Expand Up @@ -234,6 +235,13 @@ static void findPascalTags (void)
break;
}
continue;
case '=':
if (found_tag && kind == K_TYPE)
{
verify_tag = true;
break;
}
continue;
}
if (found_tag && verify_tag && *dbp != ' ')
{
Expand All @@ -256,6 +264,14 @@ static void findPascalTags (void)
verify_tag = false;
}
}
else if (tolower ((int) *dbp) == 't')
{
if (tail ("type")) /* check for type declaration */
{
found_tag = false;
Copy link
Member Author

Choose a reason for hiding this comment

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

These lines are not covered by the test cases.

verify_tag = false;
}
}
if (found_tag && verify_tag) /* not external proc, so make tag */
{
found_tag = false;
Expand All @@ -264,7 +280,7 @@ static void findPascalTags (void)
continue;
}
}
if (get_tagname) /* grab name of proc or fn */
if (get_tagname) /* grab identifier */
{
const unsigned char *cp;

Expand All @@ -274,13 +290,16 @@ static void findPascalTags (void)
/* grab block name */
while (isspace ((int) *dbp))
++dbp;
if (!starttoken(*dbp))
continue;
for (cp = dbp ; *cp != '\0' && !endtoken (*cp) ; cp++)
continue;
vStringNCopyS (name, (const char*) dbp, cp - dbp);

vStringClear (arglist);
vStringClear (vartype);
parseArglist((const char*) cp, arglist, (kind == K_FUNCTION) ? vartype : NULL);
if (kind == K_FUNCTION || kind == K_PROCEDURE)
parseArglist((const char*) cp, arglist, (kind == K_FUNCTION) ? vartype : NULL);

createPascalTag (&tag, name, kind, arglist, (kind == K_FUNCTION) ? vartype : NULL);
dbp = cp; /* set dbp to e-o-token */
Expand Down Expand Up @@ -320,6 +339,13 @@ static void findPascalTags (void)
kind = K_FUNCTION;
}
break;
case 't':
if (tail ("ype"))
{
get_tagname = true;
kind = K_TYPE;
}
break;
}
} /* while not eof */
}
Expand All @@ -333,7 +359,7 @@ extern parserDefinition* PascalParser (void)
static const char *const extensions [] = { "p", "pas", NULL };
parserDefinition* def = parserNew ("Pascal");
def->extensions = extensions;
def->kindTable = PascalKinds;
def->kindTable = PascalKinds;
def->kindCount = ARRAY_SIZE (PascalKinds);
def->parser = findPascalTags;
return def;
Expand Down