Skip to content

Commit

Permalink
initial attempt at docassemble output, not working yet.
Browse files Browse the repository at this point in the history
  • Loading branch information
mengwong committed Mar 3, 2021
1 parent c659aa8 commit aadf529
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 1 deletion.
17 changes: 16 additions & 1 deletion README.org
Original file line number Diff line number Diff line change
Expand Up @@ -313,4 +313,19 @@ to export the generated lib-path to your shell profile.

Yes, patches welcome!

* testing.
* Exporters

We transpile to several targets:

** GF

see the =nlg= branch.

** DocAssemble

We create a YAML file that drives a user interview to collect the data needed to parameterize a given L4 file.

** JSON

We pull out the simple parameters to a contract, e.g. party name, address, etc, and we stick it inside a JSON file that will subsequently be written into a PDF via XMP. See the ex-xmp project under complaw.

4 changes: 4 additions & 0 deletions exe/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ import Parser (parseProgram)
import Typing (tpProgram)
import System.Environment
import qualified ToGF as GF
import qualified ToDA as DA

-- TODO: add OptParse.Applicative to do the same as the current l4

process :: FilePath -> String -> IO ()
process filepath input = do
Expand All @@ -13,6 +16,7 @@ process filepath input = do
print (tpProgram $ () <$ ast)
--print ast
GF.nlg ast
DA.yaml ast
Left err -> do
putStrLn "Parser Error:"
print err
Expand Down
23 changes: 23 additions & 0 deletions l4/forDocAssemble.l4
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# l4version 0.3.4

lexicon
#myNumber -> number_2_N
is_legal -> legal_1_A
Business -> business_1_N

class Business {
name: String
uen: String
someNum: Int
}

-- the above should be enough information to set up a DocAssemble interview.

decl myNumber : Int

decl myBusiness : Business

-- okay, how do we say that myBusiness is called "MegaCorp"?

decl is_legal : Business -> Bool

30 changes: 30 additions & 0 deletions src/ToDA.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
module ToGF where

import Syntax
import Prop -- the generated Haskell abstract syntax from the GF
import Paths_baby_l4
import System.Environment (withArgs)
import Control.Monad (forM_)
import Text.Printf (printf)

-- prettyprinting

-- import some sort of YAML library so we aren't just doing all the prettyprinting ourselves
-- import some sort of Python library, ditto

createYAML :: (Show ct, Show et) => Program ct et -> IO [String]
createYAML (Program lexicon _2 _3 _4 _5) = do
return $ [ "---" ]

nlg :: (Show ct, Show et) => Program ct et -> IO ()
nlg prog = do
yamlstrings <- createYAML prog
putStrLn <$> yamlstrings
sequence_ [ prop
| prop <- program2prop prog
]

program2prop :: (Show ct, Show et) => Program ct et -> String
program2prop e = show e

-- later, convert "class" definitions to corresponding YAML/Python bitsies.

0 comments on commit aadf529

Please sign in to comment.