Class SourceRegions

java.lang.Object
org.ek9lang.compiler.common.SourceRegions

public final class SourceRegions extends Object
THE reader of the region and elide markers in a compiled example source (site-examples spec ยง3.4, decision D5) - every page fragment is cut from a whole, compiled source through here; never parse the markers anywhere else.
  // region: anatomy          a region a page may show:  classes/classes_anatomy.ek9#anatomy
  // end region: anatomy
  // elide: constructors      lines the page shows as ONE comment, "// ... constructors"
  // end elide: constructors

A marker is an EK9 comment WITH text (a bare // line is a syntax error), so the source still compiles exactly as written. Regions may nest, and a region name is unique within its file. An elided run is rendered as ONE comment line at the marker's indentation, // ... <name> - never a bare ... line, which is EK9's range operator, does not compile, and would teach a model that it is legal (Steve, D5).

Two views of one source:

  • extract(String, String) - what a page shows: a region (or the whole body), markers removed, elided runs collapsed, dedented to its least-indented line;
  • full(String) - the "full source" page: every line, markers removed, with the line each region starts on so the page can carry an id per region.
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    static final record 
    A source with its markers removed, and the line each region starts on.
    (package private) static enum 
    The kind of a marker line.
    (package private) static final record 
    One marker line: whether it opens or closes, its kind, its name and its indentation.
  • Method Summary

    Modifier and Type
    Method
    Description
    static String
    extract(String body, String region)
    What a page shows: the named region of body (the whole body when region is null), with every marker line removed, each elided run replaced by ONE // ... <name> comment at the run's indentation, leading and trailing blank lines dropped, and the result dedented to its least-indented line.
    full(String body)
    The "full source" view of body: every source line with the marker lines removed, and for each region the (zero-based) line of that text it starts on.
    (package private) static SourceRegions.Marker
    The marker on this line, or null when the line is source.
    static List<String>
    Every structural problem in the markers of body - unbalanced or mismatched markers, a duplicate or malformed region name, an elide inside an elide.
    static Set<String>
    The region names declared in body, in source order.

    Methods inherited from class Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Method Details

    • markerOf

      static SourceRegions.Marker markerOf(String line)
      The marker on this line, or null when the line is source.
    • problems

      public static List<String> problems(String body)
      Every structural problem in the markers of body - unbalanced or mismatched markers, a duplicate or malformed region name, an elide inside an elide. Empty when the markers are well formed.
    • regionNames

      public static Set<String> regionNames(String body)
      The region names declared in body, in source order.
    • extract

      public static String extract(String body, String region)
      What a page shows: the named region of body (the whole body when region is null), with every marker line removed, each elided run replaced by ONE // ... <name> comment at the run's indentation, leading and trailing blank lines dropped, and the result dedented to its least-indented line.
      Throws:
      IllegalArgumentException - when the markers are malformed or the region is not declared
    • full

      public static SourceRegions.Full full(String body)
      The "full source" view of body: every source line with the marker lines removed, and for each region the (zero-based) line of that text it starts on.