-- INCLUDE "AbstractSyntax.ag" -- INCLUDE "Patterns.ag" -- INCLUDE "Expression.ag" imports { import ATermAbstractSyntax } { convert :: String -> String convert [] = [] convert (c:ct) | c == '\n' = '\\' : 'n' : convert ct | otherwise = c : convert ct sQ :: String -> String sQ [] = [] sQ (x:xs) = if (x=='"') then rest else x:rest where rest = if last xs == '"' then init xs else xs removeQuotes :: String -> String removeQuotes [] = [] removeQuotes (c:ct) | c=='"' = removeQuotes ct | otherwise = c : removeQuotes ct -- A special version that omits the quotes. -- An alternative is to do show and removeQuotes afterwards. showAGPos :: Pos -> String showAGPos (Pos l c f) | l == (-1) = "" | otherwise = let file = if null f then "" else f lc = "(line " ++ show l ++ ", column " ++ show c ++")" in file ++ lc } ATTR Grammar Production Alternative Child Rule Expression Pattern [ || aterm:{ATerm} ] ATTR Productions Alternatives Children Rules Patterns [ || aterm:{[ATerm]} ] SEM Grammar | Grammar lhs.aterm = AAppl "Productions" @prods.aterm SEM Productions | Cons lhs.aterm = @hd.aterm : @tl.aterm | Nil lhs.aterm = [] SEM Production | Production lhs.aterm = AAppl "Production" [AString (sQ (getName @nt)), AString (sQ (show @inh)), AString (sQ (show @syn)), AAppl "Alternatives" @alts.aterm] SEM Alternatives | Cons lhs.aterm = @hd.aterm : @tl.aterm | Nil lhs.aterm = [] SEM Alternative | Alternative lhs.aterm = AAppl "Alternative" [AString (sQ (getName @con)), AAppl "Children" @children.aterm, AAppl "Rules" @rules.aterm ] SEM Children | Cons lhs.aterm = @hd.aterm : @tl.aterm | Nil lhs.aterm = [] SEM Child | Child lhs.aterm = AAppl "Child" [AString (sQ (getName @name)), AString (sQ (show @tp)), AString (sQ (show @inh)), AString (sQ (show @syn))] SEM Rules | Cons lhs.aterm = @hd.aterm : @tl.aterm | Nil lhs.aterm = [] SEM Rule | Rule lhs.aterm = AAppl "Rule" [@pattern.aterm, @rhs.aterm, AString (sQ (show @owrt))] SEM Expression | Expression lhs.aterm = AAppl "Expression" [AString (sQ (showAGPos @pos)), AString (sQ (show @txt))] SEM Patterns | Cons lhs.aterm = @hd.aterm : @tl.aterm | Nil lhs.aterm = [] SEM Pattern | Constr lhs.aterm = AAppl "Pattern" [AAppl "Constr" [AString (sQ (showAGPos (getPos @name))), AString (sQ (getName @name)), AAppl "Patterns" @pats.aterm]] | Product lhs.aterm = AAppl "Pattern" [AAppl "Product" [AString (sQ (showAGPos @pos)), AAppl "Patterns" @pats.aterm]] -- TODO: what exacltly is the meaning of Alias? Is it different from what Var used to be? | Alias lhs.aterm = AAppl "Pattern" [AAppl "Var" [AString (sQ (showAGPos (getPos @field))), AString (getName @field ++ "." ++ getName @attr), @pat.aterm]] | Underscore lhs.aterm = AAppl "Pattern" [AAppl "Underscore" [AString (sQ (showAGPos @pos))]]