SwiftStudies / OysterKit

OysterKit is a framework that provides a native Swift scanning, lexical analysis, and parsing capabilities. In addition it provides a language that can be used to rapidly define the rules used by OysterKit called STLR
BSD 2-Clause "Simplified" License
177 stars 23 forks source link

Using OysterKit for syntax highlight #88

Closed eimantas closed 6 years ago

eimantas commented 6 years ago

I'm pretty new to this language creation thing using tools like STLR. I was wondering if OysterKit and STLR would be of any help in creating a simple editor with rudimentary syntax highlight (by recognizing language node types and providing location information in source string).

SwiftStudies commented 6 years ago

Yes, in fact I started creating it in order to do just that.

You can actually get away with a whole lot less than a full grammar to do syntax highlighting, and it can be a lot faster than actually "building" the IR.

OysterKit supports that with the TokenStreamIterable. You can see that in use in the example playground (OysterKit Tutorial.playground).

If you were go off and read the excellent Noodlesoft articles on syntax highlighting and use a TokenStream to get the tokens you can do pretty much anything you like and STLR is much better than regular expressions for achieving the highlighting (your example from yesterday wouldn't have been possible... regex just doesn't support nesting).