Skip to content

Instantly share code, notes, and snippets.

@haskellcamargo
Created February 25, 2015 21:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save haskellcamargo/8875007d4b8058df4f26 to your computer and use it in GitHub Desktop.
Save haskellcamargo/8875007d4b8058df4f26 to your computer and use it in GitHub Desktop.
Tests with Rawr Lang
module Data where
with (~Closure, ~Countable, ~Exception, ~ReflectionClass) do
("../Data.Types.php" :: File).requireOnce!
class ClassHolder(className :: Str)
with contract Countable
my publicMethods :: Int <- 0
my methods :: [~ReflectionMethod] <- [||]
magic method construct where
className.classExists
.ifTrue(fun =>
let reflectionClass <- %% ReflectionClass(className)
@methods <- reflectionClass.getMethods!
end)
.ifFalse(fun =>
give %% Data.Error("Class '\(className)' not found.")
end)
end
method count where give @publicMethods end
method listMethods where give @methods end
method listPublicMethods where
give @methods when (fun (method :: ReflectionMethod) =>
give method.isPublic!
end)
end
static method parseDocComments(doc :: Str)
let mutable (doc, res) :: [Str] <- (doc.lines!, [||])
doc map (fun (line :: Str) =>
line.trim<!>
(line = ("/**" or "*/"))
.ifTrue(fun => pass end)
-- otherwise
(line.0 = "*")
.ifTrue(fun =>
let simpleData :: Regex <-
(/\*\s*@([a-z\|]+)\s*:\s*(.*)/)
store mutable out
let match : Int <-
simpleData.matchesWith(line, out)
match.toBool!
.ifTrue(fun =>
res.add([| out.1; out.2 |])
end)
pass
end)
.otherwise(fun =>
give %% Data.Error("Expecting '*' as the first character
of line.")
end)
end)
end
end
class Method { name :: Str, class :: Str, type :: Str, about :: Str}
let mutable methodList :: [~ReflectionMethod] <- [||]
in data set "num" as %% ClassHolder("\\Data\\Num")
data#num when (fun (item) =>
give method.getDocComment!
end)
each (fun (item) =>
let t :: Str <-
ClassHolder:parseDocComments(item.getDocComment!)
t.about!
end)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment