class
Noir::CSharpLexer
- Noir::CSharpLexer
- Reference
- Object
Overview
CSharpLexer is a hand-rolled structural lexer for C# source, modelled on
Noir::PhpLexer. The C# analyzers count {/}/(/) per line with no
string awareness (line.count('{') - line.count('}')), so a single } or
( inside a string literal truncates a method block (dropping callees) or
makes a signature run away (dropping parameters). This lexer masks every
non-code region in one linear pass so those counters can run over code only.
Handles the C# string zoo:
- regular
"…"backslash escapes - verbatim
@"…"""is an escaped quote,\is literal - interpolated
$"…{expr}…"{{/}}are literal braces; a"inside a{ }hole opens a nested string - combined
$@"…"/@$"…" - raw
"""…"""(and$"""…""") variable-length quote fence - char
'x'/'\}'/'"' - comments
//…and/* … */
Every literal is masked to spaces (newlines preserved, length unchanged), so
the structural helpers below are plain depth counters over @masked. The
source is materialised once into an Array(Char) for O(1) indexing, keeping
the scan O(n) on multi-byte (e.g. CJK-commented) source.
Defined in:
minilexers/csharp_lexer.crConstructors
Instance Method Summary
- #in_code?(pos : Int32) : Bool
- #masked : Array(Char)
-
#masked_lines : Array(String)
The masked source split into lines, parallel to
source.lines. - #matching_delimiter(open_pos : Int32) : Int32 | Nil
- #skip_ranges : Array(Range(Int32, Int32))
-
#statement_end(start_pos : Int32) : Int32
Index just after the top-level
;at or afterstart_pos, or the source size when none is found. - #tokens : Array(CSharpToken)
Constructor Detail
Instance Method Detail
The masked source split into lines, parallel to source.lines. Strings,
comments and char literals are blanked, so the C# analyzers can run their
existing per-line line.count('{') / line.count('(') counters over
masked_lines[i] (structure) while emitting lines[i] (real text).
Index just after the top-level ; at or after start_pos, or the source
size when none is found.