| 1 |
# Copyright 2022 Jeffrey Kegler |
| 2 |
# This file is part of Marpa::R2. Marpa::R2 is free software: you can |
| 3 |
# redistribute it and/or modify it under the terms of the GNU Lesser |
| 4 |
# General Public License as published by the Free Software Foundation, |
| 5 |
# either version 3 of the License, or (at your option) any later version. |
| 6 |
# |
| 7 |
# Marpa::R2 is distributed in the hope that it will be useful, |
| 8 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 9 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 10 |
# Lesser General Public License for more details. |
| 11 |
# |
| 12 |
# You should have received a copy of the GNU Lesser |
| 13 |
# General Public License along with Marpa::R2. If not, see |
| 14 |
# http://www.gnu.org/licenses/. |
| 15 |
|
| 16 |
=head1 NAME |
| 17 |
|
| 18 |
Marpa::R2::Changes - Differences between Marpa::R2 and Marpa::XS |
| 19 |
|
| 20 |
=head1 About this document |
| 21 |
|
| 22 |
This document describes the incompatible |
| 23 |
differences between Marpa::XS |
| 24 |
and Marpa::R2. |
| 25 |
(Differences that do not give rise to incompatibility |
| 26 |
are outside of its scope.) |
| 27 |
It is intended for readers already familiar with Marpa::XS, |
| 28 |
who are writing new applications for Marpa::R2, |
| 29 |
and for readers migrating Marpa::XS applications |
| 30 |
and tools to Marpa::R2. |
| 31 |
|
| 32 |
=head1 Changes |
| 33 |
|
| 34 |
=head2 Additional reserved symbol names |
| 35 |
|
| 36 |
Marpa::XS reserved, for its internal use, all symbol names |
| 37 |
ending with the right square bracket ("C<]>"). |
| 38 |
In addition, |
| 39 |
Marpa::RS reserved symbols ending |
| 40 |
with the right parenthesis ("C<)>"), |
| 41 |
the right angle bracket ("C<< > >>"), |
| 42 |
and the right curly bracket ("C<}>"). |
| 43 |
Any other valid Perl string remains an acceptable |
| 44 |
symbol name. |
| 45 |
|
| 46 |
=head2 The return value of the read() method has changed |
| 47 |
|
| 48 |
The return value of |
| 49 |
the Marpa::R2 recognizer's C<read()> method differs from its Marpa::XS |
| 50 |
equivalent. |
| 51 |
In Marpa::XS it returned the number of distinct |
| 52 |
terminals (by symbol ID) allowed in the next |
| 53 |
C<read()>. |
| 54 |
In Marpa::R2 it returns the number of recognizer |
| 55 |
events that occurred during the read. |
| 56 |
Examples of recognizer events are exhaustion, |
| 57 |
the Earley sets exceeding a designated "warning" |
| 58 |
level, |
| 59 |
and other circumstances settable by the user. |
| 60 |
For more detail, |
| 61 |
see L<the documentation of recognizer's |
| 62 |
C<read> method|Marpa::R2::Deprecated::NAIF::Recognizer/"read()">. |
| 63 |
|
| 64 |
=head2 Rule LHS's are no longer a source of action names |
| 65 |
|
| 66 |
In Marpa::XS, if there was no explicit action name for a rule, Marpa |
| 67 |
would try to find a closure that had the same name as the rule's |
| 68 |
LHS. The use of rule LHS's as |
| 69 |
action names had a potential for |
| 70 |
unpleasant surprises. |
| 71 |
A surprise could occur if the rule's LHS coincided with |
| 72 |
a function name without the prorgrammer realizing or intending it. |
| 73 |
This kind of 'action at a distance' bug can be very hard to detect |
| 74 |
and trace. |
| 75 |
|
| 76 |
It was originally thought that implicitly using the LHS as the name |
| 77 |
of an action would be convenient enough to outweigh the dangers. |
| 78 |
But in fact, |
| 79 |
this feature wound up being little used. And accidental |
| 80 |
resolution via a rule LHS was a danger for all users, whether they |
| 81 |
used the feature or not. For these reasons, as well as |
| 82 |
potential optimization and efficiency considerations, Marpa::R2 no longer |
| 83 |
does implicit action resolution using a rule LHS. |
| 84 |
|
| 85 |
=head2 Different rules with the same rank now appear in arbitrary order |
| 86 |
|
| 87 |
In ranking parse trees, |
| 88 |
if two rule instances are for different |
| 89 |
rules |
| 90 |
but have the same rule rank, |
| 91 |
they will now appear in arbitrary order. |
| 92 |
This is probably the behavior that programmers |
| 93 |
have always expected. |
| 94 |
|
| 95 |
In Marpa::XS, when the C<null_ranking> named |
| 96 |
argument of rules was in use for one of the rules, |
| 97 |
specific guarantees were made for the order |
| 98 |
in some of the cases. |
| 99 |
The intent was to be orthogonal with the guarantees |
| 100 |
made for the ranking of null variants within the |
| 101 |
same rule. |
| 102 |
These additional guarantees |
| 103 |
proved useless in practice, |
| 104 |
cumbersome to implement, |
| 105 |
and, when documented, opaque and unintuitive. |
| 106 |
In Marpa::R2 they have been dropped. |
| 107 |
|
| 108 |
=head2 Null actions now come from the rules |
| 109 |
|
| 110 |
In Marpa::XS null actions were specified by symbol. |
| 111 |
This created a dual semantics -- one for non-nulled rules, |
| 112 |
and another for nulled rules. The conventions and |
| 113 |
behaviors of the two semantics were quite dissimilar. |
| 114 |
The rules for their coordination were complicated, |
| 115 |
and it was possible for a programmer |
| 116 |
expecting one semantics, to be surprised by a result from |
| 117 |
the other. |
| 118 |
|
| 119 |
In Marpa::R2 the semantics of nulled rules is the same |
| 120 |
as that of non-nulled rules, |
| 121 |
and the semantics of nulled symbols comes from the semantics |
| 122 |
of the nulled rules. |
| 123 |
This requires rule evaluation closures to be aware |
| 124 |
they might be called for nulled rules. |
| 125 |
But it greatly simplifies the semantics conceptually. |
| 126 |
For more detail, see L<Marpa::R2::Deprecated::NAIF::Semantics::Null>. |
| 127 |
|
| 128 |
=head2 Actions can now be constants |
| 129 |
|
| 130 |
If an action name resolves to a constant, that constant is the action. |
| 131 |
The effect is the same as if the action name resolved to a function |
| 132 |
that returned that constant, except that it is more efficient. |
| 133 |
|
| 134 |
Perl cannot reliably distinguish between non-existent symbols and symbols |
| 135 |
whose value is C<undef>, |
| 136 |
so constants whose value is C<undef> are not allowed. |
| 137 |
The C<::undef> reserved action name can be used instead. |
| 138 |
|
| 139 |
=head2 Actions names beginning with "C<::>" are reserved |
| 140 |
|
| 141 |
Action names which start with "C<::>" are reserved. |
| 142 |
"C<::undef>" is a safe way of specify a constant whose |
| 143 |
value is C<undef>. |
| 144 |
Use of a reserved name which has not yet been defined causes |
| 145 |
an exception to be thrown. |
| 146 |
|
| 147 |
=head2 The "default_null_value" named argument for grammars has been removed |
| 148 |
|
| 149 |
Symbols no longer have null values, so the "default_null_value" |
| 150 |
named argument of grammars has been removed. |
| 151 |
|
| 152 |
=head2 The "null_value" symbol property has been removed |
| 153 |
|
| 154 |
Symbols no longer have null values. |
| 155 |
Use of the C<null value> symbol property |
| 156 |
now causes an exception. |
| 157 |
|
| 158 |
=head2 The token value argument of read() has changed |
| 159 |
|
| 160 |
The Marpa::R2 recognizer's C<read()> method differs from its Marpa::XS |
| 161 |
equivalent. |
| 162 |
In Marpa::R2, If C<read()>'s token value argument is |
| 163 |
omitted, then the value of the token will be a Perl C<undef>. |
| 164 |
If C<read()>'s |
| 165 |
token value is given explicitly, then that explicit value will be |
| 166 |
the value of the token. In particular, an explicit C<undef> token |
| 167 |
value argument will behave differently from an omitted token value |
| 168 |
argument. For details, see L<the documentation of recognizer's |
| 169 |
C<read> method|Marpa::R2::Deprecated::NAIF::Recognizer/"read()">. |
| 170 |
|
| 171 |
=head2 The token value argument of C<alternative()> has changed |
| 172 |
|
| 173 |
The Marpa::R2 recognizer's C<alternative()> method differs from its |
| 174 |
Marpa::XS equivalent. Its token value argument must now be a |
| 175 |
reference to the token value, not the token value itself, as in |
| 176 |
Marpa::XS. |
| 177 |
If alternative's token value argument is omitted or a |
| 178 |
Perl C<undef>, |
| 179 |
then the value of the token will be a Perl C<undef>. |
| 180 |
If alternative's |
| 181 |
token value argument is reference to C<undef>, then the value |
| 182 |
of the token is a Perl C<undef>. For details, see L<the documentation |
| 183 |
of the |
| 184 |
C<alternative> method|Marpa::R2::Deprecated::NAIF::Input_Models/"alternative()">. |
| 185 |
|
| 186 |
=head2 Marpa::R2::Recognizer::value() does not accept named arguments |
| 187 |
|
| 188 |
In the Marpa::XS recognizer, the C<new()>, C<set()> and value() methods |
| 189 |
all accepted named arguments. As of Marpa::R2, the C<value()> method |
| 190 |
will no longer do so. |
| 191 |
|
| 192 |
Allowing named arguments for the C<value()> was a holdover from a |
| 193 |
previous interface, which also seemed like it might be a convenience. |
| 194 |
But, since it was even more important that the C<value()> method be |
| 195 |
convenient as the termination test controlling a loop over the parse |
| 196 |
results, a lot of special logic was added to deal with arguments |
| 197 |
which only made sense before the first pass of the loop, etc., etc. |
| 198 |
|
| 199 |
Eliminating named arguments from the C<value()> method eliminates a |
| 200 |
variety of special cases and, as a result, the documentation of the |
| 201 |
C<value()> method is now simpler, shorter and clearer. Anything that |
| 202 |
could be done by providing named arguments to the C<value()> method |
| 203 |
can be done more using the recognizer's C<set()> method, and the code |
| 204 |
will be clearer for it. |
| 205 |
|
| 206 |
=head2 Marpa's grammar rewriting is now invisible |
| 207 |
|
| 208 |
Internally, Marpa rewrites its grammars. |
| 209 |
In Marpa::XS, most details of these rewrites were |
| 210 |
invisible, but not all. |
| 211 |
In Marpa::R2, all internal rules and symbols |
| 212 |
are now completely |
| 213 |
invisible to the user, |
| 214 |
even in the tools for debugging grammars. |
| 215 |
|
| 216 |
=head2 By default, the non-LHS symbols are the terminals |
| 217 |
|
| 218 |
Traditionally, a symbol has been a terminal if |
| 219 |
it is not on the LHS of any rule, and vice versa. |
| 220 |
This is now the default in Marpa::R2, |
| 221 |
replacing the more complicated, and less intuitive, |
| 222 |
scheme that was in Marpa::XS. |
| 223 |
Marpa::R2 still allows the user to |
| 224 |
use any non-nulling symbol as a terminal, |
| 225 |
including those symbols that appear on the LHS |
| 226 |
of a rule, |
| 227 |
but this is now an option, |
| 228 |
and never the default. |
| 229 |
For more, see |
| 230 |
L<Marpa::R2::Deprecated::NAIF::Grammar/"Terminal symbols">. |
| 231 |
|
| 232 |
=head2 The lhs_terminals grammar named argument has been eliminated |
| 233 |
|
| 234 |
The lhs_terminals named argument of grammar objects implemented |
| 235 |
what is now the default behavior. |
| 236 |
Since it no longer performs a function, |
| 237 |
its use is now a fatal error. |
| 238 |
|
| 239 |
=head2 Nulling symbols cannot be terminals |
| 240 |
|
| 241 |
In Marpa::XS, it was possible for a symbol to be both |
| 242 |
nulling and a terminal. |
| 243 |
In practice |
| 244 |
that meant |
| 245 |
that the symbol was nulling, |
| 246 |
but that, on input, |
| 247 |
that property could be overriden, |
| 248 |
and a specific instance of the nulling symbol |
| 249 |
could be made non-nulling. |
| 250 |
This behavior was worse than useless and non-intuitive -- |
| 251 |
it was dangerous and logically inconsistent. |
| 252 |
|
| 253 |
Marpa::R2 will not allow |
| 254 |
a nulling symbol to be used as a terminal. |
| 255 |
To the extent that the Marpa::XS behavior made sense, |
| 256 |
it can be duplicated by creating a symbol which |
| 257 |
is the LHS of two rules, one empty, |
| 258 |
and the other rule with a RHS consisting of exactly one |
| 259 |
terminal symbol. |
| 260 |
|
| 261 |
=head2 A sequence must have a unique LHS |
| 262 |
|
| 263 |
The LHS of a sequence rule |
| 264 |
may not be on the LHS of any other |
| 265 |
rule, whether another sequence rule, or a BNF rule. |
| 266 |
This |
| 267 |
is not as severe a restriction as it might sound -- |
| 268 |
while sequences cannot share the same LHS with other |
| 269 |
rules directly, they can do so indirectly. |
| 270 |
For details, see |
| 271 |
L<Marpa::R2::Deprecated::NAIF::Grammar/"Duplicate rules">. |
| 272 |
|
| 273 |
In Marpa::XS, the definition of when a sequence |
| 274 |
was a duplicate was more liberal, |
| 275 |
but it was also complicated and non-intuitive. |
| 276 |
The new definition is simpler and more |
| 277 |
intuitive, and its greater restrictiveness |
| 278 |
is easy to work around. |
| 279 |
|
| 280 |
=head2 The terminal status of a symbol is locked once set |
| 281 |
|
| 282 |
Once a symbol is marked as a terminal or a non-terminal, |
| 283 |
its terminal status cannot be changed. |
| 284 |
We doubt this will affect any actual applications. |
| 285 |
It would only affect an application |
| 286 |
that changes symbols from their default status |
| 287 |
to non-terminal, |
| 288 |
and then only if they attempted to mark the same symbol |
| 289 |
as a terminal at another point. |
| 290 |
Few Marpa::R2 applications change symbols from |
| 291 |
their default terminal status, |
| 292 |
and none to my knowledge mark symbols as non-terminals. |
| 293 |
|
| 294 |
=head2 Evaluation of infinite loops has been changed |
| 295 |
|
| 296 |
Infinite loops (cycles) are still, by default, fatal errors. |
| 297 |
For those considering programming with them, |
| 298 |
and evaluating parses from grammars with cycles, |
| 299 |
the semantics of cycles is now more closely specified. |
| 300 |
For details of the new semantics, |
| 301 |
see L<Marpa::R2::Deprecated::NAIF::Semantics::Infinite>. |
| 302 |
|
| 303 |
=head2 The range of values allowed for ranks has been clarified |
| 304 |
|
| 305 |
Symbols and rules have numeric ranks. |
| 306 |
Previously, no mention was made of range of values allowed. |
| 307 |
This is implemented-defined, |
| 308 |
except that the magnitudes |
| 309 |
of the ends of the range |
| 310 |
will always be |
| 311 |
at least |
| 312 |
the 28th power of 2, less 1. |
| 313 |
That is, |
| 314 |
numbers in the range between |
| 315 |
-134,217,727 and 134,217,727 will always be |
| 316 |
allowed as ranks. |
| 317 |
|
| 318 |
=head1 Copyright and License |
| 319 |
|
| 320 |
=for Marpa::R2::Display |
| 321 |
ignore: 1 |
| 322 |
|
| 323 |
Copyright 2022 Jeffrey Kegler |
| 324 |
This file is part of Marpa::R2. Marpa::R2 is free software: you can |
| 325 |
redistribute it and/or modify it under the terms of the GNU Lesser |
| 326 |
General Public License as published by the Free Software Foundation, |
| 327 |
either version 3 of the License, or (at your option) any later version. |
| 328 |
|
| 329 |
Marpa::R2 is distributed in the hope that it will be useful, |
| 330 |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 331 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 332 |
Lesser General Public License for more details. |
| 333 |
|
| 334 |
You should have received a copy of the GNU Lesser |
| 335 |
General Public License along with Marpa::R2. If not, see |
| 336 |
http://www.gnu.org/licenses/. |
| 337 |
|
| 338 |
=for Marpa::R2::Display::End |
| 339 |
|
| 340 |
=cut |
| 341 |
|