Q:

Parsing strings with stop tokens

Assuming a parser that accepts the letters a, b and c and any combination of the three.  I want to call a function with the substrings where the following conditions are met:

The substring starts with an a
The substring terminates before it encounters abc
The substring doesn't start with abc

So for example we have the following string:
bb cc ab bc cb bc abc bca bbb acc cbc ccc abc
I want to call the function with the strings ab bc cb and acc cbc ccc
I tried to implement this as follows:
import pyparsing as pp

x = pp. OneOrMore(pp. Word("abc") + ~pp. Literal("abc"))
x.addCondition(lambda tokens: tokens[0] ! = "abc")
x.addCondition(lambda tokens: tokens[0][0] == "a")
x.addParseAction(lambda tokens: print("x)", tokens))  # Print action for debugging

y = pp. Word("abc")
y.addParseAction(lambda tokens: print("y)", tokens))

text = pp. OneOrMore(x ^ y)
text.parseString("bb cc ab bc cb bc abc bca bbb acc cbc ccc abc")

But for some reason this stops 1 word too soon, here's the output:
y) ['bb']
y) ['cc']
x) ['ab', 'bc', 'bc']
y) ['cb']
y) ['abc']
y) ['bca']
y) ['bbb']
x) ['acc', 'cbc']
y) ['ccc']
y) ['abc']

Also, what if the abc stop token is a list of different strings that all would serve as a stop marker, how can I parse that? 
So something like:
stopStrings = ["abc", "bca"]
x = pp. OneOrMore(pp. Word("abc") + ~pp. OneOf(stopStrings))
...

Hopefuly this makes it clear and thanks for your help! 

A:

I think I've got it.  This SO question/answer was very helpful.  Bill Bell's answer helped me to get more than 1 termination string. 
stop_strings = ["abc", "acb"]
stop_tokens = pp. Or([pp. Literal(sub) for sub in stop_strings])

x = pp. OneOrMore(~stop_tokens + pp. Word("abc")) + pp. Optional(stop_tokens.suppress())
x.addCondition(lambda tokens: tokens[0][0] == "a")
x.addParseAction(lambda tokens: print("x)", tokens))  # Print action for debugging

y = pp. Word("abc")
y.addParseAction(lambda tokens: print("y)", tokens))

text = pp. OneOrMore(x ^ y)
text.parseString("bb cc acb ab cb abc bca bbb acc cbc ccc")

output:
y) ['bb']
y) ['cc']
y) ['acb']
x) ['ab', 'cb']
y) ['bca']
y) ['bbb']
x) ['acc', 'cbc', 'ccc']

