Regexplainer
(h
, j
, k
, l
)
👋
- I Have Two Problems
-
const [, pkg] = spec.match(/@patternfly\/pfe-([-\w]+)\/?(.*)/)
Atom Expat
- 🧰 Hackability 🔌 Plugins 🐿️ TreeSitter
atom-regex-railroad
Do YOU know any hackable editors?
Doing NeoVim
- 🌘 Moon-Oriented Programming 🖥️
- 🐒 Climbing Trees 🌴
Code Spelunking
- Components
⚙️ What are we saying?
- Renderers
✍️ How are we saying it?
- Buffers
🪟 Where are we saying it?
Components
local cursor_node = ts_utils.get_node_at_cursor()
local cursor_node = ts_utils.get_node_at_cursor()
local regexp_node = do_awful_hacks(cursor_node)
Everything we need
- do hacks to cross between host language and regex trees
- there's lots of room for improvement here
- Combine sequential
pattern_character
s - Track capture groups and nesting levels
- Translate control chars / quantifiers
- Try to handle negative lookbehinds
{
"regexp_string": "hello d([0-9]|o)lly",
"components": [{
"text": "hello d",
"type": "pattern_character"
}, {
"capture_group": 1,
"depth": 1,
"text": "([0-9]|o)",
"type": "anonymous_capturing_group",
"children": [{
"text": "[0-9]|o",
"type": "alternation",
"children": [{
"text": "[0-9]",
"type": "term",
"children": [{
"text": "0-9",
"type": "class_range"
}],
}, {
"text": "o",
"type": "pattern_character"
}],
}],
}, {
"text": "lly",
"type": "pattern_character"
}]
}
Renderers
local M: Renderer = {}
return M
local M: Renderer = {}
function M.set_lines(buffer: Renderer,
lines: {string}): {string}
end
return M
local M: Renderer = {}
function M.set_lines(buffer: Renderer,
lines: {string}): {string}
end
function M.get_lines(components: {Component},
options: Options,
state: RendererState): {string}
end
return M
Buffers
Constructing a Narrative
function M.render(buffer: Buffer,
renderer: Renderer,
components: {Component},
options: Options,
state: RendererState)
local lines = renderer
.get_lines(components, options, state)
buffer:init(lines, options, state)
renderer.set_lines(buffer, lines)
buffer:after(lines, options, state)
end
Demo Time!
Contributions Welcome
- 💻 Graphic output
- 👀 Negative Lookbehind
- 🔨 Refactoring
- 🥼 Tests
Thanks
Benny Powers
- 💼
- Principal UX Engineer @
- 🐘
- @bp@bennypowers.dev
- 🐙
- github.com/bennypowers