From f021f7b88d3a1fb5c0d7dc043ebd78572494cf94 Mon Sep 17 00:00:00 2001 From: Masatake YAMATO Date: Fri, 3 Dec 2021 04:57:37 +0900 Subject: [PATCH 1/3] Units(Pascal): move a "review-needed" test case to Units/parser-pascal.r @ntrel reviewed the case in #2241. Thank you. --- .../bug612019.pas.t/expected.tags | 0 .../bug612019.pas.t/input.pas | 0 2 files changed, 0 insertions(+), 0 deletions(-) rename Units/{review-needed.r => parser-pascal.r}/bug612019.pas.t/expected.tags (100%) rename Units/{review-needed.r => parser-pascal.r}/bug612019.pas.t/input.pas (100%) diff --git a/Units/review-needed.r/bug612019.pas.t/expected.tags b/Units/parser-pascal.r/bug612019.pas.t/expected.tags similarity index 100% rename from Units/review-needed.r/bug612019.pas.t/expected.tags rename to Units/parser-pascal.r/bug612019.pas.t/expected.tags diff --git a/Units/review-needed.r/bug612019.pas.t/input.pas b/Units/parser-pascal.r/bug612019.pas.t/input.pas similarity index 100% rename from Units/review-needed.r/bug612019.pas.t/input.pas rename to Units/parser-pascal.r/bug612019.pas.t/input.pas From 5db3b4206c1fc203f461fdd1f74b2f101d7125bd Mon Sep 17 00:00:00 2001 From: Nick Treleaven Date: Wed, 16 Oct 2019 17:21:30 +0100 Subject: [PATCH 2/3] Pascal: Port parsing of first `type` identifier Close #2241. @mastake's note: This pull chnage is based on #2241 submitted by @ntrel. I adjust the change not to fill "signature" field for tags of "type" kind. I also adjust the change to avoid regression. --- .../bug612019.pas.t/expected.tags | 1 + .../simple-pascal.d/expected.tags | 1 + parsers/pascal.c | 36 +++++++++++++++---- 3 files changed, 32 insertions(+), 6 deletions(-) diff --git a/Units/parser-pascal.r/bug612019.pas.t/expected.tags b/Units/parser-pascal.r/bug612019.pas.t/expected.tags index a8f373c74c..92f85a9f34 100644 --- a/Units/parser-pascal.r/bug612019.pas.t/expected.tags +++ b/Units/parser-pascal.r/bug612019.pas.t/expected.tags @@ -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 diff --git a/Units/parser-pascal.r/simple-pascal.d/expected.tags b/Units/parser-pascal.r/simple-pascal.d/expected.tags index 28b22ffa9d..37ece871ae 100644 --- a/Units/parser-pascal.r/simple-pascal.d/expected.tags +++ b/Units/parser-pascal.r/simple-pascal.d/expected.tags @@ -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:() diff --git a/parsers/pascal.c b/parsers/pascal.c index f5700ef645..3afa7572cc 100644 --- a/parsers/pascal.c +++ b/parsers/pascal.c @@ -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"} }; @@ -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. @@ -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 */ @@ -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 != ' ') { @@ -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; + verify_tag = false; + } + } if (found_tag && verify_tag) /* not external proc, so make tag */ { found_tag = false; @@ -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; @@ -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 */ @@ -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 */ } @@ -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; From 37b2ed7b158bbe1c8221dedb680b5c84c5bdc69b Mon Sep 17 00:00:00 2001 From: Nick Treleaven Date: Wed, 16 Oct 2019 17:46:13 +0100 Subject: [PATCH 3/3] Pascal: fix looking for an identifier when there's a comment --- .../comment-after-keyword.d/expected.tags | 1 + .../parser-pascal.r/comment-after-keyword.d/input.pas | 10 ++++++++++ parsers/pascal.c | 2 ++ 3 files changed, 13 insertions(+) create mode 100644 Units/parser-pascal.r/comment-after-keyword.d/expected.tags create mode 100644 Units/parser-pascal.r/comment-after-keyword.d/input.pas diff --git a/Units/parser-pascal.r/comment-after-keyword.d/expected.tags b/Units/parser-pascal.r/comment-after-keyword.d/expected.tags new file mode 100644 index 0000000000..ec14d560cc --- /dev/null +++ b/Units/parser-pascal.r/comment-after-keyword.d/expected.tags @@ -0,0 +1 @@ +Fun1 input.pas /^function {} Fun1: integer;$/;" f typeref:typename:integer diff --git a/Units/parser-pascal.r/comment-after-keyword.d/input.pas b/Units/parser-pascal.r/comment-after-keyword.d/input.pas new file mode 100644 index 0000000000..35821c7f55 --- /dev/null +++ b/Units/parser-pascal.r/comment-after-keyword.d/input.pas @@ -0,0 +1,10 @@ +program hello; + +function {} Fun1: integer; +begin + Fun1 := 1; +end; + +begin + Fun1(); +end. diff --git a/parsers/pascal.c b/parsers/pascal.c index 3afa7572cc..8b4e9855eb 100644 --- a/parsers/pascal.c +++ b/parsers/pascal.c @@ -290,6 +290,8 @@ 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);