Skip to main content

Module lang_helpers

Module lang_helpers 

Source
Expand description

Byte-level identity helpers shared by the classifiers and the metrics.

Some questions a walk asks are not answerable from a node’s kind: an Elixir def and a quote are both Call nodes told apart only by their target text, a Tcl switch is a plain command whose leading word names the builtin, and Python’s aliased block / lambda kinds must be normalised at one site (grammar-dispatch §9 and §10). These helpers read the bytes once so Checker, Getter, and every metric agree on the answer.

They live beside the classifiers rather than in a metric module because the classifiers consult them: a Checker impl that imported a helper from metrics::cognitive would make the parse layer depend on the metric layer, the inversion #1376 exists to remove.

Modules§

bash
Bash: the logical connectives and the string comparison of a [ … ] / [[ … ]] test.
elixir
Elixir: keyword Call identity (def, defmodule, quote, …), and applied versus named operators.
perl
Perl: telling the and and not operators, the file tests, the unary minus and bareword calls from an auto-quoted key that the grammar lexes as one of them; and reading the POD in the data section after __END__, which the grammar leaves as one leaf.
python
Python: the aliased block and lambda kind sets, and the shape of a docstring.
tcl
Tcl: the leading word of a command node, and the grammar’s braced-word kind ids.

Structs§

DocBinding
Re-exported because the LOC metric bills documentation through them — Go, Ruby and Lua runs by position, and the doc comments a bound language’s tool attaches — while the predicates beside them stay crate-private. Re-exported because the LOC metric bills documentation through them — Go, Ruby and Lua runs by position, and the doc comments a bound language’s tool attaches — while the predicates beside them stay crate-private. Re-exported because the LOC metric bills documentation through them — Go, Ruby and Lua runs by position, and the doc comments a bound language’s tool attaches — while the predicates beside them stay crate-private. How a language’s tool attaches a doc comment to the declaration after it (#1613), read from each tool’s source rather than its manual (lesson 98); see [Checker::DOC_BINDING]. A forward doc comment that the binding does not attach documents nothing and is billed as a plain comment.

Enums§

KeptDocs
Re-exported because the LOC metric bills documentation through them — Go, Ruby and Lua runs by position, and the doc comments a bound language’s tool attaches — while the predicates beside them stay crate-private. Re-exported because the LOC metric bills documentation through them — Go, Ruby and Lua runs by position, and the doc comments a bound language’s tool attaches — while the predicates beside them stay crate-private. Re-exported because the LOC metric bills documentation through them — Go, Ruby and Lua runs by position, and the doc comments a bound language’s tool attaches — while the predicates beside them stay crate-private. Which doc comments of a stretch a DocBinding attaches.

Functions§

bound_doc_run
Re-exported because the LOC metric bills documentation through them — Go, Ruby and Lua runs by position, and the doc comments a bound language’s tool attaches — while the predicates beside them stay crate-private. Re-exported because the LOC metric bills documentation through them — Go, Ruby and Lua runs by position, and the doc comments a bound language’s tool attaches — while the predicates beside them stay crate-private. Re-exported because the LOC metric bills documentation through them — Go, Ruby and Lua runs by position, and the doc comments a bound language’s tool attaches — while the predicates beside them stay crate-private. Credits the doc comments a bound language’s tool attaches to the declaration after them (#1613). Called from the LOC comment arm for every comment; credit receives each attached doc comment, whose own arm has already billed its rows as cloc. A language with no [Checker::DOC_BINDING] credits nothing here.
documents_unbound
Re-exported because the LOC metric bills documentation through them — Go, Ruby and Lua runs by position, and the doc comments a bound language’s tool attaches — while the predicates beside them stay crate-private. Re-exported because the LOC metric bills documentation through them — Go, Ruby and Lua runs by position, and the doc comments a bound language’s tool attaches — while the predicates beside them stay crate-private. Re-exported because the LOC metric bills documentation through them — Go, Ruby and Lua runs by position, and the doc comments a bound language’s tool attaches — while the predicates beside them stay crate-private. Whether a doc comment documents without a following declaration, before documents_where_it_sits has its say: every doc comment of a language with no [Checker::DOC_BINDING], and a bound language’s that does not attach forward (DocBinding::forward). A forward one documents only through bound_doc_run (#1613).
documents_where_it_sits
Re-exported because the LOC metric bills documentation through them — Go, Ruby and Lua runs by position, and the doc comments a bound language’s tool attaches — while the predicates beside them stay crate-private. Re-exported because the LOC metric bills documentation through them — Go, Ruby and Lua runs by position, and the doc comments a bound language’s tool attaches — while the predicates beside them stay crate-private. Re-exported because the LOC metric bills documentation through them — Go, Ruby and Lua runs by position, and the doc comments a bound language’s tool attaches — while the predicates beside them stay crate-private. The place half of the documentation test, for a comment already spelled or placed as documentation: it documents unless an ancestor holds it in a function or closure body ([Checker::holds_doc_comment_in_body]) without the comment opening that body as its documentation ([Checker::doc_comment_opens_body], asked of the two nearest ancestors only) and the language’s tool ignores in-body doc comments ([Checker::DOC_COMMENTS_IN_FUNCTION_BODIES]). Shared by the marker languages’ comment arms and by Lua’s LDoc opener (#1597).
leading_doc_run
Re-exported because the LOC metric bills documentation through them — Go, Ruby and Lua runs by position, and the doc comments a bound language’s tool attaches — while the predicates beside them stay crate-private. Re-exported because the LOC metric bills documentation through them — Go, Ruby and Lua runs by position, and the doc comments a bound language’s tool attaches — while the predicates beside them stay crate-private. Re-exported because the LOC metric bills documentation through them — Go, Ruby and Lua runs by position, and the doc comments a bound language’s tool attaches — while the predicates beside them stay crate-private. Credits the rows of the comment run that comment ends, when the run is documentation: it sits directly above a node the language’s [Checker::is_doc_target] accepts, or its first member opens a block per [Checker::is_doc_run_opener]. Called from a language’s LOC comment arm for every comment; only the run’s last member does any work beyond one sibling step, so a run of k rows costs O(k) sibling steps in total (#1597).
strip_global_qualifier
Re-exported because both dialects’ metrics need it and the module holding it is crate-private: iRules’ nexits and ABC walkers resolve a leading word themselves rather than through tcl::tcl_command_name, so they normalise the :: qualifier at their own call sites. A leading word with its global-namespace qualifier removed.