The Meta-Environment API
00001 #ifndef __PARSETABLE_UTILS__ 00002 #define __PARSETABLE_UTILS__ 00003 00004 #include <cache-utils.tb> 00005 #include <parsetablegen.idef> 00006 00007 process GetParseTable(ModuleId: module-id, Type: term, Table: term?) is 00008 let 00009 Error: term 00010 in 00011 snd-msg(get-parsetable(ModuleId, Type)) 00012 . 00013 ( 00014 rec-msg(parsetable(ModuleId, Type, Table?)) 00015 + 00016 rec-msg(no-parsetable(ModuleId, Type)) 00017 . Table := UNDEFINED 00018 ) 00019 endlet 00020 00021 /* BuildParseTable is started somewhere else, such that a specific 00022 * PreprocessSyntaxHandler can be bound for specific types of languages 00023 */ 00024 process BuildParsetable(TableName: str, Namespace: term, Type: term, PreprocessSyntaxHandler: str) is 00025 let 00026 ModuleId: module-id, 00027 Syntax: term, 00028 Table: term, 00029 Modulename: str, 00030 NewSyntax: term, 00031 Pid: int 00032 in 00033 InitCache(TableName) 00034 . create(ClearCacheHandler(TableName, Namespace, "status", <term>, complete), Pid?) 00035 . 00036 ( 00037 rec-msg(get-parsetable(ModuleId?, Type)) 00038 . GetCachedValue(TableName, ModuleId, Table?) 00039 . 00040 if equal(Table, UNDEFINED) then 00041 AddJob("Generating parser") 00042 . snd-msg(tm-request-transaction(syntax-definition)) 00043 . GetSyntaxDefinition(ModuleId, Syntax?) 00044 . snd-msg(tm-end-transaction(syntax-definition)) 00045 . 00046 if not-equal(Syntax, UNDEFINED) then 00047 MM-GetAttribute(ModuleId, Namespace, "name", Modulename?) 00048 . PreprocessSyntaxHandler(Modulename, Syntax, NewSyntax?) 00049 . GenerateParsetable(Modulename, NewSyntax, Table?) 00050 . 00051 if not-equal(Table, UNDEFINED) then 00052 PutCachedValue(TableName, ModuleId, Table) 00053 . snd-msg(parsetable(ModuleId, Type, Table)) 00054 else 00055 snd-msg(no-parsetable(ModuleId, Type)) 00056 fi 00057 else 00058 snd-msg(no-parsetable(ModuleId, Type)) 00059 fi 00060 . JobDone("Generating parser") 00061 else 00062 snd-msg(parsetable(ModuleId, Type, Table)) 00063 fi 00064 ) 00065 * delta 00066 endlet 00067 00068 process GenerateParsetable(Modulename: str, Syntax: term, Table: term?) is 00069 snd-msg(generate-parsetable(Syntax, Modulename)) 00070 . 00071 ( 00072 rec-msg(parsetable(Table?)) 00073 + 00074 rec-msg(no-parsetable) 00075 . Table := UNDEFINED 00076 ) 00077 00078 process DumpParseTable(ModuleId : module-id, Namespace: term, Filename : str, Type : term) is 00079 let 00080 Directory: str, 00081 Error: term, 00082 Extension: str, 00083 Id: term, 00084 NewFilename: str, 00085 NewPath: str, 00086 Path: str, 00087 Table: term 00088 in 00089 AddJob(Filename) 00090 . Id := process-id 00091 . snd-msg(get-parsetable(ModuleId, Type)) 00092 . 00093 ( 00094 rec-msg(parsetable(ModuleId, Type, Table?)) 00095 . GetModulePath(ModuleId, Namespace, Path?) 00096 . 00097 if equal(Filename, "") then 00098 TODO("DumpParseTable got empty filename") 00099 else 00100 NewFilename := Filename 00101 fi 00102 . snd-msg(io-unpack-and-write-term-in-baf(NewFilename, Table)) 00103 . 00104 ( 00105 rec-msg(io-file-written) 00106 + 00107 rec-msg(io-file-not-written(Error?)) 00108 ) 00109 + 00110 rec-msg(no-parsetable(ModuleId)) 00111 ) 00112 . JobDone(Filename) 00113 endlet 00114 00115 #endif /* __PARSETABLE_UTILS__ */