Changeset 12430 for src/Pugs/Lexer.hs

Show
Ignore:
Timestamp:
08/18/06 22:21:52 (2 years ago)
Author:
audreyt
Message:

* Pugs.Lexer: Another 5% in parsetime shaved by sharing

as much code as possible betwen Pugs.Lexer.symbol's two
branches, and delay evaluation until the match actually
happened (so the result will be on the heap and closer to us.)

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • src/Pugs/Lexer.hs

    r12317 r12430  
    197197 
    198198symbol :: String -> RuleParser String 
    199 symbol s 
    200     | isWordAny (last s) = try $ do 
    201         rv <- string s 
    202         choice [ eof >> return ' ', lookAhead (satisfy (aheadWord $ last s)) ] 
    203         whiteSpace 
    204         return rv 
    205     | otherwise          = try $ do 
    206         rv <- string s 
    207         -- XXX Wrong - the correct solution is to lookahead as much as possible 
    208         -- in the expression parser below 
    209         choice [ eof >> return ' ', lookAhead (satisfy (aheadSym $ last s)) ] 
    210         whiteSpace 
    211         return rv 
     199symbol s = try $ do 
     200    rv <- string s 
     201    let ahead  = if isWordAny lastCh then aheadWord else aheadSym 
     202        lastCh = last rv 
     203    choice [ lookAhead (satisfy (ahead lastCh)), eof >> return ' ' ] 
     204    whiteSpace 
     205    return rv 
    212206    where 
    213207    aheadWord x  '=' = not $ x `elem` "xY\xA5" -- ¥