1
0
forked from GitHub/gf-core

Use LCLR algorithm for eliminating left-recursion, with lambda terms in SISR for getting trees right.

This commit is contained in:
bringert
2006-12-20 20:10:15 +00:00
parent 5b8680b8fd
commit cb70ffadaa
14 changed files with 541 additions and 308 deletions

View File

@@ -1,5 +1,5 @@
{-# OPTIONS -fno-warn-incomplete-patterns #-}
module GF.JavaScript.PrintJS where
module GF.JavaScript.PrintJS (printTree, Doc, Print(..)) where
-- pretty-printer generated by the BNF converter
@@ -25,8 +25,10 @@ render d = rend 0 (map ($ "") $ d []) "" where
"}" :ts -> new (i-1) . showChar '}' . new (i-1) . rend (i-1) ts
";" :ts -> showChar ';' . new i . rend i ts
t : "," :ts -> showString t . space "," . rend i ts
t : "." :ts -> showString t . showString "." . rend i ts
t : ")" :ts -> showString t . showChar ')' . rend i ts
t : "]" :ts -> showString t . showChar ']' . rend i ts
t : "[" :ts -> showString t . showChar '[' . rend i ts
t :ts -> space t . rend i ts
_ -> id
new i = showChar '\n' . replicateS (2*i) (showChar ' ') . dropWhile isSpace
@@ -143,6 +145,7 @@ instance Print Expr where
ENull -> prPrec i 16 (concatD [doc (showString "null")])
EThis -> prPrec i 16 (concatD [doc (showString "this")])
EFun ids stmts -> prPrec i 16 (concatD [doc (showString "function") , doc (showString "(") , prt 0 ids , doc (showString ")") , doc (showString "{") , prt 0 stmts , doc (showString "}")])
ESeq exprs -> prPrec i 16 (concatD [doc (showString "(") , prt 0 exprs , doc (showString ")")])
prtList es = case es of
[] -> (concatD [])