#!/usr/bin/env python
import re

Exps = '''    | EArrII ArrII
    | EProc [Decl] [Stm] Env
    | EFunc [Decl] Type [Stm] Env
'''

imports = '''import Data.Array
import qualified Data.Map as M
type ArrII = Array Int Int
type EExp = Exp
type Var = String
type Loc = Int
type Env = M.Map Ident Loc
type Store = M.Map Loc (Type, EExp)
'''
patternExp = '    | EInt Integer'
patternImports = 'module AbsPascalis where'

with open('AbsPascalis.hs', 'r') as f:
    data = f.read()

toInsert = {
    patternExp: Exps,
    patternImports: imports,
}


lines = data.split('\n')

result = []
for line in lines:
    result.append(line)
    for pattern in toInsert.keys():
        if pattern == line:
            result.append(toInsert[pattern])


with open('AbsPascalis.hs', 'w') as f:
    data = f.write('\n'.join(result))

@@ -362,16 +362,48 @@
 nteger'%0A
+patternExp2 = ' %7C EInt Integer'%0A
 patternI
@@ -534,16 +534,39 @@
 : Exps,%0A
+    patternExp2: Exps,%0A
     patt
@@ -859,8 +859,44 @@
 esult))%0A
+%0A%0Aprint ('Add exps works fine! :)')%0A

Add more generic exp