-- code for generating a list of attributes and a list of -- local variables as comments in the generated file imports { import List (intersect, (\\)) import qualified UU.DData.Map as Map(toList) } ATTR Productions Production Alternatives Alternative Rules Rule [ o_pretty:{Bool} | | ] SEM Grammar | Grammar loc.o_pretty = attrInfo @lhs.options SEM Production | Production loc.comment = let syn' = map toString (Map.toList @syn) inh' = map toString (Map.toList @inh) toString (a,t) = (getName a, case t of (NT nt) -> getName nt; Haskell t -> t) chnn = inh' `intersect` syn' inhn = inh' \\ chnn synn = syn' \\ chnn in Comment . unlines $ [ replicate 3 ' ' ++ "inherited attributes:" , unlines . map ((replicate 6 ' ')++) . map (\(x,y) -> x ++ replicate ((20 - length x) `max` 0) ' ' ++ " : " ++ y) $ inhn , replicate 3 ' ' ++ "chained attributes:" , unlines . map ((replicate 6 ' ')++) . map (\(x,y) -> x ++ replicate ((20 - length x) `max` 0) ' ' ++ " : " ++ y) $ chnn , replicate 3 ' ' ++ "synthesised attributes:" , unlines . map ((replicate 6 ' ')++) . map (\(x,y) -> x ++ replicate ((20 - length x) `max` 0) ' ' ++ " : " ++ y) $ synn ] SEM Alternatives [ || comments : {Decls} ] | Cons lhs.comments = @hd.comment : @tl.comments | Nil lhs.comments = [] SEM Alternative [ || comment : {Decl} ] | Alternative lhs.comment = Comment . unlines $ [ replicate 3 ' ' ++ "local variables for " ++ getName @lhs.nt ++ "." ++ getName @con ++ ":" , unlines . map ((replicate 6 ' ')++) $ map getName @rules.locVars ] -- copied from DefaultRules, double computation :-( ATTR Rules Rule Patterns Pattern [ | | locVars USE {++} {[]}:{[Name]} ] SEM Pattern | Alias lhs.locVars = if @field == _LOC then [@attr] else []