Permalink
Browse files

updated interface parsing

  • Loading branch information...
1 parent 207be4e commit cc07625159d89e26ecf06834dd59d20345bf762e @geekrelief committed Oct 19, 2008
Showing with 40 additions and 4 deletions.
  1. +1 −1 ActionhaXe/Data.hs
  2. +2 −1 ActionhaXe/Lexer.hs
  3. +12 −2 ActionhaXe/Parser.hs
  4. +25 −0 ActionhaXe/Translator.hs
View
@@ -68,7 +68,6 @@ data PrimaryE = PEThis CToken -- this
| PELit CToken -- literal: null, boolean, numeric, string, not regular expression or xml since those don't have operations on them outside of class methods
| PEArray ArrayLit -- array literal
| PEObject ObjectLit -- {, maybe [[property : assignE],[,]] , }
--- | PERegex CToken
| PEXml CToken
| PEFunc FuncE
| PEParens CToken ListE CToken -- (, List of expressions , )
@@ -175,6 +174,7 @@ data BlockItem = Tok CToken
| Block CToken [BlockItem] CToken
| ImportDecl CToken CToken Semi -- import identifier ;
| ClassDecl [CToken] CToken CToken (Maybe [CToken]) (Maybe [CToken]) BlockItem -- attributes, class, identifier, maybe extends, maybe implements, body
+ | Interface [CToken] CToken CToken (Maybe [CToken]) BlockItem -- public | internal, interface, identifier, maybe extends, body
| MethodDecl [CToken] CToken (Maybe CToken) CToken Signature (Maybe BlockItem) -- attributes, function, maybe get/set, identifier, Signature, body
| VarS (Maybe [CToken]) CToken [VarBinding] -- maybe attributes, var, varbindings
| ForS CToken CToken (Maybe ForInit) CToken (Maybe ListE) CToken (Maybe ListE) CToken BlockItem -- for( ? ; ? ; ?) {}
View
@@ -74,7 +74,8 @@ data TokenType =
keywords = [ "...", "as", "break", "case", "catch", "class", "const", "continue", "default",
"delete", "do", "else", "extends", "false", "finally", "for", "function", "if",
- "implements", "import", "in", "instanceof", "internal", "is", "native", "new", "null", "package",
+ "implements", "import", "in", "instanceof", "interface", "internal", "is",
+ "native", "new", "null", "package",
"private", "protected", "public", "return", "super", "switch", "this", "throw",
"to", "true", "try", "typeof", "use", "undefined", "var", "void", "while", "with",
-- syntactic keywords
View
@@ -53,6 +53,7 @@ inPackageBlock = try(do{ lookAhead( op "}"); return [] })
<|> try(do{ x <- metadata; i <- inPackageBlock; return $ [x] ++ i})
<|> try(do{ x <- importDecl; i <- inPackageBlock; return $ [x] ++ i})
<|> try(do{ x <- classDecl; i <- inPackageBlock; return $ [x] ++ i})
+ <|> try(do{ x <- interface; i <- inPackageBlock; return $ [x] ++ i})
<|> (do{ x <- anytok; i <- inPackageBlock; return $ [(Tok x)] ++ i})
directives = do{ ws <- startWs; x <- many1 (choice[metadata, importDecl, methodDecl, varS, do{ x <- anytok; return $ Tok x}]); return $ (Tok ws):x}
@@ -65,6 +66,13 @@ inClassBlock = try(do{ lookAhead( op "}"); return [] })
<|> try(do{ x <- varS; i <- inClassBlock; return $ [x] ++ i})
<|> (do{ x <- anytok; i <- inClassBlock; return $ [(Tok x)] ++ i})
+interfaceBlock = do{ l <- op "{"; enterScope; x <- inInterfaceBlock; r <- op "}"; exitScope; return $ Block l x r }
+
+inInterfaceBlock = try(do{ lookAhead( op "}"); return [] })
+ <|> try(do{ x <- metadata; i <- inInterfaceBlock; return $ [x] ++ i})
+ <|> try(do{ x <- methodDecl; i <- inInterfaceBlock; return $ [x] ++ i})
+ <|> (do{ x <- anytok; i <- inInterfaceBlock; return $ [(Tok x)] ++ i})
+
funcBlock = do{ l <- op "{"; enterScope; x <- inMethodBlock; r <- op "}"; exitScope; return $ Block l x r }
inMethodBlock = try(do{ lookAhead( op "}"); return [] })
@@ -117,6 +125,8 @@ metadataSwf =
importDecl = do{ k <- kw "import"; s <- sident; o <- maybeSemi; return $ ImportDecl k s o}
+interface = do{ a <- classAttributes; k <- kw "interface"; i <- ident; e <- optionMaybe(classExtends); b <- classBlock; return $ Interface a k i e b}
+
-- need to fix classImplements to return a tuple
classDecl = do{ a <- classAttributes; k <- kw "class"; i <- ident; e <- optionMaybe(classExtends); im <- optionMaybe(classImplements); storeClass i; b <- classBlock; return $ ClassDecl a k i e im b}
@@ -139,8 +149,8 @@ methodDecl = try(do{ attr <- methodAttributes
; storeProperty n acc sig
; return $ MethodDecl attr k acc n sig b})
-methodAttributes = permute $ list <$?> (emptyctok, (try (kw "public") <|> try (kw "private") <|> (kw "protected"))) <|?> (emptyctok, ident) <|?> (emptyctok, kw "override") <|?> (emptyctok, kw "static") <|?> (emptyctok, kw "final") <|?> (emptyctok, kw "native")
- where list v o s f n ns = filter (\a -> fst a /= []) [v,ns,o,s,f,n]
+methodAttributes = permute $ list <$?> (emptyctok, (try (kw "public") <|> try (kw "private") <|> (kw "protected"))) <|?> (emptyctok, ident) <|?> (emptyctok, kw "internal") <|?> (emptyctok, kw "override") <|?> (emptyctok, kw "static") <|?> (emptyctok, kw "final") <|?> (emptyctok, kw "native")
+ where list v ns i o s f n = filter (\a -> fst a /= []) [v,ns,i,o,s,f,n]
signature = do{ lp <- op "("; a <- sigargs; rp <- op ")"; ret <- optionMaybe ( do{ o <- op ":"; r <- datatype; return (o, r)}); return $ Signature lp a rp ret} -- missing return type means constructor
View
@@ -96,6 +96,11 @@ classBlock (Block l bs r) = do
bi <- foldlM (\s b -> do{ x <- classBlockItem b; return $ s ++ x} ) "" bs
return $ showd l ++ props ++ showw l ++ bi ++ showb r
+interfaceBlock (Block l bs r) = do
+ bi <- foldlM (\s b -> do{ x <- interfaceBlockItem b; return $ s ++ x} ) "" bs
+ return $ showb l ++ bi ++ showb r
+
+
block (Block l bs r) = do
bi <- foldlM (\s b -> do{ x <- blockItem b; return $ s ++ x} ) "" bs
return $ showb l ++ bi ++ showb r
@@ -116,6 +121,7 @@ packageBlockItem b =
Tok t -> tok t >>= return
ImportDecl _ _ _ -> return $ importDecl b
ClassDecl _ _ _ _ _ _ -> classDecl b >>= return
+ Interface _ _ _ _ _ -> interface b >>= return
Metadata m -> metadata m >>= return
_ -> return ""
return x
@@ -129,6 +135,14 @@ classBlockItem b =
_ -> return $ show b
return x
+interfaceBlockItem b =
+ do x <- case b of
+ Tok t -> tok t >>= return
+ MethodDecl _ _ _ _ _ _ -> imethodDecl b >>= return
+ Metadata m -> metadata m >>= return
+ _ -> return $ show b
+ return x
+
blockItem b =
do x <- case b of
Tok t -> tok t >>= return
@@ -171,6 +185,11 @@ classDecl (ClassDecl a c n e i b) = do
attr as = concat $ map (\attr -> case (showd attr) of { "internal" -> "private" ++ showw attr; "public" -> ""; x -> showb attr }) as
implements is = maybeEl showl is
+interface (Interface a i n e b) = do
+ x <- interfaceBlock b
+ return $ attr a ++ showb i ++ showb n ++ maybeEl showl e ++ x
+ where attr as = concat $ map (\attr -> case (showd attr) of { "internal" -> "private" ++ showw attr; "public" -> ""; x -> showb attr }) as
+
methodDecl (MethodDecl a f ac n s b) = do
packageName <- getFlag fpackage
className <- getFlag fclass
@@ -201,6 +220,12 @@ methodDecl (MethodDecl a f ac n s b) = do
getArg (Signature l (a@(Arg n c t md mc):as) r ret) = showd n
getArg (Signature l [] r ret) = ""
+
+imethodDecl (MethodDecl a f ac n s b) = do
+ return $ attr a ++ showb f ++ showb n ++ signature s
+ where attr as = concat $ map (\attr -> case (showd attr) of { "internal" -> "private" ++ showw attr; x -> showb attr }) as
+
+
signatureArgs (Signature l args r ret) = showb l ++ showArgs args ++ showb r
rettype ret = case ret of

0 comments on commit cc07625

Please sign in to comment.