PyParsing: What does Combine () do?

What's the difference between:

foo = TOKEN1 + TOKEN2

and

foo = Combine(TOKEN1 + TOKEN2)

Thank.

UPDATE . Based on my experiments, it seems that Combine()for terminals where you are trying to create an expression to match, while plain +for non-terminals, But I'm not sure.

+5
source share
1 answer

The plant has 2 effects:

  • it combines all tokens into one line

  • this requires matching markers to be contiguous without intermediate spaces

If you create an expression like

realnum = Word(nums) + "." + Word(nums)

Then it realnum.parseString("3.14")will return a list of 3 tokens: leading "3", "." and the final "14". But if you wrap it in Combine, as in:

realnum = Combine(Word(nums) + "." + Word(nums))

realnum.parseString("3.14") '3.14' ( float, ). Combine , , "3.14" " 3. 14. ".

+13

All Articles