Skip to content

Commit c48fee3

Browse files
committed
optlib2c: introduce --__selector-<LANG>= pseudo option for injecting a select to optlib parser
LEX parser, a parser in development, has .l in its map. It conflicts with Lisp parser that has also .l in its map. A selector is needed for arbitration. As a temporarily solution, this change introduces --__selector-<LANG>= option to optlib2. optlib2c sets the C language function name specified with the option to the selectLanguage member of the Parser structure. In addition, this change introduces a new convention; ctags ignores an argument started with '--__'. optlib2c may handle the argument. Signed-off-by: Masatake YAMATO <[email protected]>
1 parent 2b5d5cd commit c48fee3

File tree

2 files changed

+34
-0
lines changed

2 files changed

+34
-0
lines changed

main/options.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3354,6 +3354,10 @@ static void processLongOption (
33543354
;
33553355
else if (processRolesOption (option, parameter))
33563356
;
3357+
else if (option[0] == '_' && option[1] == '_')
3358+
/* ctags ignores an argument started from --__.
3359+
* optlib2c may handle the argument. */
3360+
;
33573361
else
33583362
error (FATAL, "Unknown option: --%s", option);
33593363
}

misc/optlib2c

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,12 @@ my $options =
4444
parse_optlib ($1, $_[0]);
4545
return 1;
4646
} ],
47+
[ qr/^--__selector-(.*)=(.*)/, sub {
48+
die "Don't use --__selector-<LANG>= option before defining the language"
49+
if (! defined $_[0]->{'langdef'});
50+
$_[0]->{'selector'} = $2;
51+
return 1;
52+
} ],
4753
#
4854
# TODO: We should not assume the order of flags.
4955
#
@@ -590,6 +596,11 @@ EOF
590596
if (defined $opts->{'base'}) {
591597
print <<EOF;
592598
#include "subparser.h"
599+
EOF
600+
}
601+
if (defined $opts->{'selector'}) {
602+
print <<EOF;
603+
#include "selectors.h"
593604
EOF
594605
}
595606
print <<EOF;
@@ -949,6 +960,16 @@ EOF
949960
EOF
950961
}
951962

963+
sub emit_selector {
964+
my $opts = shift;
965+
966+
if (defined $opts->{'selector'}) {
967+
print <<EOF;
968+
static selectLanguage selectors[] = { $opts->{'selector'}, NULL };
969+
EOF
970+
}
971+
}
972+
952973
sub emit_fields_initialization {
953974
my $opts = shift;
954975
my $enabled = $opts->{"disabled"} ? "false": "true";
@@ -965,6 +986,13 @@ sub emit_fields_initialization {
965986
def->extensions = extensions;
966987
def->patterns = patterns;
967988
def->aliases = aliases;
989+
EOF
990+
if (defined $opts->{'selector'}) {
991+
print <<EOF;
992+
def->selectLanguage= selectors;
993+
EOF
994+
}
995+
print <<EOF;
968996
def->method = ${method};
969997
EOF
970998

@@ -1059,6 +1087,7 @@ EOF
10591087
emit_xtags $opts;
10601088
emit_regexs $opts;
10611089
emit_dependencies $opts;
1090+
emit_selector $opts;
10621091

10631092
print "\n";
10641093

@@ -1134,6 +1163,7 @@ sub main {
11341163
],
11351164
sequel => [ # ""
11361165
],
1166+
selector => undef,
11371167
);
11381168

11391169
for (@_) {

0 commit comments

Comments
 (0)