Skip to content

Commit

Permalink
Merge pull request #526 from dpvc/fix-decimal
Browse files Browse the repository at this point in the history
Fix problem with decimals with no leading 0 (#525)
  • Loading branch information
mgage authored Feb 16, 2021
2 parents 01d8bb1 + 2088ac6 commit 1ed89f8
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
2 changes: 1 addition & 1 deletion lib/Parser/Context/Default.pm
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ $operators = {
string => ' >< ', TeX => '\times ', perl => 'x', fullparens => 1,
class => 'Parser::BOP::cross', alternatives => ["\x{00D7}"]},

'.' => {precedence => 2, associativity => 'left', type => 'bin',
'.' => {precedence => 2, associativity => 'left', type => 'bin', patternPrecedence => 8, # after number pattern
string => '.', TeX => '\cdot ', class => 'Parser::BOP::dot', alternatives => ["\x{2219}", "\x{2022}"]},

'*' => {precedence => 3, associativity => 'left', type => 'bin', space => ' *',
Expand Down
15 changes: 14 additions & 1 deletion lib/Value/Context/Data.pm
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,11 @@ sub addToken {
my $self = shift; my $token = shift;
my $def = $self->{context}{$self->{dataName}}{$token};
unless ($def->{hidden}) {
$self->{tokens}{$token} = $self->{tokenType};
if (defined $def->{patternPrecedence}) {
$self->{patterns}{Parser::Context::protectRegexp($token)} = [$def->{patternPrecedence}, $self->{tokenType}];
} else {
$self->{tokens}{$token} = $self->{tokenType};
}
$self->addAlternatives($token,$def->{alternatives});
}
}
Expand Down Expand Up @@ -108,6 +112,10 @@ sub add {
foreach my $x (keys %D) {
Value::Error("Illegal %s name '%s'",$self->{name},$x) unless $x =~ m/^$self->{namePattern}$/;
warn "$self->{Name} '$x' already exists" if defined($data->{$x});
if ($data->{$x}) {
delete $self->{tokens}{$x};
delete $self->{patterns}{Parser::Context::protectRegexp($x)};
}
$data->{$x} = $self->create($D{$x});
$self->addToken($x);
if (ref($data->{$x}) eq 'HASH' && $data->{$x}{alias}) {
Expand Down Expand Up @@ -218,6 +226,11 @@ sub set {
$self->addAlternatives($x, $D{$x}{$id});
$update = 1;
}
if ($id eq 'patternPrecedence') {
delete $self->{tokens}{$x};
$self->addToken($x);
$update = 1;
}
}
} else {
$data->{$x} = $self->create($D{$x});
Expand Down

0 comments on commit 1ed89f8

Please sign in to comment.