diff options
author | DongHun Kwak <dh0128.kwak@samsung.com> | 2021-10-15 10:54:45 +0900 |
---|---|---|
committer | DongHun Kwak <dh0128.kwak@samsung.com> | 2021-10-15 10:54:45 +0900 |
commit | 5e552810bc3dfc820036b4b16ae53561bb7cf3c6 (patch) | |
tree | 50ee6379d4fdad236b392051a73a2825dc98fb5e /src/pyscanner.l | |
parent | d6f1e74d173f59fc63d7e031cd9685b4eb38fed2 (diff) | |
download | doxygen-5e552810bc3dfc820036b4b16ae53561bb7cf3c6.tar.gz doxygen-5e552810bc3dfc820036b4b16ae53561bb7cf3c6.tar.bz2 doxygen-5e552810bc3dfc820036b4b16ae53561bb7cf3c6.zip |
Imported Upstream version 1.8.15upstream/1.8.15
Diffstat (limited to 'src/pyscanner.l')
-rw-r--r-- | src/pyscanner.l | 212 |
1 files changed, 171 insertions, 41 deletions
diff --git a/src/pyscanner.l b/src/pyscanner.l index 9c21d41..1596b9d 100644 --- a/src/pyscanner.l +++ b/src/pyscanner.l @@ -109,7 +109,7 @@ static QCString g_packageName; //static bool g_hideClassDocs; -static QCString g_defVal; +static QGString g_defVal; static int g_braceCount; static bool g_lexInit = FALSE; @@ -118,6 +118,8 @@ static bool g_packageCommentAllowed; static bool g_start_init = FALSE; static int g_search_count = 0; +static QCString g_argType = ""; +static bool g_funcParamsEnd; //----------------------------------------------------------------------------- @@ -487,7 +489,6 @@ SHORTSTRINGITEM ({SHORTSTRINGCHAR}|{ESCAPESEQ}) SHORTSTRINGCHAR [^\\\n"] STRINGLITERAL {STRINGPREFIX}?( {SHORTSTRING} | {LONGSTRING}) STRINGPREFIX ("r"|"u"|"ur"|"R"|"U"|"UR"|"Ur"|"uR") -KEYWORD ("lambda"|"import"|"class"|"assert"|"as"|"from"|"global"|"def"|"True"|"False") FLOWKW ("or"|"and"|"is"|"not"|"print"|"for"|"in"|"if"|"try"|"except"|"yield"|"raise"|"break"|"continue"|"pass"|"if"|"return"|"while"|"elif"|"else"|"finally") POUNDCOMMENT "#"[^#\n][^\n]* SCRIPTCOMMENT "#!".* @@ -514,6 +515,8 @@ STARTDOCSYMS "##" %x FunctionDec %x FunctionParams %x FunctionBody +%x FunctionAnnotation +%x FunctionTypeAnnotation %x FunctionParamDefVal /* Class states */ @@ -933,7 +936,6 @@ STARTDOCSYMS "##" } <FunctionDec>{ - {IDENTIFIER} { //found function name if (current->type.isEmpty()) @@ -944,47 +946,59 @@ 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; + current->bodyLine = yyLineNr; + BEGIN(FunctionParams); } + ")" { // end of parameter list + current->args = argListToString(current->argList); + g_funcParamsEnd = TRUE; + } } <FunctionParams>{ ({BB}|",") { } + [\*]+ { + g_argType = yytext; + } {IDENTIFIER} { // Name of parameter lineCount(); Argument *a = new Argument; current->argList->append(a); current->argList->getLast()->name = QCString(yytext).stripWhiteSpace(); - current->argList->getLast()->type = ""; + current->argList->getLast()->type = g_argType; + g_argType = ""; } "=" { // default value // 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. @@ -992,36 +1006,150 @@ STARTDOCSYMS "##" } -<FunctionParamDefVal>{ - "(" { // internal opening brace - g_braceCount++; +<FunctionTypeAnnotation>{ + "{" | + "[" | + "(" { + ++g_braceCount; + g_defVal+=*yytext; + } + "}" | + "]" | + ")" { + --g_braceCount; g_defVal+=*yytext; } - "," | - ")" { - if (g_braceCount==0) // end of default argument + ":" { + 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; + } +} + +<FunctionAnnotation>{ + "{" | + "[" | + "(" { + ++g_braceCount; + g_defVal+=*yytext; + } + "}" | + "]" { + --g_braceCount; + g_defVal+=*yytext; + } + ")" | + "=" | + "," { + if (g_braceCount == 0) { if (current->argList->getLast()) - { - current->argList->getLast()->defval=g_defVal.stripWhiteSpace(); - } - if (*yytext == ')') - current->args = argListToString(current->argList); + current->argList->getLast()->type += g_defVal.data(); + if (*yytext != ',') + unput(*yytext); BEGIN(FunctionParams); } - else // continue + else { - if (*yytext == ')')g_braceCount--; - g_defVal+=*yytext; - } + 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; + g_defVal+=*yytext; } +} + +<FunctionParamDefVal>{ + "{" | + "[" | + "(" { // internal opening brace, assumption is that we have correct code so braces do match + ++g_braceCount; + g_defVal+=*yytext; + } + "}" | + "]" { + --g_braceCount; + g_defVal+=*yytext; + } + ")" | + "," { + if (g_braceCount == 0) + { + if (current->argList->getLast()) + current->argList->getLast()->defval=QCString(g_defVal.data()).stripWhiteSpace(); + if (*yytext == ')') + unput(*yytext); + BEGIN(FunctionParams); + } + else + { + if (*yytext == ')') + --g_braceCount; + g_defVal += *yytext; + } + } + + "'" { + g_defVal+=*yytext; + g_copyString=&g_defVal; + g_stringContext=FunctionParamDefVal; + BEGIN( SingleQuoteString ); + } + "\"" { + g_defVal+=*yytext; + g_copyString=&g_defVal; + g_stringContext=FunctionParamDefVal; + BEGIN( DoubleQuoteString ); + } \n { g_defVal+=*yytext; incLineNr(); } + . { + g_defVal+=*yytext; + } } @@ -1168,13 +1296,17 @@ STARTDOCSYMS "##" current->program+=yytext; BEGIN(TripleComment); } - {TRISINGLEQUOTE} { // start of a comment block initTriSingleQuoteBlock(); current->program+=yytext; BEGIN(TripleComment); } - + {STARTDOCSYMS}[#]* { // start of a special comment + initSpecialBlock(); + BEGIN(SpecialComment); + } + {POUNDCOMMENT} { // ignore comment with just one # + } ^{BB} { current->program+=yytext; //current->startLine = yyLineNr; @@ -1187,7 +1319,6 @@ STARTDOCSYMS "##" } ""/({NONEMPTY}|{EXPCHAR}) { - // Just pushback an empty class, and // resume parsing the body. newEntry(); @@ -1380,7 +1511,6 @@ STARTDOCSYMS "##" BEGIN(Search); } <<EOF>> { yyterminate(); - newEntry(); } } @@ -1409,7 +1539,7 @@ STARTDOCSYMS "##" actualDoc.prepend("\\verbatim "); actualDoc.append("\\endverbatim "); } - actualDoc.prepend("\\namespace "+g_moduleScope+"\\_linebr "); + actualDoc.prepend("\\namespace "+g_moduleScope+" "); handleCommentBlock(actualDoc, FALSE); } if ((docBlockContext==ClassBody /*&& !g_hideClassDocs*/) || @@ -1492,7 +1622,7 @@ STARTDOCSYMS "##" \\. { // espaced char addToString(yytext); } - "\"\"\"" { // tripple double quotes + "\"\"\"" { // triple double quotes addToString(yytext); } "'" { // end of the string @@ -1515,7 +1645,7 @@ STARTDOCSYMS "##" \\. { // espaced char addToString(yytext); } - "'''" { // tripple single quotes + "'''" { // triple single quotes addToString(yytext); } "\"" { // end of the string |