Haskell 98 Revised

Ian Lynagh [email protected]
Mon, 5 Nov 2001 17:09:02 +0000


On Mon, Nov 05, 2001 at 06:47:17AM -0800, Simon Peyton-Jones wrote:
> indeed, it's a stream of lexemes that gets passed to L, so 
> there's no whitespace anyway

The report says:

    The input to L is:
        * A stream of tokens as specified by the lexical syntax in the
          Haskell report, with the following additional tokens:

immediately before where I suggested "token" be changed to "lexeme".

I think I prefer this for a descriptive algorithm as it means you can do
things like the figures in section 2.7 (Layout).

> |   L (t:ts) ms       = L ts ms               if t is whitespace

Bah, I *really* meant

      L (t:ts) ms       = t : L ts ms           if t is whitespace

:-)


Also, the line

      L (}:ts) (0:ms)   = } : (L ts ms)

should be

      L (}:ts) (m:ms)   = } : (L ts ms)         if m == 0
                        = error "Implicit block explicitly closed"
                                                otherwise

or the } will get allowed through by

      L (t:ts) ms       = t : (L ts ms)


So my complete suggested function is:

L (t:ts) []       = t : L ts []           if t is whitespace
                  = error "lexeme outside of module contents"
                                          otherwise
L ({n}:ts) (m:ms) = { : (L ts (n:m:ms))   if n > m
                  = { : } : (L ts (m:ms)) otherwise
L (<n>:ts) (m:ms) = ; : (L ts (m:ms))     if m = n 
                  = } : (L (<n>:ts) ms)   if n < m 
                  = L ts (m:ms)           otherwise 
L (t:ts) (m:ms)   = } : (L (t:ts) ms)     if m /= 0 and parse-error(t) 
L (}:ts) (m:ms)   = } : (L ts ms)         if m == 0
                  = error "Implicit block explicitly closed"
                                          otherwise
L ({:ts) ms       = { : (L ts (0:ms))
L (t:ts) ms       = t : (L ts ms)
L [] [0]          = []
L [] (m:ms)       = } : L [] ms           if m /= 0


Thanks
Ian