I'm extending Coral to support Gnu Smalltalk syntax, and ran into
something strange.

I asked Lukas and he said that since others would be interested, I
should repost the question here. So:

Gnu Smalltalk's class variable declarations take the form of
[<identifier> := <expression>.]* at the end of an object definition.
To that end I wrote a #classVars production like so:

  classVars
      ^ (assignment , expression , $. asParser) star
      "Possibly I need to support the lack of a dot on the last
expression. Not relevant at the moment"

This didn't work as expected. Looking further, I found this oddity:

  p := PPSmalltalkParser new.
  p number end parse: '1.' "=> #(#(nil #($1) nil) 1.0)"

I would expect this to fail, because "1." isn't a number (but see below).

Indeed, ripping out the parser of #number:

  n := ($- asParser optional , #digit asParser plus , ($. asParser ,
#digit asParser plus) optional) end.
  n parse: '1.' "=> end of input expected at 1"

So I experimented a bit, and it seems like#number is being overly
eager in consuming that $. character, and Number >> #readFrom:'s
reading '1.':

  Number readFrom: '1.' readStream "=> 1.0"

  p := PPSmalltalkParser new.
  p number end parse: '1' "=> #(#(nil #($1) nil) 1)"

  p := PPSmalltalkParser new.
  p number end parse: '1.0' "=> #(#(nil #($1) #($. #($0))) 1.0)"

  p := PPSmalltalkParser new.
  p number end parse: '1. ' "=> end of input expected at 2"

Or am I being silly?

frank

Reply via email to