Created
December 28, 2013 07:27
-
-
Save kobi/8156968 to your computer and use it in GitHub Desktop.
Answer to http://stackoverflow.com/q/3349999/7586 , with captures of A and Q.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
\A | |
# Push State A, Index = 0 | |
(?<StateIdBit0>) | |
(?<StateIdBit1>) | |
(?<StateIdBit2>) | |
(?<StateIdBit3>) | |
(?: | |
(?: | |
(?: | |
# When In State A, Index = 0 | |
(?<=(?=.{0}(?<=\A\k<StateIdBit0>))\A.*) | |
(?<=(?=.{0}(?<=\A\k<StateIdBit1>))\A.*) | |
(?<=(?=.{0}(?<=\A\k<StateIdBit2>))\A.*) | |
(?<=(?=.{0}(?<=\A\k<StateIdBit3>))\A.*) | |
(?<-StateIdBit0>) | |
(?<-StateIdBit1>) | |
(?<-StateIdBit2>) | |
(?<-StateIdBit3>) | |
(?<Start>) | |
# Push State AEnd, Index = 3 | |
(?<=(?=(?<StateIdBit0>.{1}))\A.*) | |
(?<=(?=(?<StateIdBit1>.{1}))\A.*) | |
(?<StateIdBit2>) | |
(?<StateIdBit3>) | |
# Push State A0Star, Index = 2 | |
(?<StateIdBit0>) | |
(?<=(?=(?<StateIdBit1>.{1}))\A.*) | |
(?<StateIdBit2>) | |
(?<StateIdBit3>) | |
) | |
| | |
(?: | |
# When In State A0, Index = 1 | |
(?<=(?=.{1}(?<=\A\k<StateIdBit0>))\A.*) | |
(?<=(?=.{0}(?<=\A\k<StateIdBit1>))\A.*) | |
(?<=(?=.{0}(?<=\A\k<StateIdBit2>))\A.*) | |
(?<=(?=.{0}(?<=\A\k<StateIdBit3>))\A.*) | |
(?<-StateIdBit0>) | |
(?<-StateIdBit1>) | |
(?<-StateIdBit2>) | |
(?<-StateIdBit3>) | |
(?: | |
, | |
| | |
# Push State Q, Index = 4 | |
(?<StateIdBit0>) | |
(?<StateIdBit1>) | |
(?<=(?=(?<StateIdBit2>.{1}))\A.*) | |
(?<StateIdBit3>) | |
) | |
) | |
| | |
(?: | |
# When In State A0Star, Index = 2 | |
(?<=(?=.{0}(?<=\A\k<StateIdBit0>))\A.*) | |
(?<=(?=.{1}(?<=\A\k<StateIdBit1>))\A.*) | |
(?<=(?=.{0}(?<=\A\k<StateIdBit2>))\A.*) | |
(?<=(?=.{0}(?<=\A\k<StateIdBit3>))\A.*) | |
(?<-StateIdBit0>) | |
(?<-StateIdBit1>) | |
(?<-StateIdBit2>) | |
(?<-StateIdBit3>) | |
(?: | |
# Push State A0Star, Index = 2 | |
(?<StateIdBit0>) | |
(?<=(?=(?<StateIdBit1>.{1}))\A.*) | |
(?<StateIdBit2>) | |
(?<StateIdBit3>) | |
# Push State A0, Index = 1 | |
(?<=(?=(?<StateIdBit0>.{1}))\A.*) | |
(?<StateIdBit1>) | |
(?<StateIdBit2>) | |
(?<StateIdBit3>) | |
| | |
) | |
) | |
| | |
(?: | |
# When In State AEnd, Index = 3 | |
(?<=(?=.{1}(?<=\A\k<StateIdBit0>))\A.*) | |
(?<=(?=.{1}(?<=\A\k<StateIdBit1>))\A.*) | |
(?<=(?=.{0}(?<=\A\k<StateIdBit2>))\A.*) | |
(?<=(?=.{0}(?<=\A\k<StateIdBit3>))\A.*) | |
(?<-StateIdBit0>) | |
(?<-StateIdBit1>) | |
(?<-StateIdBit2>) | |
(?<-StateIdBit3>) | |
(?<A-Start>) | |
) | |
| | |
(?: | |
# When In State Q, Index = 4 | |
(?<=(?=.{0}(?<=\A\k<StateIdBit0>))\A.*) | |
(?<=(?=.{0}(?<=\A\k<StateIdBit1>))\A.*) | |
(?<=(?=.{1}(?<=\A\k<StateIdBit2>))\A.*) | |
(?<=(?=.{0}(?<=\A\k<StateIdBit3>))\A.*) | |
(?<-StateIdBit0>) | |
(?<-StateIdBit1>) | |
(?<-StateIdBit2>) | |
(?<-StateIdBit3>) | |
(?<Start>) | |
(?: | |
\w(?<Q-Start>) | |
| | |
< | |
# Push State Q2Close, Index = 5 | |
(?<=(?=(?<StateIdBit0>.{1}))\A.*) | |
(?<StateIdBit1>) | |
(?<=(?=(?<StateIdBit2>.{1}))\A.*) | |
(?<StateIdBit3>) | |
# Push State A, Index = 0 | |
(?<StateIdBit0>) | |
(?<StateIdBit1>) | |
(?<StateIdBit2>) | |
(?<StateIdBit3>) | |
| | |
\[ | |
# Push State Q1Close, Index = 9 | |
(?<=(?=(?<StateIdBit0>.{1}))\A.*) | |
(?<StateIdBit1>) | |
(?<StateIdBit2>) | |
(?<=(?=(?<StateIdBit3>.{1}))\A.*) | |
# Push State QStar, Index = 6 | |
(?<StateIdBit0>) | |
(?<=(?=(?<StateIdBit1>.{1}))\A.*) | |
(?<=(?=(?<StateIdBit2>.{1}))\A.*) | |
(?<StateIdBit3>) | |
# Push State Q1Comma, Index = 7 | |
(?<=(?=(?<StateIdBit0>.{1}))\A.*) | |
(?<=(?=(?<StateIdBit1>.{1}))\A.*) | |
(?<=(?=(?<StateIdBit2>.{1}))\A.*) | |
(?<StateIdBit3>) | |
# Push State QStar, Index = 6 | |
(?<StateIdBit0>) | |
(?<=(?=(?<StateIdBit1>.{1}))\A.*) | |
(?<=(?=(?<StateIdBit2>.{1}))\A.*) | |
(?<StateIdBit3>) | |
# Push State Q1Semicolon, Index = 8 | |
(?<StateIdBit0>) | |
(?<StateIdBit1>) | |
(?<StateIdBit2>) | |
(?<=(?=(?<StateIdBit3>.{1}))\A.*) | |
# Push State A, Index = 0 | |
(?<StateIdBit0>) | |
(?<StateIdBit1>) | |
(?<StateIdBit2>) | |
(?<StateIdBit3>) | |
) | |
) | |
| | |
(?: | |
# When In State Q2Close, Index = 5 | |
(?<=(?=.{1}(?<=\A\k<StateIdBit0>))\A.*) | |
(?<=(?=.{0}(?<=\A\k<StateIdBit1>))\A.*) | |
(?<=(?=.{1}(?<=\A\k<StateIdBit2>))\A.*) | |
(?<=(?=.{0}(?<=\A\k<StateIdBit3>))\A.*) | |
(?<-StateIdBit0>) | |
(?<-StateIdBit1>) | |
(?<-StateIdBit2>) | |
(?<-StateIdBit3>) | |
>(?<Q-Start>) | |
) | |
| | |
(?: | |
# When In State QStar, Index = 6 | |
(?<=(?=.{0}(?<=\A\k<StateIdBit0>))\A.*) | |
(?<=(?=.{1}(?<=\A\k<StateIdBit1>))\A.*) | |
(?<=(?=.{1}(?<=\A\k<StateIdBit2>))\A.*) | |
(?<=(?=.{0}(?<=\A\k<StateIdBit3>))\A.*) | |
(?<-StateIdBit0>) | |
(?<-StateIdBit1>) | |
(?<-StateIdBit2>) | |
(?<-StateIdBit3>) | |
(?: | |
# Push State QStar, Index = 6 | |
(?<StateIdBit0>) | |
(?<=(?=(?<StateIdBit1>.{1}))\A.*) | |
(?<=(?=(?<StateIdBit2>.{1}))\A.*) | |
(?<StateIdBit3>) | |
# Push State Q, Index = 4 | |
(?<StateIdBit0>) | |
(?<StateIdBit1>) | |
(?<=(?=(?<StateIdBit2>.{1}))\A.*) | |
(?<StateIdBit3>) | |
| | |
) | |
) | |
| | |
(?: | |
# When In State Q1Comma, Index = 7 | |
(?<=(?=.{1}(?<=\A\k<StateIdBit0>))\A.*) | |
(?<=(?=.{1}(?<=\A\k<StateIdBit1>))\A.*) | |
(?<=(?=.{1}(?<=\A\k<StateIdBit2>))\A.*) | |
(?<=(?=.{0}(?<=\A\k<StateIdBit3>))\A.*) | |
(?<-StateIdBit0>) | |
(?<-StateIdBit1>) | |
(?<-StateIdBit2>) | |
(?<-StateIdBit3>) | |
,? | |
) | |
| | |
(?: | |
# When In State Q1Semicolon, Index = 8 | |
(?<=(?=.{0}(?<=\A\k<StateIdBit0>))\A.*) | |
(?<=(?=.{0}(?<=\A\k<StateIdBit1>))\A.*) | |
(?<=(?=.{0}(?<=\A\k<StateIdBit2>))\A.*) | |
(?<=(?=.{1}(?<=\A\k<StateIdBit3>))\A.*) | |
(?<-StateIdBit0>) | |
(?<-StateIdBit1>) | |
(?<-StateIdBit2>) | |
(?<-StateIdBit3>) | |
; | |
) | |
| | |
(?: | |
# When In State Q1Close, Index = 9 | |
(?<=(?=.{1}(?<=\A\k<StateIdBit0>))\A.*) | |
(?<=(?=.{0}(?<=\A\k<StateIdBit1>))\A.*) | |
(?<=(?=.{0}(?<=\A\k<StateIdBit2>))\A.*) | |
(?<=(?=.{1}(?<=\A\k<StateIdBit3>))\A.*) | |
(?<-StateIdBit0>) | |
(?<-StateIdBit1>) | |
(?<-StateIdBit2>) | |
(?<-StateIdBit3>) | |
\](?<Q-Start>) | |
) | |
|\Z | |
){10} | |
)+ | |
\Z | |
# Assert state stack is empty | |
# When the first stack is empty, all stacks should be empty. | |
(?(StateIdBit0)(?!)) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment