Slide 1

Slide 1 text

RegExp. exec(‘js’) @jviereck JSConf.EU 2013

Slide 2

Slide 2 text

/a/ /.?/ /(foo|bar)+/ /(^.*a)+/ /([a-zA-Z]\s\d)+/ /jsconf\.eu/ /^abc$/ /(?=Hello)\sWorld/ /.*?/ /[^]/

Slide 3

Slide 3 text

/a/ /.?/ /(foo|bar)+/ /(^.*a)+/ /([a-zA-Z]\s\d)+/ /jsconf\.eu/ /^abc$/ /(?=Hello)\sWorld/ /.*?/ /[^]/ They look cute

Slide 4

Slide 4 text

/a/ /.?/ /(foo|bar)+/ /(^.*a)+/ /([a-zA-Z]\s\d)+/ /jsconf\.eu/ /^abc$/ /(?=Hello)\sWorld/ /.*?/ /[^]/ They look cute But they are hard to get right :(

Slide 5

Slide 5 text

“Why are you doing this?”

Slide 6

Slide 6 text

Motivation • Debug-ability • Writing JIT compiler • Wanted to present at JSConf.EU :)

Slide 7

Slide 7 text

No content

Slide 8

Slide 8 text

No content

Slide 9

Slide 9 text

Demo http://jviereck.github.io/regexp.js/

Slide 10

Slide 10 text

Overview • ParseTree • NodeList • Matcher • RegExpJS object itself • Writing a JIT in a JIT • Conclusion

Slide 11

Slide 11 text

ParseTree 4

Slide 12

Slide 12 text

ParseTree • ParseTree: • structural representation of a string • described by grammar rules • Highlevel: • RegExp =[Parser]=> ParseTree

Slide 13

Slide 13 text

Example: /(ab|c)/ ParseTree

Slide 14

Slide 14 text

Example: /(ab|c)/ ParseTree Group

Slide 15

Slide 15 text

Disjunction Example: /(ab|c)/ ParseTree Group

Slide 16

Slide 16 text

Alternative Disjunction Example: /(ab|c)/ ParseTree Group

Slide 17

Slide 17 text

Char: “a” Term Alternative Disjunction Example: /(ab|c)/ ParseTree Group

Slide 18

Slide 18 text

Char: “b” Term Char: “a” Term Alternative Disjunction Example: /(ab|c)/ ParseTree Group

Slide 19

Slide 19 text

Char: “b” Term Char: “a” Term Alternative Alternative Disjunction Example: /(ab|c)/ ParseTree Group

Slide 20

Slide 20 text

Char: “c” Term Char: “b” Term Char: “a” Term Alternative Alternative Disjunction Example: /(ab|c)/ ParseTree Group

Slide 21

Slide 21 text

Parser • Handwritten - LL(?) • Only basic error handling/messages • Uses RegExp iteself << replace them ;) • Emits “useful” information

Slide 22

Slide 22 text

Useful information { "type": "ref", "ref": 1, "from": 5, "to": 7, "raw": "\\1" } (a|b)\1

Slide 23

Slide 23 text

No content

Slide 24

Slide 24 text

No content

Slide 25

Slide 25 text

No content

Slide 26

Slide 26 text

No content

Slide 27

Slide 27 text

/[a-]/.exec(‘-’): ✓

Slide 28

Slide 28 text

/[a-]/.exec(‘-’): ✓ /[a-b]/.exec(‘-’): ✗

Slide 29

Slide 29 text

Notes on parsing • Should have gone with parser generator? • Mostly follows the spec • Addition: added handling for /]/ • Parsing numbers needs an extra slide...

Slide 30

Slide 30 text

Number parsing

Slide 31

Slide 31 text

Number parsing • parseDecimalEscape(...)

Slide 32

Slide 32 text

Number parsing • parseDecimalEscape(...) • /(a)(b)\2/ ‏ reference

Slide 33

Slide 33 text

Number parsing • parseDecimalEscape(...) • /(a)(b)\2/ ‏ reference • /(a)(b)\71/ ‏ NOT reference

Slide 34

Slide 34 text

Number parsing • parseDecimalEscape(...) • /(a)(b)\2/ ‏ reference • /(a)(b)\71/ ‏ NOT reference • IF: octal number, parseInt(71,8)

Slide 35

Slide 35 text

Number parsing • parseDecimalEscape(...) • /(a)(b)\2/ ‏ reference • /(a)(b)\71/ ‏ NOT reference • IF: octal number, parseInt(71,8) • /(a)(b)\91/ ‏ NOT reference

Slide 36

Slide 36 text

Number parsing • parseDecimalEscape(...) • /(a)(b)\2/ ‏ reference • /(a)(b)\71/ ‏ NOT reference • IF: octal number, parseInt(71,8) • /(a)(b)\91/ ‏ NOT reference • ELSE: Ignore slash, match /91/

Slide 37

Slide 37 text

Number parsing • parseDecimalEscape(...) • /(a)(b)\2/ ‏ reference • /(a)(b)\71/ ‏ NOT reference • IF: octal number, parseInt(71,8) • /(a)(b)\91/ ‏ NOT reference • ELSE: Ignore slash, match /91/ V8 at least...

Slide 38

Slide 38 text

NodeList 8

Slide 39

Slide 39 text

• ParseTree ➡ NodeList • Data structure Matcher uses NodeList

Slide 40

Slide 40 text

• ParseTree ➡ NodeList • Data structure Matcher uses NodeList Example: /ab/

Slide 41

Slide 41 text

• ParseTree ➡ NodeList • Data structure Matcher uses NodeList Data: “a” CHAR Example: /ab/

Slide 42

Slide 42 text

CHAR Data: “b” • ParseTree ➡ NodeList • Data structure Matcher uses NodeList Data: “a” CHAR Example: /ab/

Slide 43

Slide 43 text

DONE CHAR Data: “b” • ParseTree ➡ NodeList • Data structure Matcher uses NodeList Data: “a” CHAR Example: /ab/

Slide 44

Slide 44 text

Example: /(ab|c)*c/

Slide 45

Slide 45 text

Example: /(ab|c)*c/ Id: 1 Min: 0 Max: ? REPEAT

Slide 46

Slide 46 text

Example: /(ab|c)*c/ Index: 1 BEGIN_GROUP Id: 1 Min: 0 Max: ? REPEAT

Slide 47

Slide 47 text

ALTR Example: /(ab|c)*c/ Index: 1 BEGIN_GROUP Id: 1 Min: 0 Max: ? REPEAT

Slide 48

Slide 48 text

Data: “a” CHAR ALTR Example: /(ab|c)*c/ Index: 1 BEGIN_GROUP Id: 1 Min: 0 Max: ? REPEAT

Slide 49

Slide 49 text

Data: “b” CHAR Data: “a” CHAR ALTR Example: /(ab|c)*c/ Index: 1 BEGIN_GROUP Id: 1 Min: 0 Max: ? REPEAT

Slide 50

Slide 50 text

Data: “b” CHAR Data: “a” CHAR CHAR Data: “c” ALTR Example: /(ab|c)*c/ Index: 1 BEGIN_GROUP Id: 1 Min: 0 Max: ? REPEAT

Slide 51

Slide 51 text

JOIN Data: “b” CHAR Data: “a” CHAR CHAR Data: “c” ALTR Example: /(ab|c)*c/ Index: 1 BEGIN_GROUP Id: 1 Min: 0 Max: ? REPEAT

Slide 52

Slide 52 text

Index: 1 END_GROUP JOIN Data: “b” CHAR Data: “a” CHAR CHAR Data: “c” ALTR Example: /(ab|c)*c/ Index: 1 BEGIN_GROUP Id: 1 Min: 0 Max: ? REPEAT

Slide 53

Slide 53 text

Index: 1 END_GROUP JOIN Data: “b” CHAR Data: “a” CHAR CHAR Data: “c” ALTR Example: /(ab|c)*c/ Index: 1 BEGIN_GROUP Id: 1 Min: 0 Max: ? REPEAT

Slide 54

Slide 54 text

Index: 1 END_GROUP JOIN Data: “b” CHAR Data: “a” CHAR CHAR Data: “c” ALTR Data: “c” CHAR Example: /(ab|c)*c/ Index: 1 BEGIN_GROUP Id: 1 Min: 0 Max: ? REPEAT

Slide 55

Slide 55 text

Index: 1 END_GROUP JOIN Data: “b” CHAR Data: “a” CHAR CHAR Data: “c” ALTR DONE Data: “c” CHAR Example: /(ab|c)*c/ Index: 1 BEGIN_GROUP Id: 1 Min: 0 Max: ? REPEAT

Slide 56

Slide 56 text

Index: 1 END_GROUP JOIN Data: “b” CHAR Data: “a” CHAR CHAR Data: “c” ALTR DONE Data: “c” CHAR Example: /(ab|c)*c/ Index: 1 BEGIN_GROUP Id: 1 Min: 0 Max: ? REPEAT Char: “c” Term Char: “b” Term Char: “a” Term Alternative Alternative Disjunction Group

Slide 57

Slide 57 text

NodeList • Look complicated to build • Easy by walking over ParseTree • Combine one node after the other

Slide 58

Slide 58 text

NodeList: \s

Slide 59

Slide 59 text

NodeList: \s • \s: matches whitespace OR line terminator

Slide 60

Slide 60 text

NodeList: \s • \s: matches whitespace OR line terminator • stolen functions from Esprima :)

Slide 61

Slide 61 text

Matcher 12

Slide 62

Slide 62 text

Matcher • Does the actual RegExp matching • Matcher(state, nodeList) • state = { string, index, traces, counters, ...} • Tries all possibilities till match OR no progress • Calls Matcher(state’, nodeList’) recursively • If trace fails ➠ return function = backtracking

Slide 63

Slide 63 text

Matcher

Slide 64

Slide 64 text

Matcher • s = new State(‘abc’)

Slide 65

Slide 65 text

Matcher • s = new State(‘abc’) • match(s, /a(b|c)d/)

Slide 66

Slide 66 text

Matcher • s = new State(‘abc’) • match(s, /a(b|c)d/) a b c d a b d ^

Slide 67

Slide 67 text

Matcher • s = new State(‘abc’) • match(s, /a(b|c)d/) • test(s, /a/): ✓ a b c d a b d ^

Slide 68

Slide 68 text

Matcher • s = new State(‘abc’) • match(s, /a(b|c)d/) • test(s, /a/): ✓ a b c d a b d ^

Slide 69

Slide 69 text

Matcher • s = new State(‘abc’) • match(s, /a(b|c)d/) • test(s, /a/): ✓ • try /b/: match(s’, /(b|c)d/) a b c d a b d ^

Slide 70

Slide 70 text

Matcher • s = new State(‘abc’) • match(s, /a(b|c)d/) • test(s, /a/): ✓ • try /b/: match(s’, /(b|c)d/) a b c d a b d ^ “ s’=s.clone()

Slide 71

Slide 71 text

Matcher • s = new State(‘abc’) • match(s, /a(b|c)d/) • test(s, /a/): ✓ • try /b/: match(s’, /(b|c)d/) a b c d a b d ^ “ s’=s.clone()

Slide 72

Slide 72 text

Matcher • s = new State(‘abc’) • match(s, /a(b|c)d/) • test(s, /a/): ✓ • try /b/: match(s’, /(b|c)d/) • test(‘b’, /b/): ✓ a b c d a b d ^ “ s’=s.clone()

Slide 73

Slide 73 text

Matcher • s = new State(‘abc’) • match(s, /a(b|c)d/) • test(s, /a/): ✓ • try /b/: match(s’, /(b|c)d/) • test(‘b’, /b/): ✓ a b c d a b d ^ “ s’=s.clone()

Slide 74

Slide 74 text

Matcher • s = new State(‘abc’) • match(s, /a(b|c)d/) • test(s, /a/): ✓ • try /b/: match(s’, /(b|c)d/) • test(‘b’, /b/): ✓ a b c d a b d ^ “ s’=s.clone()

Slide 75

Slide 75 text

Matcher • s = new State(‘abc’) • match(s, /a(b|c)d/) • test(s, /a/): ✓ • try /b/: match(s’, /(b|c)d/) • test(‘b’, /b/): ✓ • test(‘d’, /d/): ✓ a b c d a b d ^ “ s’=s.clone()

Slide 76

Slide 76 text

Matcher • s = new State(‘abc’) • match(s, /a(b|c)d/) • test(s, /a/): ✓ • try /b/: match(s’, /(b|c)d/) • test(‘b’, /b/): ✓ • test(‘d’, /d/): ✓ a b c d a b d ^ “ s’=s.clone()

Slide 77

Slide 77 text

Matcher • s = new State(‘abc’) • match(s, /a(b|c)d/) • test(s, /a/): ✓ • try /b/: match(s’, /(b|c)d/) • test(‘b’, /b/): ✓ • test(‘d’, /d/): ✓ • DONE: ✓ a b c d a b d ^ “ s’=s.clone()

Slide 78

Slide 78 text

No content

Slide 79

Slide 79 text

• s = new State(‘abc’);

Slide 80

Slide 80 text

• s = new State(‘abc’); • match(s, /a(b|c)d/) a c d ^ a b c d

Slide 81

Slide 81 text

• s = new State(‘abc’); • match(s, /a(b|c)d/) a c d ^ a b c d

Slide 82

Slide 82 text

• s = new State(‘abc’); • match(s, /a(b|c)d/) • test(‘a’, /a/): ✓ a c d ^ a b c d

Slide 83

Slide 83 text

• s = new State(‘abc’); • match(s, /a(b|c)d/) • test(‘a’, /a/): ✓ a c d ^ a b c d

Slide 84

Slide 84 text

• s = new State(‘abc’); • match(s, /a(b|c)d/) • test(‘a’, /a/): ✓ • try /b/: match(s’, /bd/) a c d ^ a b c d

Slide 85

Slide 85 text

• s = new State(‘abc’); • match(s, /a(b|c)d/) • test(‘a’, /a/): ✓ • try /b/: match(s’, /bd/) a c d ^ a b c d “ s’=s.clone()

Slide 86

Slide 86 text

• s = new State(‘abc’); • match(s, /a(b|c)d/) • test(‘a’, /a/): ✓ • try /b/: match(s’, /bd/) • test(s’, /b/): ✗ a c d ^ a b c d “ s’=s.clone()

Slide 87

Slide 87 text

• s = new State(‘abc’); • match(s, /a(b|c)d/) • test(‘a’, /a/): ✓ • try /b/: match(s’, /bd/) • test(s’, /b/): ✗ ‏ Backtrack a c d ^ a b c d “ s’=s.clone()

Slide 88

Slide 88 text

• s = new State(‘abc’); • match(s, /a(b|c)d/) • test(‘a’, /a/): ✓ • try /b/: match(s’, /bd/) • test(s’, /b/): ✗ ‏ Backtrack a c d ^ a b c d “ s’=s.clone()

Slide 89

Slide 89 text

• s = new State(‘abc’); • match(s, /a(b|c)d/) • test(‘a’, /a/): ✓ • try /b/: match(s’, /bd/) • test(s’, /b/): ✗ ‏ Backtrack • try /c/: match(s’’, /(b|c)d/) a c d ^ a b c d “ s’=s.clone()

Slide 90

Slide 90 text

• s = new State(‘abc’); • match(s, /a(b|c)d/) • test(‘a’, /a/): ✓ • try /b/: match(s’, /bd/) • test(s’, /b/): ✗ ‏ Backtrack • try /c/: match(s’’, /(b|c)d/) a c d ^ a b c d “ s’=s.clone()

Slide 91

Slide 91 text

• s = new State(‘abc’); • match(s, /a(b|c)d/) • test(‘a’, /a/): ✓ • try /b/: match(s’, /bd/) • test(s’, /b/): ✗ ‏ Backtrack • try /c/: match(s’’, /(b|c)d/) • test(‘c’, /c/): ✓ a c d ^ a b c d “ s’=s.clone()

Slide 92

Slide 92 text

• s = new State(‘abc’); • match(s, /a(b|c)d/) • test(‘a’, /a/): ✓ • try /b/: match(s’, /bd/) • test(s’, /b/): ✗ ‏ Backtrack • try /c/: match(s’’, /(b|c)d/) • test(‘c’, /c/): ✓ a c d ^ a b c d “ s’=s.clone()

Slide 93

Slide 93 text

• s = new State(‘abc’); • match(s, /a(b|c)d/) • test(‘a’, /a/): ✓ • try /b/: match(s’, /bd/) • test(s’, /b/): ✗ ‏ Backtrack • try /c/: match(s’’, /(b|c)d/) • test(‘c’, /c/): ✓ a c d ^ a b c d “ s’=s.clone()

Slide 94

Slide 94 text

• s = new State(‘abc’); • match(s, /a(b|c)d/) • test(‘a’, /a/): ✓ • try /b/: match(s’, /bd/) • test(s’, /b/): ✗ ‏ Backtrack • try /c/: match(s’’, /(b|c)d/) • test(‘c’, /c/): ✓ • test(‘d’, /d/): ✓ a c d ^ a b c d “ s’=s.clone()

Slide 95

Slide 95 text

• s = new State(‘abc’); • match(s, /a(b|c)d/) • test(‘a’, /a/): ✓ • try /b/: match(s’, /bd/) • test(s’, /b/): ✗ ‏ Backtrack • try /c/: match(s’’, /(b|c)d/) • test(‘c’, /c/): ✓ • test(‘d’, /d/): ✓ a c d ^ a b c d “ s’=s.clone()

Slide 96

Slide 96 text

• s = new State(‘abc’); • match(s, /a(b|c)d/) • test(‘a’, /a/): ✓ • try /b/: match(s’, /bd/) • test(s’, /b/): ✗ ‏ Backtrack • try /c/: match(s’’, /(b|c)d/) • test(‘c’, /c/): ✓ • test(‘d’, /d/): ✓ • DONE a c d ^ a b c d “ s’=s.clone()

Slide 97

Slide 97 text

• s = new State(‘abc’); • match(s, /a(b|c)d/) • test(‘a’, /a/): ✓ • try /b/: match(s’, /bd/) • test(s’, /b/): ✗ ‏ Backtrack • try /c/: match(s’’, /(b|c)d/) • test(‘c’, /c/): ✓ • test(‘d’, /d/): ✓ • DONE record the trace along the way a c d ^ a b c d “ s’=s.clone()

Slide 98

Slide 98 text

Matcher pitfalls • /(a(b)*c)*/ • need to reset the matches of (b)* to null • also need to reset repeat counter • /()*a/ • Infinity matches ➡ Loop detection!

Slide 99

Slide 99 text

RegExpJS Object 16

Slide 100

Slide 100 text

re = new RegExpJS(‘abc’, ‘ig’); re.exec(‘abc’) re.test(‘abc’) Sorry, nothing on the String.prototype...

Slide 101

Slide 101 text

RegExpJS Object • So far: • created ParseTree • created NodeList • have Matcher(string, parseNodes) • Needed: • something to play with :) • actual JS object similar to RegExp object

Slide 102

Slide 102 text

RegExpJS Object • first attempt: • RegExpJS(regExp).exec = (str) => { regExp = this.regExp; nodes = buildNodeList(parse(regExp)); return match(str, nodes); } • RegExpJS(/abc/).exec(‘abc’): ✓ • RegExpJS(/abc/).exec(‘JSConf abc’): ✗

Slide 103

Slide 103 text

Match arbitrary start position

Slide 104

Slide 104 text

Match arbitrary start position • easy fix:

Slide 105

Slide 105 text

Match arbitrary start position • easy fix: • wrap the nodeList by “fake loop”

Slide 106

Slide 106 text

Match arbitrary start position • easy fix: • wrap the nodeList by “fake loop” • e.g: /abc/

Slide 107

Slide 107 text

Match arbitrary start position • easy fix: • wrap the nodeList by “fake loop” • e.g: /abc/ • /abc/ ➠ /[^]*?(abc)/

Slide 108

Slide 108 text

Match arbitrary start position • easy fix: • wrap the nodeList by “fake loop” • e.g: /abc/ • /abc/ ➠ /[^]*?(abc)/ • assign the first group index 0

Slide 109

Slide 109 text

Match arbitrary start position • easy fix: • wrap the nodeList by “fake loop” • e.g: /abc/ • /abc/ ➠ /[^]*?(abc)/ • assign the first group index 0 • /abc/.exec(‘JSConf abc’): ✓

Slide 110

Slide 110 text

Match arbitrary start position • easy fix: • wrap the nodeList by “fake loop” • e.g: /abc/ • /abc/ ➠ /[^]*?(abc)/ • assign the first group index 0 • /abc/.exec(‘JSConf abc’): ✓ • problem: V8 stack size not large enough

Slide 111

Slide 111 text

How about flags?

Slide 112

Slide 112 text

How about flags? •multiline flag: /foo/m

Slide 113

Slide 113 text

How about flags? •multiline flag: /foo/m • affects only /^/ and /$/ • easy to implement

Slide 114

Slide 114 text

How about flags? •multiline flag: /foo/m • affects only /^/ and /$/ • easy to implement •global flag: /foo/g

Slide 115

Slide 115 text

How about flags? •multiline flag: /foo/m • affects only /^/ and /$/ • easy to implement •global flag: /foo/g • repeat from last position • okay’isch to implement

Slide 116

Slide 116 text

How about flags? •ignore-case flag: /foo/i • not just str.toUpperCase() • e.g. if turns one character into two, then use the input character • fun with ranges: • /[a-}]/ ➠ /[a-}A-Z]/

Slide 117

Slide 117 text

No content

Slide 118

Slide 118 text

More fun

Slide 119

Slide 119 text

More fun • Spec requirement: • Call `ToString(...)`, `ToNumber(...)` on input • E.g. • str = { toString: function() { return false; } } • /LS/i.exec(str) ➡ returns?

Slide 120

Slide 120 text

More fun • Spec requirement: • Call `ToString(...)`, `ToNumber(...)` on input • E.g. • str = { toString: function() { return false; } } • /LS/i.exec(str) ➡ returns? • /LS/i.exec(str) === “ls”

Slide 121

Slide 121 text

so, RegExpJS object • There is more “fun” stuff required to get the ECMA test suite to pass • index.js (implements RegExpJS) ~240 LOC

Slide 122

Slide 122 text

JIT (just in time compiler) 20

Slide 123

Slide 123 text

JIT (just in time compiler) :) :) :) 20

Slide 124

Slide 124 text

JIT Overview • Convert RegExp ➡ JS-Code • Have a RegExp-JIT running in JS-JIT • Idea: match input faster • use state machine / finite automata • only support a subset of RegExp • ... but these very fast & efficient

Slide 125

Slide 125 text

Supported features • All features, except: • groups matches, lookahead - only (?: ) • no backreferences • only greedy repetitions • Not supported yet • repetitions, ... (under construction) • (written in three evenings hacks ;) )

Slide 126

Slide 126 text

this.name = id + ': NFA-States={' + nfaStates.map(function(state) {return state.name}).join(', ') + '} '; I really mean three hack evenings!

Slide 127

Slide 127 text

RegExp:

Slide 128

Slide 128 text

RegExp: /ab/

Slide 129

Slide 129 text

RegExp: /ab/ NFA:

Slide 130

Slide 130 text

RegExp: /ab/ NFA: 0 1 4 a b 2 ε

Slide 131

Slide 131 text

RegExp: NFA: 0 1 4 a b 2 ε

Slide 132

Slide 132 text

RegExp: NFA: 0 1 4 a b 2 ε /ab|a/

Slide 133

Slide 133 text

RegExp: NFA: 0 1 4 a b 2 ε 3 a ε /ab|a/

Slide 134

Slide 134 text

RegExp: NFA: 0 1 4 a b 2 ε 3 a ε DFA: /ab|a/

Slide 135

Slide 135 text

RegExp: NFA: 0 1 4 a b 2 ε 3 a ε DFA: 0 1 a b 2 /ab|a/

Slide 136

Slide 136 text

JIT Implementation • Convert RegExp to state machine • RegExp • Non-deterministic Finite Automata (NFA) • Deterministic Finite Automata (DFA) • CodeGen ➠ JavaScript code

Slide 137

Slide 137 text

/ab/ 0 1 2 a b 23

Slide 138

Slide 138 text

alphabet: Σ={a, b} /ab/ 0 1 2 a b 23

Slide 139

Slide 139 text

What alphabet to use?

Slide 140

Slide 140 text

What alphabet to use? • e.g.: ranges like /[a-\u0777]/

Slide 141

Slide 141 text

What alphabet to use? • e.g.: ranges like /[a-\u0777]/ • use one transition per character

Slide 142

Slide 142 text

What alphabet to use? • e.g.: ranges like /[a-\u0777]/ • use one transition per character 0 1 a, b, c, ...

Slide 143

Slide 143 text

What alphabet to use? • e.g.: ranges like /[a-\u0777]/ • use one transition per character • better solution? 0 1 a, b, c, ...

Slide 144

Slide 144 text

Alphabet Classes

Slide 145

Slide 145 text

Alphabet Classes • Example: /0[1-9]/

Slide 146

Slide 146 text

Alphabet Classes • Example: /0[1-9]/ 0 1 2 0 1...9

Slide 147

Slide 147 text

Alphabet Classes • Example: /0[1-9]/ 0 1 2 0 1...9 alphabet: Σ={0, 1, 2, ..., 9}

Slide 148

Slide 148 text

Alphabet Classes • Example: /0[1-9]/ • before /ab/ 0 1 2 0 1...9 alphabet: Σ={0, 1, 2, ..., 9}

Slide 149

Slide 149 text

Alphabet Classes • Example: /0[1-9]/ • before /ab/ 0 1 2 a b 0 1 2 0 1...9 alphabet: Σ={0, 1, 2, ..., 9}

Slide 150

Slide 150 text

Alphabet Classes • Example: /0[1-9]/ • before /ab/ • let 0 1 2 a b 0 1 2 0 1...9 alphabet: Σ={0, 1, 2, ..., 9}

Slide 151

Slide 151 text

Alphabet Classes • Example: /0[1-9]/ • before /ab/ • let • a ≐ 0 0 1 2 a b 0 1 2 0 1...9 alphabet: Σ={0, 1, 2, ..., 9}

Slide 152

Slide 152 text

Alphabet Classes • Example: /0[1-9]/ • before /ab/ • let • a ≐ 0 • b ≐ 1...9 0 1 2 a b 0 1 2 0 1...9 alphabet: Σ={0, 1, 2, ..., 9}

Slide 153

Slide 153 text

Alphabet Classes • Example: /0[1-9]/ • before /ab/ • let • a ≐ 0 • b ≐ 1...9 0 1 2 a b 0 1 2 0 1...9 alphabet: Σ={0, 1, 2, ..., 9} alphabet: Σ={a, b}

Slide 154

Slide 154 text

Alphabet Classes Calculation 0 numberline

Slide 155

Slide 155 text

Alphabet Classes Calculation A ≐ 65 0 numberline

Slide 156

Slide 156 text

Alphabet Classes Calculation A ≐ 65 Z ≐ 90 0 numberline

Slide 157

Slide 157 text

Alphabet Classes Calculation A-E /[A-E]/ A ≐ 65 Z ≐ 90 0 numberline

Slide 158

Slide 158 text

Alphabet Classes Calculation A-E /[A-E]/ C-Z /[C-Z]/ A ≐ 65 Z ≐ 90 0 numberline

Slide 159

Slide 159 text

Alphabet Classes Calculation A-E /[A-E]/ C-Z /[C-Z]/ A ≐ 65 Z ≐ 90 0 numberline

Slide 160

Slide 160 text

Alphabet Classes Calculation A-E /[A-E]/ C-Z /[C-Z]/ A-C D-E F-Z A ≐ 65 Z ≐ 90 0 numberline

Slide 161

Slide 161 text

Alphabet Classes Calculation A-E /[A-E]/ C-Z /[C-Z]/ A-C D-E F-Z ≐ a ≐ b ≐ c A ≐ 65 Z ≐ 90 0 numberline

Slide 162

Slide 162 text

RegExp: /[A-E]|[C-Z]/

Slide 163

Slide 163 text

RegExp: /[A-E]|[C-Z]/ 0 1 2 3 A...E C...Z ε ε

Slide 164

Slide 164 text

RegExp: /[A-E]|[C-Z]/ 0 1 2 3 A...E C...Z ε ε 0 1 2 3 a, b b, c ε ε

Slide 165

Slide 165 text

How JITy is the JIT code?

Slide 166

Slide 166 text

“Well, branchy. Not good”

Slide 167

Slide 167 text

Closing Up 26

Slide 168

Slide 168 text

TODO • Code cleanup • JIT still under construction • Align Parser/Traversal API with Esprima’s

Slide 169

Slide 169 text

Status • Matcher works agains all test cases • Help needed: • project page • bugfixes • tester!

Slide 170

Slide 170 text

More important • Crazy ideas what to use this for :) • Esprima enabled many analysis tools • Hope RegExp.JS becomes used as well • Lint RegExp • Monitor RegExp execution

Slide 171

Slide 171 text

Thank you! Looking for feedback

Slide 172

Slide 172 text

Contact [email protected] @jviereck + Julian Viereck