Changeset 6392

Show
Ignore:
Timestamp:
08/21/05 12:05:16 (3 years ago)
Author:
scook0
svk:copy_cache_prev:
8581
Message:

* Merge some more parser redundancy
* Oops, ruleDelimitedIdentifier shouldn't use lexeme identifiers
* ruleDelimitedIdentifier now matches leading delimiters

Location:
src/Pugs
Files:
2 modified

Legend:

Unmodified
Added
Removed
  • src/Pugs/Lexer.hs

    r6359 r6392  
    1616    braces, brackets, angles, balanced, balancedDelim, decimal, 
    1717 
    18     ruleQualifiedIdentifier, ruleWhiteSpaceLine, 
     18    ruleDelimitedIdentifier, ruleQualifiedIdentifier, ruleWhiteSpaceLine, 
    1919 
    2020    symbol, interpolatingStringLiteral, escapeCode, 
     
    8383decimal    = P.decimal    perl6Lexer 
    8484 
     85{-| 
     86Match one or more identifiers, separated internally by the given delimiter 
     87(with an optional leading delimiter). 
     88 
     89Returns a list of the identifiers matched, discarding the delimiters.  You 
     90can always recreate them using \"@concat $ intersperse delim@\" if you want, 
     91or else use 'ruleQualifiedIdentifier'. 
     92-} 
     93ruleDelimitedIdentifier :: String -- ^ Delimiter (e.g. \'@::@\') 
     94                        -> GenParser Char st [String] 
     95ruleDelimitedIdentifier delim = verbatimRule "delimited identifier" $ do 
     96    option "" (try $ string delim) -- leading delimiter 
     97    ruleVerbatimIdentifier `sepBy1` (try $ string delim) 
     98 
    8599ruleQualifiedIdentifier :: GenParser Char st String 
    86100ruleQualifiedIdentifier = verbatimRule "qualified identifier" $ do 
    87     chunks  <- ruleVerbatimIdentifier `sepBy1` (try $ string "::") 
     101    chunks <- ruleDelimitedIdentifier "::" 
    88102    return $ concat (intersperse "::" chunks) 
    89103 
  • src/Pugs/Parser.hs

    r6390 r6392  
    545545    scope       <- ruleScope 
    546546    typename    <- choice 
    547         [ do { name <- ruleQualifiedIdentifier ; whiteSpace ; return name } 
     547        [ lexeme ruleQualifiedIdentifier 
    548548        , return "" 
    549549        ]  -- Type 
     
    661661         
    662662{-| 
    663 Match one or more identifiers, separated internally by the given delimiter. 
    664  
    665 Returns a list of the identifiers matched, discarding the delimiters.  You 
    666 can always recreate them using \"@concat $ intersperse delim@\" if you want. 
    667  
    668 If you want to match leading or trailing delimiters, you'll have to do that 
    669 yourself. 
    670 -} 
    671 ruleDelimitedIdentifier :: String -- ^ Delimiter (e.g. \'@::@\') 
    672                         -> RuleParser [String] 
    673 ruleDelimitedIdentifier delim =  
    674     (<?> "delimited identifier") $ identifier `sepBy1` (try $ string delim) 
    675  
    676 {-| 
    677663Match the package-name and import-list part of a (non-JSAN) @use@ or @no@ 
    678664declaration, then perform the actual import. 
     
    753739ruleAuthorPart = do -- author - XXX 
    754740    char '-' 
     741    -- this will break if you specify an author AND an imports list 
    755742    str <- many1 (satisfy (/= ';')) 
    756743    return ('-':str) 
     
    776763ruleRequireDeclaration = tryRule "require declaration" $ do 
    777764    symbol "require" 
    778     names <- identifier `sepBy1` (try $ string "::") 
    779     _ <- option "" $ do -- version - XXX 
    780         char '-' 
    781         many1 (choice [ digit, char '.' ]) 
     765    names <- ruleDelimitedIdentifier "::" 
     766    _     <- option "" $ ruleVersionPart 
     767    _     <- option "" $ ruleAuthorPart 
    782768    return $ App (Var "&require") Nothing [Val . VStr $ concat (intersperse "/" names) ++ ".pm"] 
    783769 
     
    16551641    twigil  <- ruleTwigil 
    16561642    -- doesn't handle names /beginning/ with "::" 
    1657     names   <- ruleDelimitedIdentifier "::" 
    1658     return $ (sigil:twigil) ++ concat (intersperse "::" names) 
     1643    name    <- ruleQualifiedIdentifier 
     1644    return $ (sigil:twigil) ++ name 
    16591645 
    16601646ruleTwigil :: RuleParser String