Skip to content

Commit

Permalink
Vim: fill implementation: field
Browse files Browse the repository at this point in the history
Signed-off-by: Masatake YAMATO <yamato@redhat.com>
  • Loading branch information
masatake committed Mar 13, 2024
1 parent 8680595 commit 76761d4
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 4 deletions.
2 changes: 1 addition & 1 deletion Units/parser-vim.r/vim-class.d/args.ctags
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
--sort=no
--fields=+tSen{access}
--fields=+tSen{access}{implementation}
10 changes: 10 additions & 0 deletions Units/parser-vim.r/vim-class.d/expected.tags
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,13 @@ v1 input-0.vim /^ final v1 = [1, 2] # final object variable$/;"
v2 input-0.vim /^ public final v2 = {x: 1} # final object variable$/;" C line:34 class:A access:public
v3 input-0.vim /^ static final v3 = 'abc' # final class variable$/;" C line:35 class:A
v4 input-0.vim /^ public static final v4 = 0z10 # final class variable$/;" C line:36 class:A access:public
Shape input-1.vim /^abstract class Shape$/;" k line:4 implementation:abstract end:7
color input-1.vim /^ var color = Color.Black$/;" v line:5 class:Shape
thickness input-1.vim /^ var thickness = 10$/;" v line:6 class:Shape
Square input-1.vim /^class Square extends Shape$/;" k line:9 end:14
size input-1.vim /^ var size: number$/;" v line:10 class:Square typeref:typename:number
new input-1.vim /^ def new(this.size)$/;" f line:12 class:Square signature:(this.size) end:13
Triangle input-1.vim /^class Triangle extends Shape$/;" k line:16 end:22
base input-1.vim /^ var base: number$/;" v line:17 class:Triangle typeref:typename:number
height input-1.vim /^ var height: number$/;" v line:18 class:Triangle typeref:typename:number
new input-1.vim /^ def new(this.base, this.height)$/;" f line:20 class:Triangle signature:(this.base,this.height) end:21
22 changes: 22 additions & 0 deletions Units/parser-vim.r/vim-class.d/input-1.vim
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
vim9script
# Taken from https://vim-jp.org/vimdoc-en/vim9class.html#Vim9-simple-class

abstract class Shape
var color = Color.Black
var thickness = 10
endclass

class Square extends Shape
var size: number

def new(this.size)
enddef
endclass

class Triangle extends Shape
var base: number
var height: number

def new(this.base, this.height)
enddef
endclass
10 changes: 7 additions & 3 deletions parsers/vim.c
Original file line number Diff line number Diff line change
Expand Up @@ -411,7 +411,8 @@ static void parseFunction (const unsigned char *line, int parent, bool definedWi
vStringDelete (name);
}

static void parseClass (const unsigned char *line, int parent, bool isPublic)
static void parseClass (const unsigned char *line, int parent,
bool isPublic, bool isAbstract)
{
vString *name = vStringNew ();
const unsigned char *cp = line;
Expand All @@ -438,6 +439,8 @@ static void parseClass (const unsigned char *line, int parent, bool isPublic)
e->extensionFields.scopeIndex = parent;
if (isPublic)
e->extensionFields.access = eStrdup ("public");
if (isAbstract)
e->extensionFields.implementation = eStrdup ("abstract");
}
while ((line = readVimLine ()) != NULL)
{
Expand Down Expand Up @@ -833,6 +836,7 @@ static bool parseVimLine (const unsigned char *line, int parent)
bool readNextLine = true;
int heredoc = CORK_NIL;
bool isPublic = false;
bool isAbstract = false;

while (true)
{
Expand All @@ -849,7 +853,7 @@ static bool parseVimLine (const unsigned char *line, int parent)
line += 8;
while (*line && isspace (*line))
++line;
/* TODO: abstract should be stored to a field. */
isAbstract = true;
continue;
}
else if (vim9script && wordMatchLen (line, "static", 6))
Expand Down Expand Up @@ -907,7 +911,7 @@ static bool parseVimLine (const unsigned char *line, int parent)
}
else if (vim9script && wordMatchLen (line, "class", 5))
{
parseClass (skipWord (line), parent, isPublic);
parseClass (skipWord (line), parent, isPublic, isAbstract);
}

tagEntryInfo *e;
Expand Down

0 comments on commit 76761d4

Please sign in to comment.