Skip to content

Demonstration of applying optics to do interesting things with AST's

Notifications You must be signed in to change notification settings

DivineDominion/SyntaxHighlightingOptics

Repository files navigation

AST Syntax Highlighting with Optics

Would it be possible, and feasible, to express syntax highlighting rules via optics?

Current Achievment

Given an Abstract Syntax Tree stub of this form:

let ast = Root(block: .blockquote(.table(.code("Hello"))))

We can express getting to the inline .code inside a .table inside a .blockquote from the document root like so:

let deepReach = Root.blockLens
  >>> /BlockToken.blockquote
  >>> /BlockToken.table
  >>> /InlineToken.code

let value = deepReach.tryGet(ast) // → "Hello"

References and Inspiration

About

Demonstration of applying optics to do interesting things with AST's

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages