Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Group One-liner Bracketed Constructs #53

Open
3 of 8 tasks
tajmone opened this issue Feb 25, 2024 · 0 comments
Open
3 of 8 tasks

Group One-liner Bracketed Constructs #53

tajmone opened this issue Feb 25, 2024 · 0 comments
Labels
⚠️ NEEDED Medium Priority Issue

Comments

@tajmone
Copy link
Owner

tajmone commented Feb 25, 2024

We should group together all the contexts for «one-liner constructs» in order to disentangle the Syntax, on the one hand, and to optimize its performance, on the other.

The obvious place to start is by grouping those constructs which consist of a single line within square brackets ([ … ]).

Since AsciiDoc supports many such constructs, it would probably make sense to add a «top-level interceptor context» that matches — without consuming — any line which begins with an opening square bracket and end with a matching closing bracket, and in case of a match then push a dedicated context that will attempt all the pertaining pattern-matching contexts for such one-liners.

This should increase the performance of the Syntax, since it will only attempt a single RegEx at each non-matching input line, instead of trying each and every one-liner context.

  • Find and list here all the square-bracketed one-liner contexts:
    • special_section (recently added)
    • block_id_legacy (recently renamed from block_id)
    • attribute_list_line
    • Check if Asciidoctor tolerates trailing whitespace after the closing bracket, so that we can account for it in the «interceptor pattern»:
      • Asciidoctor simply ignores spaces or tabs following the bracketed element.

      • Note: If non-WS characters are found (leading or trailing) then the construct is treated as text instead of an element. A single leading space or tab, on the other hand, results in the line being treated as a verbatim block (along with any following lines until an empty line is found).

        This is rather expected, but is worth keeping into account in case we decide to also handle in our dedicated context those inline square-bracketed elements which may also occur on a line of their own (i.e. bear in mind that our filtering RegEx will only pass-on lines which start with a [ and end with a ] which might contain trailing spaces or tabs).

      • Add a «top-level interceptor context» that matches one-liners within square brackets without consuming them, and the push a context that will include all the pertaining contexts.

        • Note1: some square-bracketed inline-constructs might also occur in a single line, effectively resembling elements of this category. We could just include: them within the dedicated context, since we'd already already know that the line contains a bracketed element.

        • Note2: we should account for multiple occurrences of bracketed elements in a single line (e.g. [#myid][.myrole]), which are malformed but can nevertheless occur — Asciidoctor tends to parse them as if they were a single bracketed group, with the middle ][ ending up in the first parsed parameter, but results are unpredictable: sometimes one of the two elements is preserved, other times both are rejected, or the result is corrupted parsing.

          In any case, we should at least scope any extra bracketed groups after the first one as invalid, to signal to the user that there's a problem in the source doc. If we don't account for such multiple occurrences, the risk is that the whole line is ignored by the RegEx or, worst, it gets handled poorly (with the risk of breaking the document).

        • Ensure that there are enough syntax tests to properly cover each context, so that any breaking changes are detected immediately.

      • Move all pertaining contexts within a same group — done: it's titled "SQUARE-BRACKETED ONE-LINERS"

      • Include the pertaining contexts in order of importance, so that more frequently occurring constructs are given higher priority during execution.

@tajmone tajmone added the ⚠️ NEEDED Medium Priority Issue label Feb 25, 2024
tajmone added a commit that referenced this issue Feb 25, 2024
Tweak the Syntax:

* Reorganize Syntax contexts by grouping together all single-line
  constructs enclosed within square brackets (See #53).
* Move "Preprocessor" contexts under the "Single-Line Elements" group,
  even if they are handled as prototypes.
* Rename `lines` context to `one_liners`.
* Delete obsolete commented-out contexts from original package.
* Annotate with a "TBD!" commented-out contexts pending implementation.
tajmone added a commit that referenced this issue Feb 25, 2024
Tweak the Syntax:

* Reorganize Syntax contexts by grouping together all single-line
  constructs enclosed within square brackets (See #53).
* Move "Preprocessor" contexts under the "Single-Line Elements" group,
  even if they are handled as prototypes.
* Rename `lines` context to `one_liners`.
* Delete obsolete commented-out contexts from original package.
* Annotate with a "TBD!" commented-out contexts pending implementation.
tajmone added a commit that referenced this issue Feb 25, 2024
Tweak the Syntax:

* Reorganize Syntax contexts by grouping together all single-line
  constructs enclosed within square brackets (See #53).
* Move "Preprocessor" contexts under the "Single-Line Elements" group,
  even if they are handled as prototypes.
* Rename `lines` context to `one_liners`.
* Delete obsolete commented-out contexts from original package.
* Annotate with a "TBD!" commented-out contexts pending implementation.
tajmone added a commit that referenced this issue Feb 25, 2024
Tweak the Syntax:

* Reorganize Syntax contexts by grouping together all single-line
  constructs enclosed within square brackets (See #53).
* Move "Preprocessor" contexts under the "Single-Line Elements" group,
  even if they are handled as prototypes.
* Rename `lines` context to `one_liners`.
* Delete obsolete commented-out contexts from original package.
* Annotate with a "TBD!" commented-out contexts pending implementation.
tajmone added a commit that referenced this issue Feb 26, 2024
* Add to syntax support for special section styles,
  under the `one_liners_sq-bracketed` context (see #53).
* Add to "AsciiDoc Dark" color scheme a rule to color special sections.
* Remove a redundant inclusion of `attribute_list_line` in `one_liners`
  context, since it's already part of the `one_liners_sq-bracketed`.
* Move inclusion of `one_liners_sq-bracketed` at the top of `one_liners`
  context, because it should be give higher priority due to the vast
  number of constructs it covers, and their usage frequency (see #53).
tajmone added a commit that referenced this issue Feb 26, 2024
* Add to syntax support for special section styles,
  under the `one_liners_sq-bracketed` context (see #53).
* Add to "AsciiDoc Dark" color scheme a rule to color special sections.
* Remove a redundant inclusion of `attribute_list_line` in `one_liners`
  context, since it's already part of the `one_liners_sq-bracketed`.
* Move inclusion of `one_liners_sq-bracketed` at the top of `one_liners`
  context, because it should be give higher priority due to the vast
  number of constructs it covers, and their usage frequency (see #53).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
⚠️ NEEDED Medium Priority Issue
Projects
None yet
Development

No branches or pull requests

1 participant