From 72c5c25695273c96f30f118cb8270a037e28eb7a Mon Sep 17 00:00:00 2001 From: Sergey Kozlov Date: Mon, 8 Oct 2018 17:08:04 +0600 Subject: Add function annotations support --- src/pyscanner.l | 159 ++++++++++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 131 insertions(+), 28 deletions(-) diff --git a/src/pyscanner.l b/src/pyscanner.l index 3743712..f986a35 100644 --- a/src/pyscanner.l +++ b/src/pyscanner.l @@ -119,6 +119,7 @@ static bool g_start_init = FALSE; static int g_search_count = 0; static QCString g_argType = ""; +static bool g_funcParamsEnd; //----------------------------------------------------------------------------- @@ -514,6 +515,8 @@ STARTDOCSYMS "##" %x FunctionDec %x FunctionParams %x FunctionBody +%x FunctionAnnotation +%x FunctionTypeAnnotation %x FunctionParamDefVal /* Class states */ @@ -933,7 +936,6 @@ STARTDOCSYMS "##" } { - {IDENTIFIER} { //found function name if (current->type.isEmpty()) @@ -944,16 +946,26 @@ STARTDOCSYMS "##" current->name = current->name.stripWhiteSpace(); newFunction(); } - {B}":" { // function without arguments + {B}":"{B} { // function without arguments g_specialBlock = TRUE; // expecting a docstring bodyEntry = current; current->bodyLine = yyLineNr; - BEGIN( FunctionBody ); + BEGIN(FunctionBody); } + "->" { + g_defVal.resize(0); + g_braceCount = 0; + BEGIN(FunctionTypeAnnotation); + } {B}"(" { - BEGIN( FunctionParams ); + g_funcParamsEnd = FALSE; + BEGIN(FunctionParams); } + ")" { // end of parameter list + current->args = argListToString(current->argList); + g_funcParamsEnd = TRUE; + } } { @@ -975,20 +987,18 @@ STARTDOCSYMS "##" // TODO: this rule is too simple, need to be able to // match things like =")" as well! g_defVal.resize(0); - g_braceCount=0; + g_braceCount = 0; BEGIN(FunctionParamDefVal); } - - ")" { // end of parameter list - current->args = argListToString(current->argList); + ")" { + unput(*yytext); + BEGIN(FunctionDec); } - ":"{B} { - g_specialBlock = TRUE; // expecting a docstring - bodyEntry = current; - current->bodyLine = yyLineNr; - BEGIN( FunctionBody ); - } + g_defVal.resize(0); + g_braceCount = 0; + BEGIN(FunctionAnnotation); + } {POUNDCOMMENT} { // a comment } {PARAMNONEMPTY} { // Default rule inside arguments. @@ -996,31 +1006,124 @@ STARTDOCSYMS "##" } +{ + "[" | + "(" { + ++g_braceCount; + g_defVal+=*yytext; + } + "]" | + ")" { + --g_braceCount; + g_defVal+=*yytext; + } + ":" { + if (g_braceCount == 0) + { + current->type = g_defVal.data(); + unput(*yytext); + BEGIN(FunctionDec); + } + else + g_defVal+=*yytext; + } + "'" { + g_defVal+=*yytext; + g_copyString=&g_defVal; + g_stringContext=FunctionTypeAnnotation; + BEGIN(SingleQuoteString); + } + "\"" { + g_defVal+=*yytext; + g_copyString=&g_defVal; + g_stringContext=FunctionTypeAnnotation; + BEGIN(DoubleQuoteString); + } + \n { + g_defVal+=*yytext; + incLineNr(); + } + . { + g_defVal+=*yytext; + } +} + +{ + "[" | + "(" { + ++g_braceCount; + g_defVal+=*yytext; + } + "]" { + --g_braceCount; + g_defVal+=*yytext; + } + ")" | + "," { + if (g_braceCount == 0) + { + if (current->argList->getLast()) + current->argList->getLast()->type += g_defVal.data(); + if (*yytext == ')') + unput(*yytext); + BEGIN(FunctionParams); + } + else + { + if (*yytext == ')') + --g_braceCount; + g_defVal += *yytext; + } + } + "'" { + g_defVal+=*yytext; + g_copyString=&g_defVal; + g_stringContext=FunctionAnnotation; + BEGIN(SingleQuoteString); + } + "\"" { + g_defVal+=*yytext; + g_copyString=&g_defVal; + g_stringContext=FunctionAnnotation; + BEGIN(DoubleQuoteString); + } + \n { + g_defVal+=*yytext; + incLineNr(); + } + . { + g_defVal+=*yytext; + } +} + { "[" | "(" { // internal opening brace, assumption is that we have correct code so braces do match - g_braceCount++; + ++g_braceCount; g_defVal+=*yytext; } - "," | - "]" | - ")" { - if (g_braceCount==0) // end of default argument + "]" { + --g_braceCount; + g_defVal+=*yytext; + } + ")" | + "," { + if (g_braceCount == 0) { if (current->argList->getLast()) - { current->argList->getLast()->defval=QCString(g_defVal.data()).stripWhiteSpace(); - } - if (*yytext != ',') - current->args = argListToString(current->argList); + if (*yytext == ')') + unput(*yytext); BEGIN(FunctionParams); } - else // continue - { - if (*yytext != ',')g_braceCount--; - g_defVal+=*yytext; - } + else + { + if (*yytext == ')') + --g_braceCount; + g_defVal += *yytext; + } } + "'" { g_defVal+=*yytext; g_copyString=&g_defVal; -- cgit v0.12 From 03894677569451502c4bbc0b5f656244357dd907 Mon Sep 17 00:00:00 2001 From: Sergey Kozlov Date: Mon, 8 Oct 2018 19:32:50 +0600 Subject: Fix annotation with default value parsing --- src/pyscanner.l | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/pyscanner.l b/src/pyscanner.l index f986a35..6df4ba9 100644 --- a/src/pyscanner.l +++ b/src/pyscanner.l @@ -1059,12 +1059,13 @@ STARTDOCSYMS "##" g_defVal+=*yytext; } ")" | + "=" | "," { if (g_braceCount == 0) { if (current->argList->getLast()) current->argList->getLast()->type += g_defVal.data(); - if (*yytext == ')') + if (*yytext != ',') unput(*yytext); BEGIN(FunctionParams); } -- cgit v0.12 From ec98b6f662024fc3d5bf47e33630fc8d06bde6c6 Mon Sep 17 00:00:00 2001 From: Sergey Kozlov Date: Mon, 8 Oct 2018 19:43:18 +0600 Subject: Add support of dict/set in annotations and default values --- src/pyscanner.l | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/pyscanner.l b/src/pyscanner.l index 6df4ba9..aed1ede 100644 --- a/src/pyscanner.l +++ b/src/pyscanner.l @@ -1007,11 +1007,13 @@ STARTDOCSYMS "##" } { + "{" | "[" | "(" { ++g_braceCount; g_defVal+=*yytext; } + "}" | "]" | ")" { --g_braceCount; @@ -1049,11 +1051,13 @@ STARTDOCSYMS "##" } { + "{" | "[" | "(" { ++g_braceCount; g_defVal+=*yytext; } + "}" | "]" { --g_braceCount; g_defVal+=*yytext; @@ -1098,11 +1102,13 @@ STARTDOCSYMS "##" } { + "{" | "[" | "(" { // internal opening brace, assumption is that we have correct code so braces do match ++g_braceCount; g_defVal+=*yytext; } + "}" | "]" { --g_braceCount; g_defVal+=*yytext; -- cgit v0.12