Class ErrorDirectiveText

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

public final class ErrorDirectiveText extends Object
THE text-level reading of the @Error: PHASE: CLASSIFICATION directive lines in an example SOURCE - for the readers that show an error example to a person or a model, not for the compiler (which parses directives with the grammar and checks them with ErrorDirectiveListener). Use it; never write another regex for these lines.

Shared by the site's code block renderer and publisher (org.ek9lang.site.Ek9CodeBlockRenderer, SiteExamplePublisher, QaPageRenderer), the error catalogue (ErrorExamples, whose plain-text [EXAMPLE] reaches ek9 -h <CODE> and -E3) and the gates that check those examples. The source keeps its directive lines, where a gate reads them; a reader is shown the source without them and one caption naming the error ("Fails with E05240: <meaning>", decision D4 of the site-examples spec).

  • Method Details

    • isErrorExample

      public static boolean isErrorExample(String source)
      True when the source carries at least one @Error directive - an error example.
    • withoutErrorDirectives

      public static String withoutErrorDirectives(String source)
      The source with every @Error directive line removed - what a reader would type.
    • errorCodes

      public static List<String> errorCodes(String source)
      The error codes the source's @Error directives name, in source order, without repeats.
      Throws:
      IllegalArgumentException - when a directive names a classification that does not exist
    • phases

      public static List<String> phases(String source)
      The phase names the source's @Error directives give, in source order, without repeats.
    • expectedErrorLines

      public static List<String> expectedErrorLines(String source)
      Where each directive says its error is, as "<line>:<CLASSIFICATION>" - the line after the directive, counting from 1 - in source order. The exact check of a PARSING directive reads this: a syntax error stops the parse, so no directive is ever read from a parse tree, and the text is all there is.
      Throws:
      IllegalArgumentException - when a directive names a classification that does not exist
    • meaningOf

      public static String meaningOf(String code)
      The one-line meaning of a semantic error code, from the compiler's own classification.
      Throws:
      IllegalArgumentException - when no classification has the code