Noir::SwiftLexer
Inherits Noir::MaskedLexer < Reference < Object
SwiftLexer is a hand-rolled structural masking lexer for Swift source,
modelled on Noir::PhpLexer, Noir::CSharpLexer, and Noir::ScalaLexer.
Swift routes and brace counting used to be performed line-by-line or with ad-hoc regexes, causing:
- Delimiters (
{,},(,)) in string literals and comments to truncate closures or corrupt group scopes. - Route-shaped literals in documentation or comments (e.g.
app.get("fake")) to be falsely detected as endpoints. - Multi-line
"""strings, raw strings (#"..."#,##"..."##), and nested block comments (/* /* */ */) to corrupt parser state across lines.
This lexer performs a single linear pass that blanks every non-code region
(comments and string literal contents) to spaces while keeping newlines and
delimiters (", """, #", "#, etc., //, /*, */), and keeping code
inside string interpolations \( unmasked so braces inside interpolations
stay balanced.
Constants
MAX_INTERPOLATION_DEPTH = 64
Constructors
Instance methods
chars
Sourcecode_lines
Sourcemasked_lines
Sourcemasked_source
Source