Exemplo n.º 1
0
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
# IN THE SOFTWARE.

import os, sys
sys.path.insert(0, os.path.dirname(os.path.dirname(__file__)))
from pymeta import builder, grammar

fp = open(os.path.join(os.path.dirname(__file__), 'parser.py'), 'wb')
ometa_grammar = grammar.OMetaGrammar(open(os.path.join(os.path.dirname(__file__),"meme.g")).read())
tree = ometa_grammar.parseGrammar('MemeParser', builder.TreeBuilder)
fp.write(builder.writeBoot(tree))

# fp = open(os.path.join(os.path.dirname(__file__), 'coretr.py'), 'wb')
# ometa_grammar = grammar.OMetaGrammar(open(os.path.join(os.path.dirname(__file__),"core_tr.g")).read())
# tree = ometa_grammar.parseGrammar('CoreTr', builder.TreeBuilder)
# fp.write(builder.writeBoot(tree))

fp = open(os.path.join(os.path.dirname(__file__), 'memetr.py'), 'wb')
ometa_grammar = grammar.OMetaGrammar(open(os.path.join(os.path.dirname(__file__),"meme_tr.g")).read())
tree = ometa_grammar.parseGrammar('MemeTr', builder.TreeBuilder)
fp.write(builder.writeBoot(tree))

# fp = open(os.path.dirname(__file__) + '/../loader.py', 'wb')
# ometa_grammar = grammar.OMetaGrammar(open(os.path.dirname(__file__)+"/load_module.ast.g").read())
# tree = ometa_grammar.parseGrammar('Loader', builder.TreeBuilder)
# fp.write(builder.writeBoot(tree))
Exemplo n.º 2
0
# Generates a boot grammar and stores it in boot_generated.py. If everything looks OK you can
# replace your boot.py with the generated module.
if __name__ == '__main__':
    import os, sys
    sys.path.insert(0, os.path.dirname(os.path.dirname(__file__)))
    from pymeta import builder, grammar
    fp = open(os.path.join(os.path.dirname(__file__), 'boot_generated.py'), 'wb')
    ometa_grammar = grammar.OMetaGrammar(grammar.ometaGrammar)
    tree = ometa_grammar.parseGrammar('BootOMetaGrammar', builder.TreeBuilder)
    fp.write(builder.writeBoot(tree))
Exemplo n.º 3
0
# Generates static grammar modules so the PyvaScript grammar doesn't need to be
# parsed on first import.
if __name__ == '__main__':
    import os, sys
    sys.path.insert(0, os.path.dirname(os.path.dirname(__file__)))
    from pymeta.builder import TreeBuilder, writeBoot
    from pymeta.grammar_definition import OMetaGrammar
    from pyvascript.grammar import grammar_path, translator_path
    for name, path in (('Grammar', grammar_path), ('Translator', translator_path)):
        with open(path, 'r') as fp:
            source = fp.read()
        grammar = OMetaGrammar(source)
        tree = grammar.parseGrammar('Generated' + name, TreeBuilder)
        path = os.path.join(os.path.dirname(__file__), name.lower() + '_generated.py')
        with open(path, 'w') as fp:
            fp.write('import json\ndef p(s): print(s)\n')
            fp.write(writeBoot(tree))
Exemplo n.º 4
0
# Generates static grammar modules so the PyvaScript grammar doesn't need to be
# parsed on first import.
if __name__ == '__main__':
    import os, sys
    sys.path.insert(0, os.path.dirname(os.path.dirname(__file__)))
    from pymeta.builder import TreeBuilder, writeBoot
    from pymeta.grammar_definition import OMetaGrammar
    from pyvascript.grammar import grammar_path, translator_path
    for name, path in (('Grammar', grammar_path), ('Translator',
                                                   translator_path)):
        with open(path, 'r') as fp:
            source = fp.read()
        grammar = OMetaGrammar(source)
        tree = grammar.parseGrammar('Generated' + name, TreeBuilder)
        path = os.path.join(os.path.dirname(__file__),
                            name.lower() + '_generated.py')
        with open(path, 'w') as fp:
            fp.write('import json\ndef p(s): print(s)\n')
            fp.write(writeBoot(tree))