softlang / megalib

A library of megamodels
6 stars 5 forks source link

Optimizing Substitution #13

Closed le-cram closed 7 years ago

le-cram commented 7 years ago

There may appear a lot of redundancy when using substitution. The question is whether it is worth addressing by changing the copy & replace mechanism.

Consider an example as follows from antlr.demo.MegaLChecker.megal

import antlr.ListenerForParserError where {
[
    checker / ?App,
    MegaL / ?InputLanguage, 
    checkerGrammar / ?grammar,
    checkerLexer / ?ANTLRJavaLexer, 
    checkerParser / ?ANTLRJavaParser, 
    checkerParserFiles / ?ANTLRJavaParserFiles, 
    checkerLexerFiles / ?ANTLRJavaLexerFiles,
    ?someMegaModel / ?input,
    CheckerErrorListener / ?ErrorListener,
    ?parserObjectWithListenersAfterApplication / ?parserObjectWithErrorListenerAfterApplication
]
} 
import antlr.ListenerForParser where{
[
    checker / ?App,
    MegaL / ?InputLanguage, 
    checkerGrammar / ?grammar,
    checkerLexer / ?lexer, 
    checkerParser / ?parser, 
    checkerParserFiles / ?parserFiles, 
    checkerLexerFiles / ?lexerFiles,
    ?someMegaModel / ?input,
    checkerModelListener / ?parserListener0, //
    ?parserObject2 / ?subject2
]
}

This is just a sketch for reducing this redundancy. Don't know whether this is good, but it looks like its less dsl code. The idea here, would be to first import all entities from imported modules and then start the substitution. This might make things easier....

import antlr.ListenerForParser
import antlr.ListenerForParserError
//This basically needs to be invisible when pretty printing anyways...
{   //basically antlr.Parsing and transitive import from antlr.App
checker / ?App,
MegaL / ?InputLanguage, 
checkerGrammar / ?grammar,
checkerLexer / ?ANTLRJavaLexer, 
checkerParser / ?ANTLRJavaParser, 
checkerParserFiles / ?ANTLRJavaParserFiles, 
checkerLexerFiles / ?ANTLRJavaLexerFiles,
?someMegaModel / ?input,
[ //antlr.ListenerForParserError 
    checkerErrorListener / ?ErrorListener,
    ?parserObjectWithListenersAfterApplication / ?parserObject2
],
[ //antlr.ListenerForParser 
    checkerParserListener0 / ?parserListener0, //
    ?parserObject2 / ?subject2
]
}  
le-cram commented 7 years ago

Will try refactoring the model first instead. It might be more understandable if you'd create two to three model files instead. Each focusing on one aspect: Parsing, ParserListener and ErrorListener.