From 7c4b661233195baede48356f594ebb15f4aa210d Mon Sep 17 00:00:00 2001 From: adam Date: Sun, 27 May 2007 16:47:43 -0400 Subject: [PATCH] update README, ditch Main.lhs darcs-hash:20070527204743-5007d-87bd651f82433a1ea7a5b0b35533f102d7b5f7be.gz --- README | 15 +++-- src/HaskellDemo.hs | 7 -- src/Main.lhs | 181 ---------------------------------------------------- 3 files changed, 11 insertions(+), 192 deletions(-) delete mode 100644 src/HaskellDemo.hs delete mode 100644 src/Main.lhs diff --git a/README b/README index fd7dd4c..7891aab 100644 --- a/README +++ b/README @@ -2,7 +2,7 @@ Scannerless Boolean Parser Adam Megacz -12-Dec-2005 +updated 27-May-2007 ______________________________________________________________________________ Requirements @@ -49,8 +49,10 @@ Browsing the code sbp/ -- core API: grammar, trees, and forests misc -- regression testing and sample code util -- some nifty data structures not specific to parsing - tib -- Text with Indentation and Braces (experimental/undocumented) + meta -- code relating to the metagrammar (meta.g) + chr -- code for parsing character streams (you want this) doc/ + jargon.txt -- read this! api/ -- generated javadocs go here tests/ meta.g -- the tentative metagrammar, written in itself @@ -74,5 +76,10 @@ Using the code would be anything drastic enough to require more than a few minutes to update a grammar description. - The TIB stuff is super experimental; I'm not even sure if I'll keep - it around. Use at your own risk. + +______________________________________________________________________________ +Haskell Integration + + If you're using LambdaVM (the Java backend for GHC), you'll be able + to use SBP in your Haskell code. See src/SBP.lhs for more info. + diff --git a/src/HaskellDemo.hs b/src/HaskellDemo.hs deleted file mode 100644 index eaac568..0000000 --- a/src/HaskellDemo.hs +++ /dev/null @@ -1,7 +0,0 @@ -module Main where - import SBP; - main = do x <- SBP.parseFile ["edu.berkeley.sbp.jar"] "tests/meta.g" "tests/testcase.g" - putStr "\n" - putStr $ show x - putStr "\n" - putStr "\n" diff --git a/src/Main.lhs b/src/Main.lhs deleted file mode 100644 index bcac25b..0000000 --- a/src/Main.lhs +++ /dev/null @@ -1,181 +0,0 @@ -\begin{code} -module Main -where -import SBP -main = do t <- parseFile "../wix/wix.g" "../wix/lasik.wix" - putStrLn $ toHtml $ ((fromTree $ coalesceFlatHeadlessNodes t) :: Doc) - --- url crap --- ul/ol --- glyphs - ------------------------------------------------------------------------------- -data Doc = Doc Header [Section] -data Section = Section [Text] [Paragraph] -data Paragraph = Blockquote [Text] - | HR - | OL - | P [Text] -data Text = WS - | Chars String - | Symbol String - | Quotes [Text] - | Block [Text] - | Command String [Text] - | Verbatim String - | Link [Text] URL - | Underline [Text] - | Footnote [Text] - | TT [Text] - | Citation [Text] - | Strikethrough [Text] - | Superscript [Text] - | Subscript [Text] - | Smallcap [Text] - | Bold [Text] - | Keyword [Text] - | Italic [Text] -data Header = Header -data URL = URL - deriving Show - -{- -glyph = euro:: "(e)" - | r:: "(r)" - | c:: "(c)" - | tm:: "(tm)" - | emdash:: "--" - | ellipses:: "..." - | cent:: "\\cent" --} - ------------------------------------------------------------------------------- -class FromTree a where - fromTree :: Tree -> a -class FromTrees a where - fromTrees :: [Tree] -> a -instance FromTree a => FromTree [a] where - fromTree (Tree _ c _) = map fromTree c - -instance FromTree Doc where - fromTree (Tree "Doc" [a,b] _) = Doc Header $ fromTree b - fromTree (Tree "Doc" [b] _) = Doc Header $ fromTree b - fromTree _ = error "top level must be Doc" - -instance FromTree Section where - fromTree (Tree "Section" [(Tree _ c _),(Tree _ paragraphs _)] _) = - Section (map fromTree c) $ map fromTree paragraphs - -instance FromTree Paragraph where - fromTree (Tree "P" [Tree _ text _] _) = P $ map fromTree text - fromTree (Tree "HR" _ _) = HR - -instance FromTree Text where - fromTree (Tree "Chars" chars _) = Chars $ fromTrees chars - fromTree (Tree "WS" _ _) = WS - fromTree (Tree "Symbol" sym _) = Symbol $ fromTrees sym - fromTree (Tree "Quotes" x _) = Quotes $ map fromTree x - fromTree (Tree "Block" x _) = Block $ map fromTree x - fromTree (Tree "Command" [x,y] _) = Command (fromTree x) (fromTree y) - fromTree (Tree "Verbatim" x _) = Verbatim $ fromTrees x - fromTree (Tree "Link" [word,link] _) = Link (fromTree word) (fromTree link) - fromTree (Tree "Underline" x _) = Underline $ map fromTree x - fromTree (Tree "Footnote" x _) = Footnote $ map fromTree x - fromTree (Tree "TT" x _) = TT $ map fromTree x - fromTree (Tree "Citation" x _) = Citation $ map fromTree x - fromTree (Tree "Strikethrough" x _) = Strikethrough $ map fromTree x - fromTree (Tree "Superscript" x _) = Superscript $ map fromTree x - fromTree (Tree "Subscript" x _) = Subscript $ map fromTree x - fromTree (Tree "Smallcap" x _) = Smallcap $ map fromTree x - fromTree (Tree "Bold" x _) = Bold $ map fromTree x - fromTree (Tree "Keyword" x _) = Keyword $ map fromTree x - fromTree (Tree "Italic" x _) = Italic $ map fromTree x - fromTree (Tree x _ _) = Chars $ x - -instance FromTree URL where - fromTree x = URL - -instance FromTree String where - fromTree (Tree h c _) = h++(concatMap fromTree c) -instance FromTrees String where - fromTrees ts = concatMap (fromTree :: Tree -> String) ts - ------------------------------------------------------------------------------- -class ToHtml a where - toHtml :: a -> String -instance ToHtml a => ToHtml [a] where - toHtml x = concatMap toHtml x - -instance ToHtml Doc where - toHtml (Doc h secs) = "" ++ (toHtml secs) ++ "" -instance ToHtml Section where - toHtml (Section header paragraphs) = "

"++(toHtml header)++"

"++(toHtml paragraphs) -instance ToHtml Paragraph where - toHtml (Blockquote t) = "
"++(toHtml t)++"
" - toHtml HR = "
" - toHtml OL = "
    " - toHtml (P t) = "

    "++(toHtml t)++"

    " -instance ToHtml Text where - toHtml WS = " " - toHtml (Chars s) = toHtml s - toHtml (Symbol s) = toHtml s - toHtml (Quotes x) = "\""++(toHtml x)++"\"" - toHtml (Block x) = toHtml x - toHtml (Verbatim x) = "
    \n"++x++"\n
    " - toHtml (Link t ref) = ""++(toHtml t)++"" - toHtml (Underline x) = ""++(toHtml x)++"" - toHtml (TT x) = ""++(toHtml x)++"" - toHtml (Citation x) = ""++(toHtml x)++"" - toHtml (Strikethrough x) = ""++(toHtml x)++"" - toHtml (Superscript x) = ""++(toHtml x)++"" - toHtml (Subscript x) = ""++(toHtml x)++"" - toHtml (Smallcap x) = ""++(toHtml x)++"" - toHtml (Bold x) = ""++(toHtml x)++"" - toHtml (Keyword x) = ""++(toHtml x)++"" - toHtml (Italic x) = ""++(toHtml x)++"" - toHtml (Command x y) = error $ "unsupported command "++(show x) - toHtml (Footnote x) = error $ "footnotes not supported" - -instance ToHtml String where - toHtml s = concatMap htmlEscapeChar s - where - htmlEscapeChar '<' = "<" - htmlEscapeChar '>' = ">" - htmlEscapeChar '&' = "&" - htmlEscapeChar '\'' = "'" - htmlEscapeChar '\"' = """ - htmlEscapeChar c = [c] - - - - - - -{- - -Doc: { { Section: { { Chars: { 19 } Symbol: { - } Chars: { Nov } } - { P: { { Chars: { Two } WS Chars: { weeks } WS Chars: { ago } WS - Chars: { I } WS Chars: { had } WS Chars: { Lasik } WS - Chars: { performed } WS Chars: { at } WS - Link: { { Chars: { the } WS Chars: { Pacific } WS Chars: { Vision } - WS Chars: { Institute } } - URL: { http DNS: { { pacificvision org } } { . } } } - WS Chars: { The } WS Chars: { short } WS Chars: { story } WS - Chars: { is } WS Chars: { that } WS Chars: { it } WS - Chars: { rocks } Symbol: { , } WS Chars: { and } WS Chars: { I } WS - Chars: { very } WS Chars: { highly } WS - Chars: { recommend } WS Chars: { Dr } Symbol: { . } WS - Chars: { Faktorovich } - Symbol: { , } WS - Chars: { as } WS - Chars: { well } - WS Chars: { as } - WS - Chars: { the } - --} -\end{code} - - - - -- 1.7.10.4