I am using pyparsing to write a small grammar, but I'm running into an issue where the definition of one variable requires me to use another variable that itself requires the first one, etc. This answer helped me some, since I am working with Prolog strings, but it didn't seem to address the issue I'm having.
Working example, without the issue
import pyparsing as pp
# grammar
argument = pp.Word(pp.alphas)
pred = pp.Word(pp.alphas) + (pp.Suppress('(') + pp.delimitedList(argument) + pp.Suppress(')'))
# tests
test_string1="func(x, y)"
test_result1 = pred.parse_string(test_string1)
print(test_result1.dump())
Broken example, with the issue
import pyparsing as pp
# grammar
argument = pp.Word(pp.alphas) | pred
pred = pp.Word(pp.alphas) + (pp.Suppress('(') + pp.delimitedList(argument) + pp.Suppress(')'))
# tests
test_string2="func(func(x), y)"
test_result2 = pred.parse_string(test_string2)
print(test_result2.dump())
The idea is that a predication might have as one of its arguments another predication which itself might have more arguments or predications etc. However, in the first line of the grammar in the broken example, the code breaks because it is trying to reference pred, which hasn't been assigned yet. I can switch the order, but the problem will persist, because pred requires the usage of argument since a pred can have an argument.
On paper I think it should work, since eventually it would terminate, but because of the fact that I have to declare things in a certain order it doesn't seem to work in code form.
