This page walks through implementing the LOC family —Documentation Index
Fetch the complete documentation index at: https://mehen.ophi.dev/llms.txt
Use this file to discover all available pages before exploring further.
loc.sloc, loc.ploc,
loc.lloc, loc.cloc, loc.blank — for a new language analyzer.
Five LOC variants
SLOC
A straight count of all lines in the file including code, comments, and blank lines. Value: 11.PLOC
A count of the instruction lines of code contained in the source code. This includes any brackets or similar syntax on a new line. Comments and blank lines are excluded. Value: 3.LLOC
The “logical” line count is the number of statements in the code. What a statement is depends on the language. In the example there is only a single statement — the function call ofproduct with the
Iterator as its argument.
Value: 1.
CLOC
Number of comments in the code. The type of comment does not matter — single line, block, or doc. Value: 6.Blank
Whitespace-only lines. Value: 2.Implementation
To implement the LOC metrics for a new language, contribute the appropriate node-kind matchers in your analyzer crate’sloc module. mehen’s mehen-metrics::loc exposes the LocStats accumulator that all
analyzers feed.
The accumulator pattern:
- Walk the parse tree per-line, deciding whether each line is code, comment, blank, or mixed.
- For LLOC, walk the AST and count nodes whose kind matches the language’s statement kinds
(
expression_statement,if_statement,for_statement, …). - Emit
LocStatson file-close;mehen-metrics::halstead_routing::insert_loc_metricswrites the resultingloc.*keys.
crates/mehen-metrics/src/loc.rs and the per-language loc modules for live examples.
See also
- LOC family — user-facing reference.
- How-to: Add a new language — broader analyzer authoring flow.