Skip to content

Commit

Permalink
optlib2c: support datatype flag in --_fielddef option
Browse files Browse the repository at this point in the history
Signed-off-by: Masatake YAMATO <[email protected]>
  • Loading branch information
masatake committed Jan 20, 2025
1 parent 4f98367 commit 0582c06
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 5 deletions.
45 changes: 43 additions & 2 deletions misc/optlib2c
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,36 @@ my $langdef_flags =
} ],
];

my $fielddef_flags =
[
[ qr/\{datatype=([^\}]+)\}/, sub {
my $datatype = "";

if ($1 eq 'str')
{
$datatype .= "FIELDTYPE_STRING";
}
elsif ($1 eq 'int')
{
$datatype .= "FIELDTYPE_INTEGER";
}
elsif ($1 eq 'bool')
{
$datatype .= "FIELDTYPE_BOOL";
}
elsif (($1 eq 'bool+str') || ($1 eq 'str+bool'))
{
$datatype .= "FIELDTYPE_STRING|FIELDTYPE_BOOL";
}
else
{
die "Unknown datatype specification: \"{datatype=$1}\" in \"--_fielddef-<LANG>=...\"";
}

$_[0]->{'datatype'} = $datatype;
} ],
];

my $options =
[
[ qr/^--options=(.*)/, sub {
Expand Down Expand Up @@ -135,18 +165,22 @@ my $options =
push @{$_[0]->{'extradefs'}}, { name => $name, desc => $desc };
return 1;
} ],
[ qr/^--_fielddef-(.*)=([^,]+),([^\{]+)/, sub {
[ qr/^--_fielddef-(.*)=([^,]+),([^\{]+)(.*)/, sub {
die "Don't use --_fielddef-<LANG>=+ option before defining the language"
if (! defined $_[0]->{'langdef'});
die "Adding a field is allowed only to the language specified with --langdef: $1"
unless ($_[0]->{'langdef'} eq $1);

my $name = $2;
my $desc = $3;
my $rest = $4;
die "unacceptable character is used for field name: $name"
unless ($name =~ /^[a-zA-Z]+$/);

push @{$_[0]->{'fielddefs'}}, { name => $name, desc => $desc };
my $fdef = { name => $name, desc => $desc };
push @{$_[0]->{'fielddefs'}}, $fdef;
parse_flags ($rest, $fdef, $fielddef_flags);

return 1;
} ],
[ qr/^--_roledef-([^.]*)\.(?:([a-zA-Z])|\{([a-zA-Z][a-zA-Z0-9]*)\})=([a-zA-Z0-9]+),([^\{]+)/, sub {
Expand Down Expand Up @@ -1062,6 +1096,13 @@ EOF
.enabled = $enabled,
.name = "$_->{'name'}",
.description = "$desc",
EOF
if (defined $_->{'datatype'}) {
print <<EOF;
.dataType = $_->{'datatype'},
EOF
}
print <<EOF;
},
EOF
}
Expand Down
1 change: 1 addition & 0 deletions optlib/inko.c
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,7 @@ extern parserDefinition* InkoParser (void)
.enabled = true,
.name = "implements",
.description = "Trait being implemented",
.dataType = FIELDTYPE_STRING,
},
};

Expand Down
2 changes: 1 addition & 1 deletion optlib/inko.ctags
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
--kinddef-Inko=c,constant,Constant definition
--kinddef-Inko=r,reopen,Reopen class

--_fielddef-Inko=implements,Trait being implemented
--_fielddef-Inko=implements,Trait being implemented{datatype=str}

--fields-Inko=+{implements}

Expand Down
2 changes: 2 additions & 0 deletions optlib/passwd.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,13 @@ extern parserDefinition* PasswdParser (void)
.enabled = true,
.name = "home",
.description = "home directory",
.dataType = FIELDTYPE_STRING,
},
{
.enabled = true,
.name = "shell",
.description = "login shell",
.dataType = FIELDTYPE_STRING,
},
};
static tagRegexTable PasswdTagRegexTable [] = {
Expand Down
4 changes: 2 additions & 2 deletions optlib/passwd.ctags
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@
--langdef=Passwd
--map-Passwd=+(passwd)
--kinddef-Passwd=u,username,user names
--_fielddef-Passwd=home,home directory
--_fielddef-Passwd=shell,login shell
--_fielddef-Passwd=home,home directory{datatype=str}
--_fielddef-Passwd=shell,login shell{datatype=str}
--fields-Passwd=+{home}
--fields-Passwd=+{shell}
--regex-Passwd=/^([^:]+):([^:]+):([^:]+):([^:]+):([^:]*):([^:]+):([^:]+)/\1/u/{_field=home:\6}{_field=shell:\7}

0 comments on commit 0582c06

Please sign in to comment.