R
R
Ruslan2021-01-15 10:48:04
Python
Ruslan, 2021-01-15 10:48:04

Can pyparsing rules be written as a string to a variable?

Here is a simple parsing rule:

grammar = pp.Word(pp.alphas).suppress() + pp.Optional(':') + pp.Word(pp.nums)('code')

I would like to make it a string, like this:
grammar = '{{Suppress:(W:(ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz)) [":"]} W:(0123456789)}'

The task is such that I get the parsing rules via REST, of course, you can write it as program code to a file and connect it as a module via import, but this is dangerous. Malicious code may arrive, I want to avoid this.

Or maybe there are some ideas how to get out of this situation?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
Ruslan, 2021-01-19
@Tiasar

EBNF solution to this issue

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question