diff --git a/README.md b/README.md index 814faf1..bd2e9e7 100644 --- a/README.md +++ b/README.md @@ -1 +1,36 @@ # rubyhs + +A *node* is the "fully qualified name" of either 1) a function; or 2) +a module. The program should create a *reference graph*. The +reference graph shows which nodes reference other nodes. Treating +modules and functions equally allow us to express that a module calls +a function as in: + + module M + f + end + +as well as the opposite where a function refers to a constant: + + def f + M + end + +The program should ensure that references actually correspond to nodes +that we know of. + +The program should maintain forward edges as well as backwards edges. +That way we can both answer the question "Which nodes does this node +transitively reference" as well as "which nodes transitively reference +this node". + +Given a reference graph and a node - called the query - that program +should print out a spanning tree rooted at the query node. Cycles +should be marked. E.g. like so for two mutually defined nodes `a` and +`b`: + + { + "a": { + "b": { "a": "__cycle__" } + } + } diff --git a/ruby/test.rb b/ruby/test.rb index be77365..0a063f4 100644 --- a/ruby/test.rb +++ b/ruby/test.rb @@ -1,3 +1,6 @@ +def h +end + module M def f end @@ -8,7 +11,13 @@ module M h(2, a: :a) end + def h + end + module N + def h + end + def f M::foo h @@ -31,4 +40,3 @@ end f(2) h(2, a: 'a') h(2, a: :a) - diff --git a/src/Rubyhs.hs b/src/Rubyhs.hs index 6617034..12980ef 100644 --- a/src/Rubyhs.hs +++ b/src/Rubyhs.hs @@ -49,17 +49,16 @@ command = Command <$> targets <*> printAST where targets = many (Options.argument Options.str (Options.metavar "TARGET")) printAST = Options.switch - $ Options.long "quiet" - <> Options.short 'q' - <> Options.help "Whether to be quiet" + $ Options.long "print-ast" + <> Options.help "Print AST and exit" getCommand :: IO Command getCommand = Options.execParser opts where opts = Options.info (Options.helper <*> command) ( Options.fullDesc - <> Options.progDesc "Print a greeting for TARGET" - <> Options.header "hello - a test for optparse-applicative" ) + <> Options.progDesc "Static analysis of Ruby" + <> Options.header "rubyhs - Static analysis of Ruby" ) decodeFail :: MonadFail m => FromJSON a => ByteString -> m a decodeFail s = case eitherDecode s of