Class ReadabilityAssessor

java.lang.Object
org.ek9lang.compiler.tokenizer.ReadabilityAssessor
All Implemented Interfaces:
Serializable

public final class ReadabilityAssessor extends Object implements Serializable
THE incremental readability (ARI) scorer - feed it every token exactly once, in order, then ask for the score.

This is the single implementation of the ARI counting rules. TokenStreamAssessment drives it over a whole lexer for standalone/debug use; CompilableSource drives it from tokenConsumed so that readability is computed during the parser's own lex rather than by lexing the file a second time.

Do NOT re-derive the counting rules elsewhere. An instance is stateful and single-use per source; call reset() before feeding a fresh token stream.

See Also:
  • Constructor Details

    • ReadabilityAssessor

      public ReadabilityAssessor()
  • Method Details

    • accept

      public void accept(String symbolicName, String rawTokenText)
      Accept one token. The symbolic name may be null, in which case the literal content is used in its place - matching the historic behaviour of the whole-stream assessment.
      Parameters:
      symbolicName - the lexer's symbolic name for the token type, or null
      rawTokenText - the token's text, exactly as the lexer produced it
    • score

      public String score()
      The ARI score for everything accepted so far.
    • reset

      public void reset()
      Discard all accumulated counts, ready for a fresh token stream.
    • tidyLiteralContent

      String tidyLiteralContent(String content)
      Also used for token display, so escaping must stay identical to what was shown historically.