From 7c22ceacf996ea0ac773349afca39eed6af4b9ea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ji=C5=99=C3=AD=20Techet?= Date: Sun, 7 Dec 2014 22:25:13 +0100 Subject: [PATCH] Update the go parser to the latest version from ctags --- tagmanager/ctags/go.c | 80 +++++++++++++++++++------------------------ 1 file changed, 35 insertions(+), 45 deletions(-) diff --git a/tagmanager/ctags/go.c b/tagmanager/ctags/go.c index 4eefab14..1e5c2d76 100644 --- a/tagmanager/ctags/go.c +++ b/tagmanager/ctags/go.c @@ -521,20 +521,16 @@ static void makeTag (tokenInfo *const token, const goKind kind) static void parsePackage (tokenInfo *const token) { - tokenInfo *const name = newToken (); - - readToken (name); - if (isType (name, TOKEN_IDENTIFIER)) + readToken (token); + if (isType (token, TOKEN_IDENTIFIER)) { - makeTag (name, GOTAG_PACKAGE); + makeTag (token, GOTAG_PACKAGE); if (!scope && Option.include.qualifiedTags) { scope = vStringNew (); - vStringCopy (scope, name->string); + vStringCopy (scope, token->string); } } - - deleteToken (name); } static void parseFunctionOrMethod (tokenInfo *const token) @@ -545,15 +541,16 @@ static void parseFunctionOrMethod (tokenInfo *const token) // MethodDecl = "func" Receiver MethodName Signature [ Body ] . // Receiver = "(" [ identifier ] [ "*" ] BaseTypeName ")" . // BaseTypeName = identifier . - tokenInfo *const name = newToken (); // Skip over receiver. - readToken (name); - if (isType (name, TOKEN_OPEN_PAREN)) - skipToMatched (name); + readToken (token); + if (isType (token, TOKEN_OPEN_PAREN)) + skipToMatched (token); - if (isType (name, TOKEN_IDENTIFIER)) + if (isType (token, TOKEN_IDENTIFIER)) { + makeTag (token, GOTAG_FUNCTION); + // Skip over parameters. readToken (token); skipToMatched (token); @@ -564,11 +561,7 @@ static void parseFunctionOrMethod (tokenInfo *const token) // Skip over function body. if (isType (token, TOKEN_OPEN_CURLY)) skipToMatched (token); - - makeTag (name, GOTAG_FUNCTION); } - - deleteToken (name); } static void parseConstTypeVar (tokenInfo *const token, goKind kind) @@ -581,49 +574,46 @@ static void parseConstTypeVar (tokenInfo *const token, goKind kind) // TypeSpec = identifier Type . // VarDecl = "var" ( VarSpec | "(" { VarSpec ";" } ")" ) . // VarSpec = IdentifierList ( Type [ "=" ExpressionList ] | "=" ExpressionList ) . - tokenInfo *const name = newToken (); boolean usesParens = FALSE; - readToken (name); + readToken (token); - if (isType (name, TOKEN_OPEN_PAREN)) + if (isType (token, TOKEN_OPEN_PAREN)) { usesParens = TRUE; - readToken (name); + readToken (token); } -again: - while (1) + do { - if (isType (name, TOKEN_IDENTIFIER)) + while (!isType (token, TOKEN_EOF)) { - makeTag (name, kind); + if (isType (token, TOKEN_IDENTIFIER)) + { + makeTag (token, kind); + readToken (token); + } + if (!isType (token, TOKEN_COMMA)) + break; readToken (token); } - if (!isType (token, TOKEN_COMMA)) - break; - readToken (name); - } - skipType (token); - while (!isType (token, TOKEN_SEMICOLON) && !isType (token, TOKEN_CLOSE_PAREN) - && !isType (token, TOKEN_EOF)) - { - readToken (token); - skipToMatched (token); - } - - if (usesParens) - { - if (!isType (token, TOKEN_CLOSE_PAREN)) // we are at TOKEN_SEMICOLON + skipType (token); + while (!isType (token, TOKEN_SEMICOLON) && !isType (token, TOKEN_CLOSE_PAREN) + && !isType (token, TOKEN_EOF)) { - readToken (name); - if (!isType (name, TOKEN_CLOSE_PAREN) && !isType (name, TOKEN_EOF)) - goto again; + readToken (token); + skipToMatched (token); + } + + if (usesParens && !isType (token, TOKEN_CLOSE_PAREN)) + { + // we are at TOKEN_SEMICOLON + readToken (token); } } - - deleteToken (name); + while (!isType (token, TOKEN_EOF) && + usesParens && !isType (token, TOKEN_CLOSE_PAREN)); } static void parseGoFile (tokenInfo *const token)