Changeset 32 for src/Parser.hs
- Timestamp:
- 02/16/05 18:48:28 (4 years ago)
- svk:copy_cache_prev:
- 1041
- Files:
-
- 1 modified
-
src/Parser.hs (modified) (10 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/Parser.hs
r31 r32 13 13 import Internals 14 14 import AST 15 import Help 15 16 import Lexer 16 17 … … 56 57 , rulePackageDeclaration 57 58 , ruleVarDeclaration 59 , ruleUseDeclaration 58 60 ] 59 61 … … 87 89 , ruleSubGlobal 88 90 ] 89 pos <- getPosition90 91 cxt2 <- option cxt1 $ ruleBareTrait "returns" 91 92 formal <- option Nothing $ return . Just =<< parens ruleSubParameters … … 148 149 scope <- ruleScope 149 150 name <- parseVarName 150 return $ Syn "sym" [Sym (Symbol scope name (Val VUndef))] 151 exp <- option (Val VUndef) $ do 152 tryChoice $ map symbol $ words " = := ::= " 153 ruleExpression 154 return $ Syn "sym" [Sym $ Symbol scope name exp] 155 156 ruleUseDeclaration :: RuleParser Exp 157 ruleUseDeclaration = rule "use declaration" $ do 158 symbol "use" 159 option ' ' $ char 'v' 160 version <- many1 (choice [ digit, char '.' ]) 161 when (version > versnum) $ do 162 pos <- getPosition 163 error $ "Perl v" ++ version ++ " required--this is only v" ++ versnum ++ ", stopped at " ++ (show pos) 164 return $ Val VUndef 151 165 152 166 rulePackageDeclaration = rule "package declaration" $ fail "" … … 156 170 ruleConstruct = rule "construct" $ tryChoice 157 171 [ ruleGatherConstruct 158 , ruleBlockConstruct159 172 ] 160 173 … … 163 176 block <- ruleBlock 164 177 retSyn "gather" [block] 165 166 ruleBlockConstruct = rule "block construct" $ do167 formal <- option Nothing $ choice [ ruleBlockFormalStandard, ruleBlockFormalPointy ]168 block <- ruleBlock169 fail ""170 171 ruleBlockFormalStandard = rule "standard block parameters" $ do172 symbol "sub"173 return . Just =<< parens ruleSubParameters174 175 ruleBlockFormalPointy = rule "pointy block parameters" $ do176 symbol "->"177 return . Just =<< ruleSubParameters178 178 179 179 ruleCondConstruct = rule "conditional construct" $ fail "" … … 187 187 ruleExpression = (<?> "expression") $ parseOp 188 188 189 ruleBlockLiteral = rule "block construct" $ do 190 (typ, formal) <- option (SubBlock, Nothing) $ choice 191 [ ruleBlockFormalStandard 192 , ruleBlockFormalPointy 193 ] 194 body <- ruleBlock 195 let (fun, names) = extract (body, []) 196 params = (maybe [] id formal) ++ map nameToParam names 197 -- Check for placeholder vs formal parameters 198 unless (isNothing formal || null names || names == ["$_"] ) $ 199 fail "Cannot mix placeholder variables with formal parameters" 200 let sub = Sub { isMulti = False 201 , subName = "<anon>" 202 , subPad = [] 203 , subType = typ 204 , subAssoc = "pre" 205 , subReturns = "Any" 206 , subParams = if null params then [defaultArrayParam] else params 207 , subFun = fun 208 } 209 return (Val $ VSub sub) 210 211 ruleBlockFormalStandard = rule "standard block parameters" $ do 212 symbol "sub" 213 params <- option Nothing $ return . Just =<< parens ruleSubParameters 214 return $ (SubRoutine, params) 215 216 ruleBlockFormalPointy = rule "pointy block parameters" $ do 217 symbol "->" 218 params <- ruleSubParameters 219 return $ (SubBlock, Just params) 220 189 221 190 222 … … 211 243 , postOps " ++ -- " -- Auto-Increment 212 244 , rightOps " ** " -- Exponentiation 213 , preOps " ! + - ~ ? * ** +^ ~^ ?^ \\ " -- Symbolic Unary 245 -- , preOps " ! + - ~ ? * ** +^ ~^ ?^ \\ " -- Symbolic Unary 246 , preOps " ! + ~ ? * ** +^ ~^ ?^ \\ " -- Symbolic Unary 214 247 , leftOps " * / % x xx +& +< +> ~& ~< ~> " -- Multiplicative 215 248 , leftOps " + - ~ +| +^ ~| ~^ " -- Additive … … 344 377 sigil <- oneOf "$@%&" 345 378 caret <- option "" $ choice [ string "^", string "*" ] 346 name <- many1 wordAny 347 return $ (sigil:caret) ++ name 379 name <- many1 (choice [ wordAny, char ':' ]) 380 return $ if sigil == '&' && not (':' `elem` name) 381 then (sigil:caret) ++ "prefix:" ++ name 382 else (sigil:caret) ++ name 348 383 349 384 parseVar = do … … 356 391 357 392 parseLit = choice 358 [ numLiteral 393 [ ruleBlockLiteral 394 , numLiteral 359 395 , strLiteral 360 396 , arrayLiteral
