Skip to content

Commit

Permalink
Vala: tag enum and enum values
Browse files Browse the repository at this point in the history
Signed-off-by: Masatake YAMATO <yamato@redhat.com>
  • Loading branch information
masatake committed Dec 19, 2020
1 parent f275734 commit 4d4f386
Show file tree
Hide file tree
Showing 4 changed files with 121 additions and 0 deletions.
1 change: 1 addition & 0 deletions Units/parser-vala.r/enum.vala.d/args.ctags
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
--sort=no
19 changes: 19 additions & 0 deletions Units/parser-vala.r/enum.vala.d/expected.tags
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
Skk input.vala /^namespace Skk {$/;" n
ModifierType input.vala /^ public enum ModifierType {$/;" e namespace:Skk
NONE input.vala /^ NONE = 0,$/;" v enum:Skk.ModifierType
SHIFT_MASK input.vala /^ SHIFT_MASK = 1 << 0,$/;" v enum:Skk.ModifierType
LOCK_MASK input.vala /^ LOCK_MASK = 1 << 1,$/;" v enum:Skk.ModifierType
CONTROL_MASK input.vala /^ CONTROL_MASK = 1 << 2,$/;" v enum:Skk.ModifierType
MOD1_MASK input.vala /^ MOD1_MASK = 1 << 3,$/;" v enum:Skk.ModifierType
MOD2_MASK input.vala /^ MOD2_MASK = 1 << 4,$/;" v enum:Skk.ModifierType
MOD3_MASK input.vala /^ MOD3_MASK = 1 << 5,$/;" v enum:Skk.ModifierType
MOD4_MASK input.vala /^ MOD4_MASK = 1 << 6,$/;" v enum:Skk.ModifierType
MOD5_MASK input.vala /^ MOD5_MASK = 1 << 7,$/;" v enum:Skk.ModifierType
LSHIFT_MASK input.vala /^ LSHIFT_MASK = 1 << 22,$/;" v enum:Skk.ModifierType
RSHIFT_MASK input.vala /^ RSHIFT_MASK = 1 << 23,$/;" v enum:Skk.ModifierType
USLEEP_MASK input.vala /^ USLEEP_MASK = 1 << 24,$/;" v enum:Skk.ModifierType
SUPER_MASK input.vala /^ SUPER_MASK = 1 << 26,$/;" v enum:Skk.ModifierType
HYPER_MASK input.vala /^ HYPER_MASK = 1 << 27,$/;" v enum:Skk.ModifierType
META_MASK input.vala /^ META_MASK = 1 << 28,$/;" v enum:Skk.ModifierType
RELEASE_MASK input.vala /^ RELEASE_MASK = 1 << 30$/;" v enum:Skk.ModifierType
KeyEvent input.vala /^ public class KeyEvent : Object {$/;" c namespace:Skk
58 changes: 58 additions & 0 deletions Units/parser-vala.r/enum.vala.d/input.vala
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
/* Taken from https://github.com/ueno/libskk
* (libskk/libskk/key-event.vala)
* errordomain is removed because ctags is not ready to parse it.
*/

/*
* Copyright (C) 2011-2018 Daiki Ueno <ueno@gnu.org>
* Copyright (C) 2011-2018 Red Hat, Inc.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
using Gee;

namespace Skk {
/**
* A set of bit-flags to indicate the state of modifier keys.
*/
[Flags]
public enum ModifierType {
NONE = 0,
SHIFT_MASK = 1 << 0,
LOCK_MASK = 1 << 1,
CONTROL_MASK = 1 << 2,
MOD1_MASK = 1 << 3,
MOD2_MASK = 1 << 4,
MOD3_MASK = 1 << 5,
MOD4_MASK = 1 << 6,
MOD5_MASK = 1 << 7,

// dummy modifiers for NICOLA
LSHIFT_MASK = 1 << 22,
RSHIFT_MASK = 1 << 23,
USLEEP_MASK = 1 << 24,

SUPER_MASK = 1 << 26,
HYPER_MASK = 1 << 27,
META_MASK = 1 << 28,
RELEASE_MASK = 1 << 30
}

/**
* Object representing a key event.
*/
public class KeyEvent : Object {
/* ... */
}
}
43 changes: 43 additions & 0 deletions parsers/vala.c
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,7 @@ static void parseNamespace (tokenInfo *const token, int corkIndex);
static void parseInterface (tokenInfo *const token, int corkIndex);
static void parseClass (tokenInfo *const token, int corkIndex);
static void parseStatement (tokenInfo *const token, int corkIndex);
static void parseEnum (tokenInfo *const token, int corkIndex);


/*
Expand Down Expand Up @@ -563,6 +564,46 @@ static void parseStatement (tokenInfo *const token, int parentIndex)
tokenDelete (lastToken);
}

static void parseEnumBody (tokenInfo *const token, int corkIndex)
{
bool s = tokenTypePairSetState (&valaTokenInfoClass, '<', false);
while (!tokenIsEOF (token))
{
tokenRead (token);
if (tokenIsType (token, IDENTIFIER))
{
makeSimpleTagFromToken (token, K_ENUMVALUE, corkIndex);
tokenType endMakers [] = {',', '}'};
if (tokenSkipToTypesOverPairs (token, endMakers, ARRAY_SIZE(endMakers)))
{
if (tokenIsTypeVal (token, '}'))
break;
}
else
break;
}
}
tokenTypePairSetState (&valaTokenInfoClass, '<', s);
}

static void parseEnum (tokenInfo *const token, int corkIndex)
{
tokenRead (token);
if (!tokenIsType (token, IDENTIFIER))
return; /* Unexpected sequence of token */

int enumCorkIndex = makeSimpleTagFromToken (token, K_ENUM, corkIndex);

tokenRead (token);
if (!tokenSkipToType (token, '{'))
return; /* Unexpected sequence of token */
parseEnumBody (token, enumCorkIndex);

tagEntryInfo *e = getEntryInCorkQueue (enumCorkIndex);
if (e)
e->extensionFields.endLine = token->lineNumber;
}

static void recurseValaTags (tokenInfo *token, int parentIndex)
{
/* Skip attributes */
Expand All @@ -574,6 +615,8 @@ static void recurseValaTags (tokenInfo *token, int parentIndex)
parseInterface (token, parentIndex);
else if (tokenIsKeyword(token, CLASS))
parseClass (token, parentIndex);
else if (tokenIsKeyword(token, ENUM))
parseEnum (token, parentIndex);
else if (tokenIsType (token, IDENTIFIER))
parseStatement (token, parentIndex);
}
Expand Down

0 comments on commit 4d4f386

Please sign in to comment.