Hi Volker

you wrote:

At 12:41 PM 4/6/00 +0200, you wrote:
>>> parse "LIB1 "  ["LIB1"]
>== false
>>> parse "LIB1 "  ["LIB1" to end]
>== true
>>> parse "LI B1 "  ["LIB1" to end]
>== false                                       
>
>result says, could parse full string, or there is a rest, IMO.

that is correct and undisputed. According to the documentation parse
ignores spaces unless used with the /all refinement.

In the example

(1)
>> parse " LIB1"  ["LIB1"]
== true

I demonstrate that parse w/o /all refinement indeed *ignores* spaces, at
least leading spaces.

The example

(2) 
>> parse "LIB1 "  ["LIB1" (print "found it")]
found it
== true

demonstrates that parse w/o /all also ignores *trailing* spaces. 

If we leave away the expression (print "found it") and simply do

(3)
>> parse "LIB1 "  ["LIB1"]
== false

the trailing space is *not* ignored. Why all of a sudden is the trailing
space not ignored? Should it be ignored?

My position is: In example (3) the trailing space should be ignored,
because the pattern matching part of the rule in (3) is no different from
the pattern matching part of the rule in (2). Since we are doing the same
pattern matching against the same input stream we should be getting the
same results. 

Should (2) return the same results as (3), or should (3) behave like (2)?
Since we are using parse without the /all refinement, and parse ignores
spaces without the /all refinement, the trailing space should be ignored in
(3) as it is being ignored in (2) and the string should be considered
completely parsed.

My guess is that (3) does not act like (2) because the termination code for
parse is incomplete in situation (3). How do (2) and (3) differ? In (2) the
rule block is *not* exhausted with the "LIB1" pattern. In (3) it is.

When parse encounters the trailing space, it still has something remaining
in the rule block, namely (print "found it"). This means that empty?
rule-block at this point will return false. Since there's still something
remaining in the rule block, parse continues to evaluate the rule-block. In
doing so, it returns to a part of the parse code that is ignore-spaces-aware.

In (3) the rule block is exhausted with the "LIB1" pattern. empty?
rule-block returns true and parse returns false because it has not reached
the end of the input stream, but it has already exhausted its rules. That
is an incorrect termination, since we are using parse without the /all
refinement, and parse should determine whether or not all remaining
characters in the input stream are spaces, before it decides whether to
return true or false. If only spaces remain, - and in our example that is
the case - parse should report true, just as it did in (2).


;- Elan >> [: - )]

Reply via email to