Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Have you tried pickling your parser? I have done this before with a complex parser (for Python itself), and got a reasonable improvement in startup time. Save the pickled parser off to a file, and then to parse a single message, unpickle the parser in from the file instead of explicitly building it. If streamline is an expensive part of the setup, then be sure to call <code>parser.streamline()</code> before pickling - then when actually parsing a message, this expensive streamline step can be skipped.</p> <p>You might also be inefficient in constructing your parser if you are not defining low-level primitives, but explicitly redefining the same expressions over and over. For instance, using <code>Word(nums)</code> repeatedly, instead of defining a low-level expression <code>integer = Word(nums)</code> and then referring to <code>integer</code> in places where integers are expected. It is rare for this to have an effect at parser construction time (I have only seen one other person actually have this problem), but it can happen.</p> <p>Are you using a function to define complex sub-parsers that follow a pattern? Try memoizing that function, so that repeated calls with the same arguments return the same parsing expression instead of new expressions. Then these repeated expressions will only get streamlined once.</p> <p>Do you have a complex low-level expression that is used many places with different results names? This will actually create copies of that expression under the covers. You could explicitly call <code>streamline</code> as part of the definition step, and the copies would streamlined ahead of time. I could envision this kind of thing if you have an expression for a real number. In fact, I've seen significant parse-time improvement if you replace a real number definition made up by assembling pyparsing bits (something like <code>Combine(Optional(oneOf('- +')) + Word(nums) + Optional('.' + Word(nums)) + Optional(oneOf('E e') + Optional(oneOf('- +')) + Word(nums))</code>) with a single Regex expression (<code>Regex(r'[-+]?\d+(\.\d*)?([Ee][-+]?\d+)?')</code> would correspond to the previous expression). No need to go overboard on this though, pyparsing does a lot of internal representation of parser expressions as regexes.</p> <p>Well that's all I can come up just on speculation - for more specific suggestions you'll need to post your 500-liner on a pastebin somewhere, so we can see the details of what is happening.</p> <p>EDIT: One thing you can do is try replacing all of the literal definitions like:</p> <pre><code>AddToken = Suppress(Literal("Add")| "A") </code></pre> <p>with </p> <pre><code>AddToken = oneOf("Add A").suppress() </code></pre> <p>This will substantially reduce the number of elements in your parser, so much fewer bits to be streamlined or pickled.</p> <p>This looks like an error:</p> <pre><code>digitLetter=Group(Word(DIGIT+"-"+DIGIT)|Word(digitMapLetter))("digitLetter") </code></pre> <p>There is no reason to repeat DIGIT string inside a Word definition.</p> <p>Don't create Words with whitespace in them, you are very likely to read beyond what you intended. Your use of LWSP also looks improper, since you are trying to do your own whitespace skipping. If you <em>must</em> do this, change <code>Word(WSP)</code> to <code>White(WSP)</code>. But really, why are you doing your own whitespace skipping?</p> <p>Change COMMENT to:</p> <pre><code>COMMENT = ';' + restOfLine + lineEnd </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload