Skip to content

Commit

Permalink
WIP: start on weight_allowed flag in parser
Browse files Browse the repository at this point in the history
  • Loading branch information
ikluft committed Sep 1, 2023
1 parent 35cb892 commit 91ce334
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/perl/prefvote/lib/PrefVote/Core/Input/CEF.pm
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ sub parse
#

# parse candidate preference order from line
my @pref_order = $parser->parse( $line );
my @pref_order = $parser->parse( $line, $self->{vote_def} );
push @{$self->{ballots}}, \@pref_order;
$self->debug_print( "parse: pref_order=" . join( ",", @pref_order ) );
}
Expand Down
15 changes: 13 additions & 2 deletions src/perl/prefvote/lib/PrefVote/Core/Input/CEF_Parser.yp
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,12 @@ quantifier:
;

weight:
'^' INT { return { weight => $_[2]}; }
'^' INT {
if ( not ( $_[0]->YYData->{VOTEDEF}{weight_allowed} // 0 )) {
$_[0]->YYError;
}
return { weight => $_[2]};
}
;

words:
Expand Down Expand Up @@ -133,6 +138,11 @@ sub _Lexer
$parser->{USER}{CHARNO} += length $1;
}

# check for end of input after whitespace
if ( length $parser->YYData->{INPUT} == 0 ) {
return ( '', undef );
}

# find first token from matching list
foreach my $token_pair ( @CEF_TOKENS ) {
my ( $token_name, $token_regex ) = @$token_pair;
Expand Down Expand Up @@ -164,8 +174,9 @@ sub _Lexer

sub parse
{
my ($self, $input_str) = @_;
my ($self, $input_str, $vote_def) = @_;
$self->YYData->{INPUT} = $input_str;
$self->YYData->{VOTEDEF} = $vote_def;
$self->{USER}{CHARNO} = 0;
my $result = $self->YYParse( yylex => \&_Lexer, yyerror => \&_Error );
return $result;
Expand Down

0 comments on commit 91ce334

Please sign in to comment.