DMS-XS-Parser

 view release on metacpan or  search on metacpan

ppport.h  view on Meta::CPAN

BmPREVIOUS|5.003007||Viu
BmRARE|5.003007||Viu
BmUSEFUL|5.003007||Viu
BOL|5.003007||Viu
BOL_t8|5.035004||Viu
BOL_t8_p8|5.033003||Viu
BOL_t8_pb|5.033003||Viu
BOL_tb|5.035004||Viu
BOL_tb_p8|5.033003||Viu
BOL_tb_pb|5.033003||Viu
BOM_UTF8|5.025005|5.003007|p
BOM_UTF8_FIRST_BYTE|5.019004||Viu
BOM_UTF8_TAIL|5.019004||Viu
boolSV|5.004000|5.003007|p
boot_core_builtin|5.035007||Viu
boot_core_mro|5.009005||Viu
boot_core_PerlIO|5.007002||Viu
boot_core_UNIVERSAL|5.003007||Viu
BOUND|5.003007||Viu
BOUNDA|5.013009||Viu
BOUNDA_t8|5.035004||Viu
BOUNDA_t8_p8|5.033003||Viu
BOUNDA_t8_pb|5.033003||Viu

ppport.h  view on Meta::CPAN

#ifndef isUTF8_CHAR
#  define isUTF8_CHAR(s, e)              (                                            \
    (e) <= (s) || ! is_utf8_string(s, UTF8_SAFE_SKIP(s, e))                     \
    ? 0                                                                         \
    : UTF8SKIP(s))
#endif

#endif

#if 'A' == 65
#ifndef BOM_UTF8
#  define BOM_UTF8                       "\xEF\xBB\xBF"
#endif

#ifndef REPLACEMENT_CHARACTER_UTF8
#  define REPLACEMENT_CHARACTER_UTF8     "\xEF\xBF\xBD"
#endif

#elif '^' == 95
#ifndef BOM_UTF8
#  define BOM_UTF8                       "\xDD\x73\x66\x73"
#endif

#ifndef REPLACEMENT_CHARACTER_UTF8
#  define REPLACEMENT_CHARACTER_UTF8     "\xDD\x73\x73\x71"
#endif

#elif '^' == 176
#ifndef BOM_UTF8
#  define BOM_UTF8                       "\xDD\x72\x65\x72"
#endif

#ifndef REPLACEMENT_CHARACTER_UTF8
#  define REPLACEMENT_CHARACTER_UTF8     "\xDD\x72\x72\x70"
#endif

#else
#  error Unknown character set
#endif

vendor/dms-c/dms.c  view on Meta::CPAN

    parser p;
    memset(&p, 0, sizeof p);
    p.src = src;
    p.len = srclen;
    p.line = 1;
    p.record_forms = 1;
    p.lite = lite;
    p.unordered = unordered;
    /* SPEC §"UTF-8 only, NFC-normalized": DMS source is plain UTF-8 with
       no byte-order mark. A leading U+FEFF is not silently consumed —
       reject it explicitly so encoding mistakes surface loudly. (BOMs
       *inside* string/heredoc bodies are fine; this only fires at offset 0.) */
    if (srclen >= 3 && (unsigned char)src[0] == 0xEF && (unsigned char)src[1] == 0xBB && (unsigned char)src[2] == 0xBF) {
        set_err_at(&p, 1, 0, 0,
                   "BOM (U+FEFF) at file start is not allowed; DMS source is plain UTF-8");
        if (err) *err = p.err;
        pending_free(&p.pending);
        path_free(&p.path);
        attached_free(&p.comments);
        original_free(&p.original_forms);
        return NULL;
    }
    /* U+0000 is not allowed anywhere in DMS source (see SPEC §Strings). */
    for (size_t i = 0; i < srclen; i++) {
        if (src[i] == '\0') {

vendor/dms-c/dms.c  view on Meta::CPAN


   Returns:
     1  → `*fm_end_out` is the byte offset (in raw `src`) one past the
          closing `+++`'s EOL. The caller can NUL/NFC-validate just
          `src[0..*fm_end_out]` and feed that slice to
          `parse_front_matter_tbl` — body bytes are skipped entirely.
     0  → "no FM present": leading trivia walks cleanly, but the next
          non-trivia byte is not `+++`. `*fm_end_out` is unset.
    -1  → bail to the slow path. The fast scanner can't bound the FM
          region without doing real validation work — either the input
          starts with a BOM, contains an unterminated/malformed comment
          in leading trivia, or never closes the FM. The slow path
          surfaces the matching diagnostic.

   The closing `+++` is detected by the same trimmed-line test
   `parse_front_matter_tbl` uses (lines 2202-2206), so the bounded
   region byte-matches what the slow path would have consumed. */
static int find_fm_end_fast(const char *src, size_t srclen, size_t *fm_end_out) {
    /* BOM at offset 0 — slow path so the dedicated diagnostic fires. */
    if (srclen >= 3
        && (unsigned char)src[0] == 0xEF
        && (unsigned char)src[1] == 0xBB
        && (unsigned char)src[2] == 0xBF) {
        return -1;
    }
    size_t pos = 0;
    /* ----- leading trivia: blank lines + line/block comments ----- */
    while (pos < srclen) {
        /* skip inline ws */

vendor/dms-c/dms.c  view on Meta::CPAN

        }
        pos = after_eol;
    }
    /* Hit EOF without finding closer. */
    return -1;
}

/* SPEC §Front-matter-only decode (tier-0, required).

   Pre-scans raw bytes to bound the FM region (`find_fm_end_fast`),
   then BOM/NUL/NFC-validates only that prefix and feeds it to
   `parse_front_matter_tbl`. Body bytes are never visited — call cost
   scales with FM-region size, not source size. On any pre-scan
   ambiguity (BOM, malformed leading comment, missing closer, etc.)
   we fall through to the slow path which validates the entire source
   and emits the canonical diagnostic.

   `parse_front_matter_tbl`'s contract:
     - returns NULL with `p.has_err == 0` when the document has no
       opening `+++` (no FM present),
     - returns a calloc'd `dms_table *` (possibly with `len == 0`
       for an empty `+++\n+++`) on success,
     - returns NULL with `p.has_err == 1` on any in-FM error.

vendor/dms-c/dms.c  view on Meta::CPAN

    parser p;
    memset(&p, 0, sizeof p);
    p.src = src;
    p.len = srclen;
    p.line = 1;
    p.record_forms = 1;
    /* SPEC §Front-matter-only decode: this entry point runs in lite
       mode (no comment AST, no original_forms inside the FM). */
    p.lite = 1;
    p.unordered = 0;
    /* Fast pre-scan: bound the FM region so the BOM/NUL/NFC pass below
       only touches FM bytes. NFC of a stable-boundary prefix equals
       the prefix of NFC(full) (the closing `+++` is ASCII and therefore
       a stable boundary), so byte offsets and line numbers inside the
       FM region are identical to the full-source path — diagnostics
       remain byte-identical per SPEC. */
    size_t scan_len = srclen;
    {
        size_t fm_end = 0;
        int rc = find_fm_end_fast(src, srclen, &fm_end);
        if (rc == 0) {
            /* No FM present — fast bail without touching body bytes. */
            if (has_front_matter) *has_front_matter = false;
            return NULL;
        } else if (rc == 1) {
            /* Restrict validation/parse to the FM region. */
            scan_len = fm_end;
        }
        /* rc == -1: fall through to the slow full-source path. */
    }
    /* SPEC §"UTF-8 only, NFC-normalized": reject a leading BOM so
       encoding mistakes surface loudly. */
    if (scan_len >= 3
        && (unsigned char)src[0] == 0xEF
        && (unsigned char)src[1] == 0xBB
        && (unsigned char)src[2] == 0xBF) {
        set_err_at(&p, 1, 0, 0,
                   "BOM (U+FEFF) at file start is not allowed; DMS source is plain UTF-8");
        if (err) *err = p.err;
        pending_free(&p.pending);
        path_free(&p.path);
        attached_free(&p.comments);
        original_free(&p.original_forms);
        return NULL;
    }
    /* U+0000 is not allowed anywhere in DMS source. We scan the FM
       region only — body NULs are not surfaced by this entry point
       per SPEC (body bytes aren't tokenized here). */



( run in 0.558 second using v1.01-cache-2.11-cpan-9581c071862 )