Changeset 8724

Show
Ignore:
Timestamp:
01/17/06 12:55:27 (3 years ago)
Author:
audreyt
Message:

* implemented \x[1,2,3,].

Files:
3 modified

Legend:

Unmodified
Added
Removed
  • src/Pugs/Lexer.hs

    r8722 r8724  
    2222    rule, verbatimRule, literalRule, 
    2323    tryRule, tryVerbatimRule, 
    24     tryChoice, 
     24    tryChoice, ruleComma, 
    2525 
    2626    ruleScope, ruleTrait, ruleTraitName, ruleBareTrait, ruleType, 
     
    6161maybeParens :: CharParser st a -> CharParser st a 
    6262maybeParens p = choice [ parens p, p ] 
    63  
    64 maybeVerbatimBrackets :: CharParser st a -> CharParser st a 
    65 maybeVerbatimBrackets p = choice [ verbatimBrackets p, p ] 
    6663 
    6764parens     :: CharParser st a -> CharParser st a 
     
    197194 
    198195-- | Backslashed non-alphanumerics (except for @\^@) translate into themselves. 
    199 escapeCode      :: GenParser Char st Char 
    200 escapeCode      = charEsc <|> charNum <|> charAscii <|> charControl <|> anyChar 
     196escapeCode      :: GenParser Char st String 
     197escapeCode      = ch charEsc <|> charNum <|> ch charAscii <|> ch charControl <|> ch anyChar 
    201198                <?> "escape code" 
     199    where 
     200    ch = fmap (:[]) 
    202201 
    203202charControl :: GenParser Char st Char 
     
    207206                    } 
    208207 
    209 charNum :: GenParser Char st Char                     
     208-- This is currently the only escape that can return multiples. 
     209charNum :: GenParser Char st String 
    210210charNum = do 
    211     code <- choice 
    212         [ decimal  
     211    codes <- choice 
     212        [ fmap (:[]) decimal  
    213213        , based 'o'  8 octDigit 
    214214        , based 'x' 16 hexDigit 
    215215        , based 'd' 10 digit 
    216216        ] 
    217     return . toEnum $ fromInteger code 
     217    return $ map (toEnum . fromInteger) codes 
    218218    where 
    219219    based ch num p = do 
    220220        char ch 
    221         maybeVerbatimBrackets (number num p) 
     221        choice [ verbatimBrackets (number num p `sepEndBy1` ruleComma) 
     222               , fmap (:[]) (number num p) 
     223               ] 
     224 
     225ruleComma :: GenParser Char st () 
     226ruleComma = do 
     227    lexeme (char ',') 
     228    return () 
    222229 
    223230number :: Integer -> GenParser tok st Char -> GenParser tok st Integer 
  • src/Pugs/Parser.hs

    r8717 r8724  
    20612061        return (x:a, ruleComma) 
    20622062         
    2063 ruleComma :: RuleParser () 
    2064 ruleComma = do 
    2065     lexeme (char ',') 
    2066     return () 
    2067  
    20682063ruleCommaOrSemicolon :: RuleParser () 
    20692064ruleCommaOrSemicolon = do 
     
    22862281    char '\\' 
    22872282    nextchar <- escapeCode -- see Lexer.hs 
    2288     return (Val $ VStr [nextchar]) 
     2283    return (Val $ VStr nextchar) 
    22892284 
    22902285qInterpolateDelimiter :: Char -> RuleParser Exp 
  • t/syntax/interpolation/strings.t

    r7978 r8724  
    1212=cut 
    1313 
    14 plan 32; 
     14plan 30; 
    1515 
    1616my $world = "World"; 
     
    6868is("x  \d[65,66,000067]  x", "x  ABC  x",  "\\d[] allows multiple chars (2)"); 
    6969 
    70 is("x  \x[41,42,43]]  x",    "x  ABC]  x", "\\d[] should not eat following ]s"); 
    71 is("x  \d[65,66,67]]  x",    "x  ABC]  x", "\\x[] should not eat following ]s"); 
     70is("x  \x[41,42,43]]  x",    "x  ABC]  x", "\\x[] should not eat following ]s"); 
     71is("x  \d[65,66,67]]  x",    "x  ABC]  x", "\\d[] should not eat following ]s");