Changeset 6673

Show
Ignore:
Timestamp:
09/03/05 21:49:59 (3 years ago)
Author:
luqui
Message:

r552@feather: fibonaci | 2005-09-03 21:49:38 +0200
The erroneous "sub <foo>" no longer parses. Sub parameters may now be operators,
eg. "sub foo(&infix:<+>) {...}".

Files:
2 modified

Legend:

Unmodified
Added
Removed
  • src/Pugs/Parser.hs

    r6656 r6673  
    453453ruleSubName = verbatimRule "subroutine name" $ do 
    454454    twigil  <- ruleTwigil 
    455     fixity  <- option "" $ choice (map (try . string) $ fixities) 
    456     name    <- ruleQualifiedIdentifier 
    457                 <|> try (between (string "<<") (string ">>") 
    458                     (many1 (satisfy (/= '>') <|> lookAhead (satisfy (/= '>'))))) 
    459                 <|> between (char '<') (char '>') (many1 $ satisfy (/= '>')) 
    460                 <|> between (char '\171') (char '\187') (many1 $ satisfy (/= '\187')) 
    461     return $ "&" ++ twigil ++ fixity ++ name 
     455    name    <- ruleOperatorName <|> ruleQualifiedIdentifier 
     456    return $ "&" ++ twigil ++ name 
     457 
     458ruleOperatorName :: RuleParser String 
     459ruleOperatorName = do 
     460    fixity <- choice (map (try . string) fixities) 
     461    name <- try (between (string "<<") (string ">>") 
     462              (many1 (satisfy (/= '>') <|> lookAhead (satisfy (/= '>'))))) 
     463            <|> between (char '<') (char '>') (many1 $ satisfy (/= '>')) 
     464            <|> between (char '\171') (char '\187') (many1 $ satisfy (/= '\187')) 
     465    return $ fixity ++ name 
    462466    where 
    463467    fixities = words " prefix: postfix: infix: circumfix: coerce: self: term: postcircumfix: rule_modifier: trait_verb: trait_auxiliary: scope_declarator: statement_control: infix_postfix_meta_operator: postfix_prefix_meta_operator: prefix_postfix_meta_operator: infix_circumfix_meta_operator: " 
     468     
    464469 
    465470ruleSubParameters :: ParensOption -> RuleParser (Maybe [Param]) 
     
    17331738    -- Valid param names: $foo, @bar, &baz, %grtz, ::baka 
    17341739    sigil   <- choice [ oneOf "$@%&" >>= return . (:""), string "::" ] 
    1735     twigil  <- ruleTwigil 
    1736     name    <- many1 wordAny 
    1737     return $ sigil ++ twigil ++ name 
     1740    if sigil == "&" 
     1741        then ruleSubName 
     1742        else do twigil <- ruleTwigil 
     1743                name   <- many1 wordAny 
     1744                return $ sigil ++ twigil ++ name 
    17381745 
    17391746ruleVarName :: RuleParser String 
  • t/subroutines/lexical_subs.t

    r6654 r6673  
    44use Test; 
    55 
    6 plan 3; 
     6plan 5; 
    77 
    88sub f() {  
     
    2121is(callit({ $^x + 2 }), 3, "lexical subs get precedence over package subs"); 
    2222 
     23sub infix:<@@> ($x, $y) { $x + $y } 
    2324 
     25sub foo2(&infix:<@@>) { 
     26    2 @@ 3; 
     27} 
     28 
     29is(2 @@ 3, 5); 
     30is(foo2({ $^x * $^y }), 6); 
    2431 
    2532# vim: ft=perl6 :