Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Errors once #152

Merged
merged 2 commits into from
Aug 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 13 additions & 24 deletions perl/gherkin-perl.razor
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
}
@helper HandleParserError(IEnumerable<string> expectedTokens, State state)
{<text> $token->detach;
my $err = $self->_construct_parser_error(
$err = $self->_construct_parser_error(
$token,
["@Raw(string.Join("\", \"", expectedTokens))"],
"State: @state.Id - @Raw(state.Comment)",
Expand All @@ -26,7 +26,7 @@
return @state.Id;
</text>}
@helper MatchToken(TokenType tokenType)
{<text>match_@(tokenType)($context, $token)</text>}
{<text>$context->token_matcher->match_@(tokenType)($token)</text>}
package Gherkin::Generated::@(Model.ParserClassName);

# This file is generated. Do not edit! Edit gherkin-perl.razor instead.
Expand Down Expand Up @@ -94,29 +94,17 @@ sub _construct_parser_error {
return $error_class->new( $token, @@args );
}

@foreach(var rule in Model.RuleSet.TokenRules)
{<text>
sub match_@(rule.Name.Replace("#", "")) {
my ($self, $context, $token) = @@_;
@if (rule.Name != "#EOF")
{
@:return if $token->is_eof;
}
return $self->handle_external_error(
$context,
sub { $context->token_matcher->match_@(rule.Name.Replace("#", ""))( $token ) }
);
}
</text>}

@foreach(var state in Model.States.Values.Where(s => !s.IsEndState)) //..
{<text>
# @Raw(state.Comment)
sub match_token_at_@(state.Id) {
my ( $self, $token, $context ) = @@_;
my ( $ok, $err );
@foreach(var transition in state.Transitions)
{
@:if ($self->@MatchToken(transition.TokenType)) {
@:($ok, $err) = @MatchToken(transition.TokenType);
@:if ($ok) {
@:$self->add_error( $context, $err ) if $err;
if (transition.LookAheadHint != null)
{
@:if ($self->lookahead_@(transition.LookAheadHint.Id)($context, $token)) {
Expand Down Expand Up @@ -150,18 +138,19 @@ sub lookahead_@(lookAheadHint.Id) {
my @@queue;
my $match = 0;

my $ok;
while (1) {
$token = $context->read_token();
$token->detach;
push( @@queue, $token );

@foreach(var tokenType in lookAheadHint.ExpectedTokens) {
@:$match = 1 if $self->@MatchToken(tokenType);
}
last if $match;
@foreach(var tokenType in lookAheadHint.ExpectedTokens) {<text>
($match) = @MatchToken(tokenType);
last if $match;</text>}

@foreach(var tokenType in lookAheadHint.Skip) {
@:next if $self->@MatchToken(tokenType);
@foreach(var tokenType in lookAheadHint.Skip) {<text>
($ok) = @MatchToken(tokenType);
next if $ok;</text>
}

last;
Expand Down
Loading