Created
December 17, 2013 20:47
-
-
Save kobi/8012361 to your computer and use it in GitHub Desktop.
Answer to http://stackoverflow.com/q/3349999/7586
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>) | |
(?: | |
(?: | |
(?: | |
# When In State A, Index = 0 | |
(?<=(?=.{0}(?<=\A\k<StateIdBit0>))\A.*) | |
(?<=(?=.{0}(?<=\A\k<StateIdBit1>))\A.*) | |
(?<=(?=.{0}(?<=\A\k<StateIdBit2>))\A.*) | |
(?<-StateIdBit0>) | |
(?<-StateIdBit1>) | |
(?<-StateIdBit2>) | |
(?: | |
# Push State A, Index = 0 | |
(?<StateIdBit0>) | |
(?<StateIdBit1>) | |
(?<StateIdBit2>) | |
(?: | |
, | |
| | |
# Push State Q, Index = 1 | |
(?<=(?=(?<StateIdBit0>.{1}))\A.*) | |
(?<StateIdBit1>) | |
(?<StateIdBit2>) | |
) | |
| | |
) | |
) | |
| | |
(?: | |
# When In State Q, Index = 1 | |
(?<=(?=.{1}(?<=\A\k<StateIdBit0>))\A.*) | |
(?<=(?=.{0}(?<=\A\k<StateIdBit1>))\A.*) | |
(?<=(?=.{0}(?<=\A\k<StateIdBit2>))\A.*) | |
(?<-StateIdBit0>) | |
(?<-StateIdBit1>) | |
(?<-StateIdBit2>) | |
(?: | |
\w | |
| | |
< | |
# Push State Q2Close, Index = 2 | |
(?<StateIdBit0>) | |
(?<=(?=(?<StateIdBit1>.{1}))\A.*) | |
(?<StateIdBit2>) | |
# Push State A, Index = 0 | |
(?<StateIdBit0>) | |
(?<StateIdBit1>) | |
(?<StateIdBit2>) | |
| | |
\[ | |
# Push State Q1Close, Index = 6 | |
(?<StateIdBit0>) | |
(?<=(?=(?<StateIdBit1>.{1}))\A.*) | |
(?<=(?=(?<StateIdBit2>.{1}))\A.*) | |
# Push State QStar, Index = 3 | |
(?<=(?=(?<StateIdBit0>.{1}))\A.*) | |
(?<=(?=(?<StateIdBit1>.{1}))\A.*) | |
(?<StateIdBit2>) | |
# Push State Q1Comma, Index = 4 | |
(?<StateIdBit0>) | |
(?<StateIdBit1>) | |
(?<=(?=(?<StateIdBit2>.{1}))\A.*) | |
# Push State QStar, Index = 3 | |
(?<=(?=(?<StateIdBit0>.{1}))\A.*) | |
(?<=(?=(?<StateIdBit1>.{1}))\A.*) | |
(?<StateIdBit2>) | |
# Push State Q1Semicolon, Index = 5 | |
(?<=(?=(?<StateIdBit0>.{1}))\A.*) | |
(?<StateIdBit1>) | |
(?<=(?=(?<StateIdBit2>.{1}))\A.*) | |
# Push State A, Index = 0 | |
(?<StateIdBit0>) | |
(?<StateIdBit1>) | |
(?<StateIdBit2>) | |
) | |
) | |
| | |
(?: | |
# When In State Q2Close, Index = 2 | |
(?<=(?=.{0}(?<=\A\k<StateIdBit0>))\A.*) | |
(?<=(?=.{1}(?<=\A\k<StateIdBit1>))\A.*) | |
(?<=(?=.{0}(?<=\A\k<StateIdBit2>))\A.*) | |
(?<-StateIdBit0>) | |
(?<-StateIdBit1>) | |
(?<-StateIdBit2>) | |
> | |
) | |
| | |
(?: | |
# When In State QStar, Index = 3 | |
(?<=(?=.{1}(?<=\A\k<StateIdBit0>))\A.*) | |
(?<=(?=.{1}(?<=\A\k<StateIdBit1>))\A.*) | |
(?<=(?=.{0}(?<=\A\k<StateIdBit2>))\A.*) | |
(?<-StateIdBit0>) | |
(?<-StateIdBit1>) | |
(?<-StateIdBit2>) | |
(?: | |
# Push State QStar, Index = 3 | |
(?<=(?=(?<StateIdBit0>.{1}))\A.*) | |
(?<=(?=(?<StateIdBit1>.{1}))\A.*) | |
(?<StateIdBit2>) | |
# Push State Q, Index = 1 | |
(?<=(?=(?<StateIdBit0>.{1}))\A.*) | |
(?<StateIdBit1>) | |
(?<StateIdBit2>) | |
| | |
) | |
) | |
| | |
(?: | |
# When In State Q1Comma, Index = 4 | |
(?<=(?=.{0}(?<=\A\k<StateIdBit0>))\A.*) | |
(?<=(?=.{0}(?<=\A\k<StateIdBit1>))\A.*) | |
(?<=(?=.{1}(?<=\A\k<StateIdBit2>))\A.*) | |
(?<-StateIdBit0>) | |
(?<-StateIdBit1>) | |
(?<-StateIdBit2>) | |
,? | |
) | |
| | |
(?: | |
# When In State Q1Semicolon, Index = 5 | |
(?<=(?=.{1}(?<=\A\k<StateIdBit0>))\A.*) | |
(?<=(?=.{0}(?<=\A\k<StateIdBit1>))\A.*) | |
(?<=(?=.{1}(?<=\A\k<StateIdBit2>))\A.*) | |
(?<-StateIdBit0>) | |
(?<-StateIdBit1>) | |
(?<-StateIdBit2>) | |
; | |
) | |
| | |
(?: | |
# When In State Q1Close, Index = 6 | |
(?<=(?=.{0}(?<=\A\k<StateIdBit0>))\A.*) | |
(?<=(?=.{1}(?<=\A\k<StateIdBit1>))\A.*) | |
(?<=(?=.{1}(?<=\A\k<StateIdBit2>))\A.*) | |
(?<-StateIdBit0>) | |
(?<-StateIdBit1>) | |
(?<-StateIdBit2>) | |
\] | |
) | |
|\Z | |
){7} | |
)+ | |
\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