Permalink
Browse files

Changing null value logic: t+

  • Loading branch information...
1 parent c0a13be commit 75b0db2a63d1c3bd3406a1b4d5701030f789ec9b Jeffrey Kegler committed May 22, 2012
Showing with 34 additions and 113 deletions.
  1. +10 −49 r2/lib/Marpa/R2/Grammar.pm
  2. +2 −2 r2/lib/Marpa/R2/Value.pm
  3. +4 −46 r2/pod/Grammar.pod
  4. +16 −14 r2/pod/Semantics/Null.pod
  5. +1 −1 r2/t/null_infinite1.t
  6. +1 −1 r2/t/null_infinite4.t
View
@@ -54,8 +54,7 @@ BEGIN {
:package=Marpa::R2::Internal::Symbol
ID { Unique ID }
NAME
- LHS_RANK
- TERMINAL_RANK
+ RANK
END_OF_STRUCTURE
Marpa::R2::offset($structure);
} ## end BEGIN
@@ -309,7 +308,7 @@ sub Marpa::R2::Grammar::set {
if ( defined( my $value = $args->{'default_rank'} ) ) {
Marpa::R2::exception(
- 'terminals option not allowed after grammar is precomputed')
+ 'default_rank option not allowed after grammar is precomputed')
if $grammar_c->is_precomputed();
$grammar->[Marpa::R2::Internal::Grammar::DEFAULT_RANK] = $value;
} ## end if ( defined( my $value = $args->{'default_rank'} ) )
@@ -318,6 +317,8 @@ sub Marpa::R2::Grammar::set {
if ( defined( my $value = $args->{'symbols'} ) ) {
Marpa::R2::exception(
+ 'The symbols option is not currently implemented');
+ Marpa::R2::exception(
'symbols option not allowed after grammar is precomputed')
if $grammar_c->is_precomputed();
Marpa::R2::exception('symbols value must be REF to HASH')
@@ -590,7 +591,7 @@ sub Marpa::R2::Grammar::precompute {
# LHS_RANK is left undefined if not explicitly set
SYMBOL: for my $symbol ( @{$symbols} ) {
- $symbol->[Marpa::R2::Internal::Symbol::TERMINAL_RANK] //=
+ $symbol->[Marpa::R2::Internal::Symbol::RANK] //=
$default_rank;
}
@@ -648,26 +649,6 @@ sub Marpa::R2::Grammar::precompute {
} ## end for my $symbol ( @{ Marpa::R2::Grammar::unproductive_symbols...})
} ## end if ( $grammar->[Marpa::R2::Internal::Grammar::WARNINGS...])
- RULE: for my $rule_id ( 0 .. $grammar_c->rule_count() - 1 ) {
- my $rule = $rules->[$rule_id];
- $rule->[Marpa::R2::Internal::Rule::RANK] //= $default_rank;
- my $rule_rank = $rule->[Marpa::R2::Internal::Rule::RANK];
- my $lhs_id = $grammar_c->rule_lhs($rule_id);
- my $lhs = $symbols->[$lhs_id];
- my $lhs_rank = $lhs->[Marpa::R2::Internal::Symbol::LHS_RANK];
- if ( defined $lhs_rank
- and $lhs_rank == $rule->[Marpa::R2::Internal::Rule::RANK] )
- {
- Marpa::R2::exception(
- 'Rank mismatch in rule: ',
- brief_rule($rule),
- "\n",
- "LHS rank is $lhs_rank; rule rank is ",
- $rule->[Marpa::R2::Internal::Rule::RANK]
- );
- } ## end if ( defined $lhs_rank and $lhs_rank == $rule->[...])
- } ## end for my $rule_id ( 0 .. $grammar_c->rule_count() - 1 )
-
return $grammar;
} ## end sub Marpa::R2::Grammar::precompute
@@ -934,39 +915,19 @@ sub assign_user_symbol {
my $symbol = assign_symbol( $grammar, $name );
my $symbol_id = $symbol->[Marpa::R2::Internal::Symbol::ID];
- # Do RANK first, so that the other options override it
- my $rank = $options->{rank};
- if ( defined $rank ) {
- Marpa::R2::exception(qq{Symbol "$name": rank must be an integer})
- if not Scalar::Util::looks_like_number($rank)
- or not int($rank) != $rank;
- $symbol->[Marpa::R2::Internal::Symbol::LHS_RANK] =
- $symbol->[Marpa::R2::Internal::Symbol::TERMINAL_RANK] = $rank;
- } ## end if ( defined $rank )
-
PROPERTY: while ( my ( $property, $value ) = each %{$options} ) {
- if (not $property ~~
- [qw(terminal rank lhs_rank terminal_rank )] )
- {
+ if ( not $property ~~ [qw(terminal rank )] ) {
Marpa::R2::exception(qq{Unknown symbol property "$property"});
}
if ( $property eq 'terminal' ) {
$grammar_c->symbol_is_terminal_set( $symbol_id, $value );
}
- if ( $property eq 'terminal_rank' ) {
- Marpa::R2::exception(
- qq{Symbol "$name": terminal_rank must be an integer})
- if not Scalar::Util::looks_like_number($value)
- or int($value) != $value;
- $symbol->[Marpa::R2::Internal::Symbol::TERMINAL_RANK] = $value;
- } ## end if ( $property eq 'terminal_rank' )
- if ( $property eq 'lhs_rank' ) {
- Marpa::R2::exception(
- qq{Symbol "$name": lhs_rank must be an integer})
+ if ( $property eq 'rank' ) {
+ Marpa::R2::exception(qq{Symbol "$name": rank must be an integer})
if not Scalar::Util::looks_like_number($value)
or int($value) != $value;
- $symbol->[Marpa::R2::Internal::Symbol::LHS_RANK] = $value;
- } ## end if ( $property eq 'lhs_rank' )
+ $symbol->[Marpa::R2::Internal::Symbol::RANK] = $value;
+ } ## end if ( $property eq 'rank' )
} ## end while ( my ( $property, $value ) = each %{$options} )
return $symbol;
View
@@ -1029,7 +1029,7 @@ sub do_high_rule_only {
# Set up ranks by symbol
my @rank_by_symbol = ();
SYMBOL: for my $symbol ( @{$symbols} ) {
- my $rank = $symbol->[Marpa::R2::Internal::Symbol::TERMINAL_RANK];
+ my $rank = $symbol->[Marpa::R2::Internal::Symbol::RANK];
$rank_by_symbol[ $symbol->[Marpa::R2::Internal::Symbol::ID] ] = $rank;
} # end for my $symbol ( @{$symbols} )
@@ -1098,7 +1098,7 @@ sub do_rank_by_rule {
# Set up ranks by symbol
my @rank_by_symbol = ();
SYMBOL: for my $symbol ( @{$symbols} ) {
- my $rank = $symbol->[Marpa::R2::Internal::Symbol::TERMINAL_RANK];
+ my $rank = $symbol->[Marpa::R2::Internal::Symbol::RANK];
$rank_by_symbol[ $symbol->[Marpa::R2::Internal::Symbol::ID] ] = $rank;
} # end for my $symbol ( @{$symbols} )
View
@@ -428,12 +428,11 @@ for rules without an L<C<action> property|/"action">.
Details are given in
L<the document on semantics|Marpa::R2::Semantics>.
-=head2 default_null_value
+=head2 default_empty_action
-The C<default_null_value> named argument specifies
-the null value for
-symbols
-without a L<C<null_value> property|/"null_value">.
+The C<default_empty_action> named argument specifies
+the action for empty (zero length) rules
+which have no action specified explicitly.
Details are given in
L<the document on semantics|Marpa::R2::Semantics>.
@@ -801,47 +800,6 @@ whose RHS is the sequence LHS symbol.
The LHS of the intermediate rule can then be used,
without restriction, as the LHS of other rules.
-=head1 SYMBOL DESCRIPTORS
-
-=for Marpa::R2::Display
-name: Null Value Example
-partial: 1
-normalize-whitespace: 1
-
- symbols => {
- L => { null_value => 'null L' },
- R => { null_value => 'null R' },
- A => { null_value => 'null A' },
- B => { null_value => 'null B' },
- X => { null_value => 'null X' },
- Y => { null_value => 'null Y' },
- },
-
-=for Marpa::R2::Display::End
-
-A symbol descriptor is a hash.
-In the key/value pairs of this hash,
-the hash key is the symbol property name
-and the hash value is the value of
-that property.
-The available symbol properties are as follows:
-
-=head2 null_value
-
-The C<null_value> symbol property specifies
-the null value of its symbol.
-Details are given in
-L<the document on semantics|Marpa::R2::Semantics>.
-
-=head2 terminal
-
-A boolean.
-If true, it allows the symbol to be used as a terminal.
-If false, it disallows use of
-the symbol as a terminal.
-For details, see
-L<the section on terminals|/"Terminal Symbols">.
-
=head1 COPYRIGHT AND LICENSE
=for Marpa::R2::Display
View
@@ -155,30 +155,32 @@ perltidy: '-dcsc -sil=0'
return 'S(' . ( join q{;}, map { $_ // '[ERROR!]' } @_ ) . ')';
}
+ sub X { return $_[1]; }
+ sub Y { return $_[1]; }
+
+ our $null_A = 'null A';
+ our $null_B = 'null B';
+ our $null_L = 'null L';
+ our $null_R = 'null R';
+ our $null_X = 'null X';
+ our $null_Y = 'null Y';
+
my $grammar = Marpa::R2::Grammar->new(
{ start => 'S',
actions => 'main',
rules => [
[ 'S', [qw/L R/] ],
[ 'L', [qw/A B X/] ],
- [ 'L', [] ],
+ [ 'L', [], 'null_L' ],
[ 'R', [qw/A B Y/] ],
- [ 'R', [] ],
- [ 'A', [] ],
- [ 'B', [] ],
- [ 'X', [] ],
+ [ 'R', [], 'null_R' ],
+ [ 'A', [], 'null_A' ],
+ [ 'B', [], 'null_B' ],
+ [ 'X', [], 'null_X' ],
[ 'X', [qw/x/] ],
- [ 'Y', [] ],
+ [ 'Y', [], 'null_Y' ],
[ 'Y', [qw/y/] ],
],
- symbols => {
- L => { null_value => 'null L' },
- R => { null_value => 'null R' },
- A => { null_value => 'null A' },
- B => { null_value => 'null B' },
- X => { null_value => 'null X' },
- Y => { null_value => 'null Y' },
- },
}
);
View
@@ -63,7 +63,7 @@ my $grammar = Marpa::R2::Grammar->new(
{ lhs => 'f', rhs => [] },
{ lhs => 'f', rhs => ['S'], action => 'main::rule_f' },
],
- symbols => { a => { terminal => 1 }, },
+ terminals => [qw(a)],
default_action => 'main::default_action',
}
);
View
@@ -60,7 +60,7 @@ my $grammar = Marpa::R2::Grammar->new(
{ lhs => 'f', rhs => [], action => 'main::dash' },
{ lhs => 'f', rhs => ['S'], action => 'main::rule_f' },
],
- symbols => { a => { terminal => 1 }, },
+ terminals => [qw(a)],
}
);

0 comments on commit 75b0db2

Please sign in to comment.