/* eslint-disable */ @// import parser macros @import 'general-parser-macros.jmacs' @// possible mode types are: @// HDT: Header Dictionary Triples @$ c_braces = 0; @// convert utf8-encoded byte sequence to string @> utf8_string(array) decode_utf_8(@{array? array: 'a.slice(i, i_null)'}) @; // only if the @> if_null_termination() @; @// change state @> goto(s_method) return this.@{s_method}(a, n, i); @; @// save current state to stack @> push_state(state, is_var) @$ q = "'"; this.nested.push(@{is_var? '': q}@{state}@{is_var? '': q}); @; @// restore previous state from stack @> pop_state() let s_resume_state = this.nested.pop(); return this[s_resume_state](a, n, i); @; @> method(name, bytes_needed, string_var, n) @{name}(a, n, i) { @// minimum number of bytes needed for this state @- bytes_needed @// count how many braces need to be closed @$ c_braces += 1; @- 1 === bytes_needed // single byte needed if(i < n) { @: // need at least @{bytes_needed} bytes if(n - i >= @{bytes_needed}) { @; @// null-terminated string @+ string_var @// count how many braces need to be closed @$ c_braces += 1; // index of null character let i_null = a.indexOf(0, i); // string is within buffer if(-1 !== i_null) { @{crc(n || 16)} // decode string from buffer let @{string_var} = @{utf8_string()}; @; @; @> bail(state) // save state before pausing this.state = this.@{state}; // update offset this.offset += i; // consumer is pausing if(n < 0) { // go async return; } // store what is unparsed this.pre = a.slice(i); // if we're not parsing a stream, then this is an error // return this.eos && this.eos(); return; @; @> end_method(name) @// for all braces that need to be closed @*{ for(let i_brace=0; i_brace this.max_buffer_size) { return this.parse_error(a, n, i, '@{name}'); } } } @{bail(name)} }, @;