Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
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
1 change: 1 addition & 0 deletions Units/parser-pascal.r/bug612019.pas.t/expected.tags
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
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
36 changes: 30 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 @@ -280,7 +296,8 @@ static void findPascalTags (void)

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 +337,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 +357,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