module Noir::ClojureScanner

Overview

Low-level Clojure reader primitives, shared by the callee extractor in this directory and by the Clojure framework analyzers — Analyzer::Clojure::Helper is a thin delegation layer over this module, so the two never drift again.

Every offset here is a byte offset into the raw source (byte_at), never a character index, so the values stay usable with String#byte_slice on sources containing non-ASCII text.

Extended Modules

Direct including types

Defined in:

miniparsers/clojure_scanner.cr

Instance Method Summary

Instance Method Detail

def find_matching_delimiter(source : String, index : Int32, open_char : Char, close_char : Char, limit : Int32) : Int32 #

Find the offset of the delimiter closing the one at index, skipping over comments, string literals and character literals so a ) inside ";)" or a \( never moves the depth counter. Returns index unchanged when no match is found.


[View source]
def line_number_for(source : String, index : Int32, start_line : Int32 = 1) : Int32 #

Line number of a byte offset, counted from start_line (1-based by default, matching a whole-file offset).


[View source]
def skip_char_literal(source : String, index : Int32, limit : Int32) : Int32 #

Advance from the \ that opens a character literal to the literal's last byte (the same "last byte consumed" contract as #skip_string).

Clojure character literals are \a, \", \(, \\, \; (a single character, reader-significant ones included), the named forms \newline, \space, \tab, \formfeed, \backspace and \return, \uXXXX and \oNNN. Without this, \" opens a string that runs to the next quote in the file and \( counts as a real open paren, so depth accounting — and with it every route below the literal — collapses.


[View source]
def skip_comment(source : String, index : Int32, limit : Int32) : Int32 #

Advance past a ; line comment, stopping on the newline that ends it.


[View source]
def skip_string(source : String, index : Int32, limit : Int32) : Int32 #

Advance from the opening " of a string literal to its closing quote, honouring \ escapes. Returns the last in-range offset when the literal is unterminated so callers still make progress.


[View source]