Skip to content

Instantly share code, notes, and snippets.

@conartist6
Last active March 28, 2022 18:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save conartist6/bec47897072b54884bae3db73e574235 to your computer and use it in GitHub Desktop.
Save conartist6/bec47897072b54884bae3db73e574235 to your computer and use it in GitHub Desktop.
Regex engine refactor diagrams

Before

                                                            ┌───────────────┐
                                                            │  Expression   │
                                                            │  root: true   │
                                                            │ globalIdx: 1  │
                                                            └───────┬───────┘
                                                          parentSeq │ ▲
                                                                    │ │ expr
                                  ┌──────────────┐          ┌───────┴─┴─────┐
                                  │    State     │          │    State      │
                                  │  type: cont  │          │ type: success │
                                  └──────────────┘          └───────┬───────┘
                                           ▲                        │ ▲
                                           │ state                  ▼ │ state
                           better ┌────────┴─────┐  better  ┌─────────┴─────┐
                          null ◄──┤   Sequence   │◄─────────┤   Sequence    │
                                  │              │  worse   │               │  worse
                                  └──────┬───────┴─────────►└───────┬───────┴──► null
                              parentExpr │ ▲             parentExpr │
                                         ▼ │ best                   │
                                  ┌────────┴─────┐ ◄────────────────┘
                                  │  Expression  │
                                  │              │
                                  └──────┬───────┘
                               parentSeq │ ▲
                                         │ │ expr
        ┌──────────────┐          ┌──────┴─┴─────┐
        │    State     │          │    State     │
        │  type: cont  │          │  type: expr  │
        └──────────────┘          └──────┬───────┘
                 ▲                       │ ▲
                 │ state                 ▼ │ state
 better ┌────────┴─────┐  better  ┌────────┴─────┐
null ◄──┤   Sequence   │◄─────────┤   Sequence   │
        │              │  worse   │              │  worse
        └──────┬───────┴─────────►└──────┬───────┴──► null
    parentExpr │ ▲            parentExpr │
               ▼ │ best                  │
        ┌────────┴─────┐ ◄───────────────┘
        │  Expression  │
        │  root: true  │
        │ globalIdx: 0 │
        └──────────────┘

After

                                     ┌─────────┐
                                     │ Matcher │
                                     └─────────┘
                                            ▲
                                            │ next           ┌───────────────┐
                            better ┌────────┴─────┐  better  │    Match      │
           ┌─────────┐     null ◄──┤   Sequence   │◄─────────┤ captures: ['']│
           │ Matcher │             │              │  worse   │ globalIdx: 1  │  worse
           └─────────┘             └──────┬───────┴─────────►└──────┬────────┴──► null
                  ▲                parent │ ▲                parent │
                  │ next                  ▼ │ best                  │
  better ┌────────┴─────┐  better  ┌────────┴─────┐ ◄───────────────┘
 null ◄──┤   Sequence   │◄─────────┤  Expression  │
         │              │  worse   │              │  worse
         └──────┬───────┴─────────►└──────┬───────┴──► null
         parent │ ▲                parent │
                ▼ │ best                  │
         ┌────────┴─────┐ ◄───────────────┘
         │    Match     │
         │ captures: [] │
         │ globalIdx: 0 │
         └────────┬─────┘
                  │ parent
                  ▼  null
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment