igordejanovic / parglare

A pure Python LR/GLR parser - http://www.igordejanovic.net/parglare/
MIT License
135 stars 32 forks source link

Parser object singleton or caching. Actions as object members #126

Closed xor2003 closed 3 years ago

xor2003 commented 3 years ago

Description

I have big grammar 28k. pgt file is 9MB. There are actions and recognizers in python.

So creation of Gramar and Parser from pgt file takes time. But I want unit tests to pass fast. So I want to create Gramar, Parser objects just once (or some prototyping) and to have actions, orginizers to be from different objects (;same class; store different context data) Can I deepcopy Parser, Gramar?

Can you advice something?

igordejanovic commented 3 years ago

How long does it take to load from cache? The slowest part AFAIK is generating LR table, which gets cached and reused. I haven't worked with grammars that are slow in other parts of the construction process. Have you tried to do deepcopy?

xor2003 commented 3 years ago

After I used Singletone it doesn't bother me anymore

xor2003 commented 3 years ago

When I do deepcopy it cannot deepcopy Grammar. It is some issue with recursion and python crashing. It works for me when I do simple copy().