@spotify/backstage-plugin-pulse-common 0.12.1 → 0.12.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +12 -0
- package/dist/config.cjs.js +2 -0
- package/dist/graphql/schema-types.generated.cjs.js +2 -0
- package/dist/index.cjs.js +1 -22
- package/dist/index.d.ts +3 -3
- package/dist/permissions.cjs.js +2 -0
- package/dist/polyfills.cjs.js +2 -0
- package/dist/templates/convertTemplateToNode.cjs.js +2 -0
- package/dist/templates/evaluation.cjs.js +2 -0
- package/dist/templates/index.cjs.js +2 -0
- package/dist/templates/interpolation.cjs.js +2 -0
- package/dist/templates/locators.cjs.js +2 -0
- package/dist/templates/logic.cjs.js +2 -0
- package/dist/templates/schema/logic_parser.cjs.js +23 -0
- package/dist/templates/schema/survey-template-schema.json.cjs.js +2 -0
- package/dist/templates/validateResponse.cjs.js +2 -0
- package/dist/templates/validateTemplate.cjs.js +2 -0
- package/dist/transformCase.cjs.js +2 -0
- package/package.json +11 -4
package/CHANGELOG.md
CHANGED
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
"use strict";const i="pulse.experimentalFlags",l=(t,e)=>t.getOptionalStringArray(i)?.includes(e),o=(t,e)=>{const r=t.getOptionalStringArray(i),n=`${e}=`;return r?.find(a=>a.startsWith(n))?.replace(n,"")};exports.getExperimentalOptionalBoolean=l,exports.getExperimentalOptionalString=o;
|
|
2
|
+
//# sourceMappingURL=config.cjs.js.map
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
"use strict";var i=(e=>(e.DuplicateResponse="DUPLICATE_RESPONSE",e.InternalError="INTERNAL_ERROR",e.InvalidDates="INVALID_DATES",e.InvalidId="INVALID_ID",e.InvalidParticipants="INVALID_PARTICIPANTS",e.InvalidResponse="INVALID_RESPONSE",e.MissingTitle="MISSING_TITLE",e.OverlappingSurveys="OVERLAPPING_SURVEYS",e.ParticipantsFrozen="PARTICIPANTS_FROZEN",e.SurveyIsClosed="SURVEY_IS_CLOSED",e.Unauthorized="UNAUTHORIZED",e))(i||{}),t=(e=>(e.Horizontal="HORIZONTAL",e.Vertical="VERTICAL",e))(t||{}),I=(e=>(e.Optional="OPTIONAL",e.Request="REQUEST",e.Required="REQUIRED",e))(I||{}),a=(e=>(e.Description="DESCRIPTION",e.MatrixMulti="MATRIX_MULTI",e.MatrixSingle="MATRIX_SINGLE",e.McMulti="MC_MULTI",e.McSingle="MC_SINGLE",e.TextMulti="TEXT_MULTI",e.TextSingle="TEXT_SINGLE",e))(a||{}),S=(e=>(e.All="ALL",e.Constrained="CONSTRAINED",e.Subset="SUBSET",e))(S||{}),T=(e=>(e.Finalized="FINALIZED",e.Partial="PARTIAL",e))(T||{}),r=(e=>(e.Active="ACTIVE",e.Published="PUBLISHED",e))(r||{}),R=(e=>(e.Q1="Q1",e.Q2="Q2",e.Q3="Q3",e.Q4="Q4",e))(R||{});exports.MutationResponseErrorCode=i,exports.QuestionLayout=t,exports.QuestionRequirement=I,exports.QuestionType=a,exports.RandomizationType=S,exports.SurveyResponseStatus=T,exports.SurveyStatus=r,exports.TargetQuarter=R;
|
|
2
|
+
//# sourceMappingURL=schema-types.generated.cjs.js.map
|
package/dist/index.cjs.js
CHANGED
|
@@ -1,23 +1,2 @@
|
|
|
1
|
-
"use strict";var St=require("@backstage/plugin-permission-common"),$t=require("@ungap/structured-clone"),zt=require("ajv"),Dt=require("ajv-formats"),Pt=require("assert"),Lt=require("crypto"),Ct=require("lodash");function j(s){return s&&typeof s=="object"&&"default"in s?s:{default:s}}function Qt(s){if(s&&typeof s=="object"&&"default"in s)return s;var t=Object.create(null);return s&&Object.keys(s).forEach(function(n){if(n!=="default"){var i=Object.getOwnPropertyDescriptor(s,n);Object.defineProperty(t,n,i.get?i:{enumerable:!0,get:function(){return s[n]}})}}),t.default=s,Object.freeze(t)}var Mt=j($t),jt=j(zt),Ut=j(Dt),Ft=j(Pt),Bt=Qt(Lt),V=j(Ct);const Zt="survey-instance",Pe=St.createPermission({name:"survey.instance.administer",attributes:{action:"create"}}),Gt=[Pe],Le="pulse.experimentalFlags",Vt=(s,t)=>s.getOptionalStringArray(Le)?.includes(t),Wt=(s,t)=>{const n=s.getOptionalStringArray(Le),i=`${t}=`;return n?.find(r=>r.startsWith(i))?.replace(i,"")},Xt=()=>{"structuredClone"in globalThis||(globalThis.structuredClone=Mt.default)};var Ht="surveyTemplate",Jt="http://json-schema.org/draft-07/schema",Yt="Survey Template",Kt="object",en={template:{type:"object",description:"Meta data about the survey template",properties:{id:{type:"string",description:"An id of the survey template. If there are multiple templates with the same id, they must have different versions.",format:"regex",pattern:"^[a-zA-Z][a-zA-Z0-9_-]*[a-zA-Z0-9]$",minLength:1},version:{type:"string",format:"regex",pattern:"^[0-9]+(\\.[0-9]+)?$",description:"A version of template"},name:{type:"string",description:"The display name of the survey template",minLength:1},description:{type:"string",description:"A longer description of the survey template"},owner:{type:"string",description:"The owner of the survey template",minLength:1}},required:["id","version","name","owner"],additionalProperties:!1},parameters:{type:"array",description:"Template parameters that can or must be set when creating a survey from this template. Parameters are referred to elsewhere in the survey using the ${p:<id>} construct and will get lazily in-place replaced.",items:{type:"object",properties:{id:{type:"string",description:"The id of the parameter",format:"regex",pattern:"^[a-zA-Z][a-zA-Z0-9_]*$"},description:{type:"string",description:"The description of the parameter"},format:{type:"string",enum:["string","number","boolean"],description:"The format of the parameter. Should only be set if a default value is not provided."},default:{type:["string","number","boolean"],description:"An optional default value of this parameter. If this is omitted, the parameter must be provided when creating a survey from the template."}},required:["id","description"],oneOf:[{required:["format"]},{required:["default"]}],additionalProperties:!1}},macros:{type:"object",description:"Expression shortcuts. Macros are referred to elsewhere in the survey using the ${m:<name>} construct (similar to parameters) and will get lazily in-place replaced. Macros can be recursive and contain references to parameters or answers in the survey.",additionalProperties:{type:"string"}},sections:{type:"array",description:"The survey sections, in the order they will appear in the survey",items:{$ref:"#/$defs/section"}}},tn=!1,nn=["template","parameters","sections"],sn={section:{type:"object",description:"A survey section.",properties:{id:{type:"string",description:"The id of this section",format:"regex",pattern:"^[a-zA-Z][a-zA-Z0-9_-]*[a-zA-Z0-9]$"},name:{type:"string",description:"The name of this section"},display_logic:{type:"string",description:"An optional boolean expression that decides if the surveyee should see the questions in this section."},hide_progress_bar:{type:"boolean",description:"When set, the survey progress bar will not be shown during this section."},pages:{type:"array",description:"The questions in the section, split into pages",items:{$ref:"#/$defs/page"}}},additionalProperties:!1,required:["id","name","pages"]},page:{type:"object",properties:{questions:{type:"array",description:"The questions on the page",items:{$ref:"#/$defs/question"}}},required:["questions"],additionalProperties:!1},question:{type:"object",properties:{id:{type:"string",description:"The unique ID of the question",pattern:"^[a-zA-Z][a-zA-Z0-9_]*$"},text:{type:"string",description:"The question description, in markdown"},type:{type:"string",enum:["mc-single","mc-multi","matrix-single","matrix-multi","text-single","text-multi","description"],description:"The type of question"},layout:{type:"string",enum:["vertical","horizontal"],description:"Determines the visual layout of the options in multiple choice questions"},display_logic:{type:"string",description:"A boolean expression with logic if this question should be displayed or not"},required:{type:"string",enum:["required","optional","request"],description:"If the question is required to answer; request means you will get a warning if you skip it but you can."},validation:{type:"object",description:"Validation constraints on the question. Only applied if the user has answered the question, so typically used in combination with required",properties:{min_choices:{type:"integer",description:"The minimum number of choices to user can pick (multiple choice questions only)"},max_choices:{type:"integer",description:"The maximum number of choices to user can pick (multiple choice questions only)"}},additionalProperties:!1},statements:{type:"array",items:{$ref:"#/$defs/statement"}},dynamic_statements:{type:"string",description:"Carry forward statements from a previous question",pattern:"^[a-zA-Z][a-zA-Z0-9_]*/(all|selected|all_entered_text|selected_entered_text|not_selected|for_matrix_choice\\([\\-a-zA-Z0-9_]+\\)|unselected_for_matrix_choice\\([\\-a-zA-Z0-9_]+\\))$"},statement_groups:{type:"array",items:{type:"object",properties:{statements:{type:"array",items:{$ref:"#/$defs/statement"}},id:{type:"string",description:"The id of the group."},display:{type:"string",description:"The display name of the group"},display_logic:{type:"string",description:"A boolean expression determining if the group should be displayed"},randomization:{$ref:"#/$defs/randomization"}},required:["statements","id","display"],additionalProperties:!1}},choices:{type:"array",items:{$ref:"#/$defs/choice"}},dynamic_choices:{type:"string",description:"Carry forward choices from a previous question",pattern:"^[a-zA-Z][a-zA-Z0-9_]*/(all|selected|all_entered_text|selected_entered_text|not_selected|for_matrix_choice\\([\\-a-zA-Z0-9_]+\\)|unselected_for_matrix_choice\\([\\-a-zA-Z0-9_]+\\))$"},choice_groups:{type:"array",items:{type:"object",properties:{choices:{type:"array",items:{$ref:"#/$defs/choice"}},id:{type:"string",description:"The id of the group."},display:{type:"string",description:"The display name of the group"},display_logic:{type:"string",description:"A boolean expression determining if the group should be displayed"},randomization:{$ref:"#/$defs/randomization"}},required:["choices","id","display"],additionalProperties:!1}},randomization:{$ref:"#/$defs/randomization"},configuration:{type:"object",properties:{choice_column_width_pixels:{type:"integer",description:"Size of the column with the choice descriptions in a matrix question"}},additionalProperties:!1}},additionalProperties:!1,required:["text"],oneOf:[{$ref:"#/$defs/question-mc-horizontal"},{$ref:"#/$defs/question-mc-vertical"},{$ref:"#/$defs/question-matrix"},{$ref:"#/$defs/question-text"},{$ref:"#/$defs/question-description"}]},"question-mc-horizontal":{type:"object",properties:{type:{enum:["mc-single","mc-multi"]},position:{const:"horizontal"}},required:["id","type","position","choices"],not:{anyOf:[{required:["choice_groups"]},{required:["dynamic_choices"]},{required:["statements"]},{required:["dynamic_statements"]},{required:["statement_groups"]}]}},"question-mc-vertical":{type:"object",properties:{type:{enum:["mc-single","mc-multi"]},position:{const:"vertical"}},required:["id","type"],not:{anyOf:[{required:["statements"]},{required:["dynamic_statements"]},{required:["statement_groups"]}]},oneOf:[{anyOf:[{required:["choices"]},{required:["dynamic_choices"]}],not:{required:["choice_groups"]}},{required:["choice_groups"],not:{anyOf:[{required:["choices"]},{required:["dynamic_choices"]}]}}]},"question-matrix":{type:"object",properties:{type:{enum:["matrix-single","matrix-multi"]}},required:["id","type","choices"],not:{anyOf:[{required:["dynamic_choices"]},{required:["choice_groups"]}]},oneOf:[{anyOf:[{required:["statements"]},{required:["dynamic_statements"]}],not:{required:["statement_groups"]}},{required:["statement_groups"],not:{anyOf:[{required:["statements"]},{required:["dynamic_statements"]}]}}]},"question-text":{type:"object",properties:{type:{enum:["text-single","text-multi"]}},required:["id","type"],not:{anyOf:[{required:["choices"]},{required:["choice_groups"]},{required:["dynamic_choices"]},{required:["statements"]},{required:["statement_groups"]},{required:["dynamic_statements"]},{required:["randomization"]}]}},"question-description":{type:"object",properties:{type:{const:"description"}},not:{anyOf:[{required:["choices"]},{required:["choice_groups"]},{required:["dynamic_choices"]},{required:["statements"]},{required:["statement_groups"]},{required:["dynamic_statements"]},{required:["randomization"]}]}},statement:{type:"object",properties:{id:{type:"string",pattern:"^[a-zA-Z][a-zA-Z0-9_]*$",description:"The id of the statement"},display:{type:"string",description:"The statement name, as shown to the surveyee"},display_logic:{type:"string",description:"A boolean expression determining if the statement should be displayed"}},required:["id","display"],additionalProperties:!1},choice:{type:"object",properties:{display:{type:"string",description:"The choice name, as shown to the surveyee"},id:{type:"string",pattern:"^[a-zA-Z][a-zA-Z0-9_]*$",description:"The id of the choice"},value:{type:"integer",description:"The value the choice"},display_logic:{type:"string",description:"A boolean expression determining if the choice should be displayed"},text_input:{type:"string",enum:["no","optional","forced"],description:"If a textbox should appear next to the choice, and if it should be mandatory to fill it in if the choice is selected"},exclusive_answer:{type:"boolean",description:"If true, this choice can't be combined with other choices in this question"}},required:["display"],oneOf:[{required:["value"]},{required:["id"]}],additionalProperties:!1},randomization:{type:"object",description:"Configuration of the display order randomization of choices, statements or groups.",properties:{type:{type:"string",description:"The type of randomization: randomize all items, a subset of them, or using constrained randomization",enum:["all","subset","constrained"]},total:{type:"integer",description:"Maximum number of items to show"},order:{type:"string",description:"A space separated string containing the order of the items; each 'word' is either an id of some item or the wildcard $ representing the remaining items"}},required:["type"],oneOf:[{properties:{type:{const:"all"}},not:{required:["total","order"]}},{properties:{type:{const:"subset"}},required:["total"],not:{required:["order"]}},{properties:{type:{const:"constrained"}},required:["order"]}],additionalProperties:!1}},Ce={$id:Ht,$schema:Jt,title:Yt,type:Kt,properties:en,additionalProperties:tn,required:nn,$defs:sn};const rn=/\$\{m:([^\}]+)\}/g,an=100,_e=(s,t)=>{if(typeof t=="string"){let n=t,i=0;for(;i<an;){const r=n.replace(rn,(a,o)=>{if(s[o]===void 0)throw new Error(`Undefined macro: ${o}`);return s[o]});if(r===n)return r;n=r,i+=1}throw new Error(`Failed to finish interpolate macros - cyclic macros!? Stuck at: ${t}"`)}return typeof t=="object"&&Object.keys(t).forEach(n=>{t[n]=_e(s,t[n])}),t},Qe=s=>(s.sections=_e(s.macros||{},s.sections),s),on="(?<questionId>[a-zA-Z][a-zA-Z0-9_]*)",ln="((?<expressionWithoutIdentifier>all|all_entered_text|selected|selected_entered_text|not_selected)|(?<expressionWithIdentifier>for_matrix_choice|unselected_for_matrix_choice)(\\((?<identifier>[\\-a-zA-Z0-9_]+)\\)))",Me=new RegExp(`^${on}/${ln}$`);var w=(s=>(s.ALL="all",s.ALL_ENTERED_TEXT="all_entered_text",s.SELECTED="selected",s.SELECTED_ENTERED_TEXT="selected_entered_text",s.NOT_SELECTED="not_selected",s.FOR_MATRIX_CHOICE="for_matrix_choice",s.UNSELECTED_FOR_MATRIX_CHOICE="unselected_for_matrix_choice",s))(w||{});const je=s=>Me.test(s),S=s=>{const t=s.match(Me)?.groups;if(!t)throw new Error(`Invalid locator expression: ${s}`);const n=t.expressionWithoutIdentifier||t.expressionWithIdentifier||"all",i={questionId:t.questionId,expression:n};if(t.identifier){const r=isNaN(parseInt(t.identifier,10))?t.identifier:parseInt(t.identifier,10);i.identifier=r}return i};var _n=(s=>(s.DuplicateResponse="DUPLICATE_RESPONSE",s.InternalError="INTERNAL_ERROR",s.InvalidDates="INVALID_DATES",s.InvalidId="INVALID_ID",s.InvalidParticipants="INVALID_PARTICIPANTS",s.InvalidResponse="INVALID_RESPONSE",s.MissingTitle="MISSING_TITLE",s.OverlappingSurveys="OVERLAPPING_SURVEYS",s.ParticipantsFrozen="PARTICIPANTS_FROZEN",s.SurveyIsClosed="SURVEY_IS_CLOSED",s.Unauthorized="UNAUTHORIZED",s))(_n||{}),cn=(s=>(s.Horizontal="HORIZONTAL",s.Vertical="VERTICAL",s))(cn||{}),pn=(s=>(s.Optional="OPTIONAL",s.Request="REQUEST",s.Required="REQUIRED",s))(pn||{}),I=(s=>(s.Description="DESCRIPTION",s.MatrixMulti="MATRIX_MULTI",s.MatrixSingle="MATRIX_SINGLE",s.McMulti="MC_MULTI",s.McSingle="MC_SINGLE",s.TextMulti="TEXT_MULTI",s.TextSingle="TEXT_SINGLE",s))(I||{}),un=(s=>(s.All="ALL",s.Constrained="CONSTRAINED",s.Subset="SUBSET",s))(un||{}),dn=(s=>(s.Finalized="FINALIZED",s.Partial="PARTIAL",s))(dn||{}),hn=(s=>(s.Active="ACTIVE",s.Published="PUBLISHED",s))(hn||{}),mn=(s=>(s.Q1="Q1",s.Q2="Q2",s.Q3="Q3",s.Q4="Q4",s))(mn||{});const W=(s,t="camelCase")=>{const n=t==="camelCase"?V.default.camelCase:V.default.snakeCase;return V.default.transform(s,(i,r,a)=>{const o=typeof a=="string"?n(a):a;i[o]=V.default.isObject(r)&&!(r instanceof Date)?W(r,t):r})};function fn(s){const t=structuredClone(s);return{...t,...t.template,sections:t.sections.map(n=>({...W(n),pages:n.pages.map((i,r)=>({...i,id:`${n.id}-${r}`,questions:yn(t,n,i.questions)}))}))}}function yn(s,t,n){return n.map(i=>gn(s.template.id,t,i))}function gn(s,t,n){return{...W({...n,choiceGroups:n.choice_groups?.map(i=>({...i,randomization:ce(i.randomization)})),statementGroups:n.statement_groups?.map(i=>({...i,randomization:ce(i.randomization)})),randomization:ce(n.randomization)}),id:Fe(s,n),type:ue(n.type),layout:xn(n.layout),required:wn(n.required),label:t.name}}function ce(s){return s?{type:Ue(s.type),order:s.order?.split(" "),total:s.total}:void 0}function Ue(s){return s.toUpperCase()}function Fe(s,t){return`${s}.${t.id}`}const pe=s=>s.split(".").pop();function ue(s="description"){return s.replace("-","_").toUpperCase()}function xn(s){return s?.toUpperCase()}function wn(s="optional"){return s.replace("-","_").toUpperCase()}function de(s){return structuredClone(s).sections.flatMap(t=>t.pages.flatMap(n=>n.questions))}function vn(s={}){return s.transformer&&s.transformer.constructor.name==="object"&&(s.transformer=Z.fromObj(s.transformer)),ft._load_from_dict({data:Ii,memo:Ri,...s})}const Be={};class Ze{}const X={},Ge={escape(s){return s.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")},compile(s,t){return new RegExp(s,t)},error:SyntaxError};function Tn(s,t,n,i){const r=s.compile(t,i).exec(n);if(r!=null)return r[0]}class Ve{constructor(t,n,i,r,a=!1){this.terminals=t,this.g_regex_flags=n,this.re_=i,this.use_bytes=r,this.match_whole=a,this.allowed_types=new Set(this.terminals.map(o=>o.name)),this._regexps=this._build_mres(t)}_build_mres(t){let n=this.match_whole?"$":"",i=On(t,a=>a.pattern.flags.join("")),r=[];for(let[a,o]of i){const l=o.map(p=>`(?<${p.name}>${p.pattern.to_regexp()+n})`).join("|");r.push(new RegExp(l,this.g_regex_flags+a+"y"))}return r}match(t,n){for(const i of this._regexps){i.lastIndex=n;let r=i.exec(t);if(r){let a=null;for(let[o,l]of Object.entries(r.groups))if(l){a=o;break}return[r[0],a]}}}}const We=typeof require<"u"&&require("util");class Xe{}const U={};function g(s){return Object.entries(s)}function he(s){return Object.keys(s)}function bn(s,t){t===void 0&&(t=Object.keys(s)[0]);let n=s[t];return delete s[t],n}function He(s,t,n=null){return s[t]||n}function Je(s,t){if(s.constructor.name==="Map")for(const[n,i]of g(t))s.set(n,i);else for(const[n,i]of g(t))s[n]=i}function En(s){return function(){return new s(...arguments)}}function h(s){let t=0,n=[...arguments].slice(1);return s.replace(/%([sr])/g,function(){const i=arguments[1],r=n[t++];return i==="r"?We?We.inspect(r,!1,null,!0):JSON.stringify(r,null,0):r})}function In(s,t){let n=new Set(s);for(const i of t)n.add(i);return n}function Ye(s,t){return[...s].filter(n=>!t.has(n))}function Ke(s){return{...s}}function et(s){return!!s}function me(s){return Object.create(s.prototype)}function R(s){if(typeof s=="object"){let t=Object.create(Object.getPrototypeOf(s));return Object.assign(t,s)}return s}function H(s){return new Set(s)}function fe(s){return s&&s.constructor.name==="Object"}function Rn(s){return s&&s.constructor.name==="Array"}function Nn(s){return typeof s=="function"}function*F(s,t=0){let n=t;for(const i of s)yield[n++,i]}function qn(s){for(const t of s)if(t)return!0;return!1}function tt(s,t){return t.filter(s||et)}function J(s){let t=[...arguments].slice(1);return function(){return s(...t,...arguments)}}class ye extends Error{}function v(s){return s[s.length-1]}function $(s){return function(){let t=new s(...arguments);return t.__call__.bind(t)}}function N(s,t){return Array.from({length:t},()=>s).flat()}function nt(s){return/^[A-Z_$]*$/.test(s)}function ge(s,t,n){const i=s.split(t);return n?i.splice(-n-1):i}function xe(s,t){let n=new RegExp(t,"g");return(s.match(n)||[]).length}function kn(s,t){for(let n of s)if(!t.has(n))return!1;return!0}function*On(s,t){let n=[],i=null;for(const r of s){const a=t(r);i&&a!=i&&(yield[i,n],n=[]),n.push(r),i=a}yield[i,n]}let q=class extends Error{};class k extends q{}function we(s,t,n="Got %r, expected one of %s"){if(!t.includes(s))throw new k(h(n,s,t))}class Y extends q{}class An extends q{}class B extends q{}class A extends q{pos_in_stream=null;_terminals_by_name=null;get_context(t,n=40){let i,r,a=this.pos_in_stream,o=max(a-n,0),l=a+n;return t instanceof bytes?(r=v(ge(t.slice(o,a),`
|
|
2
|
-
`,1)),i=t.slice(a,l).split(`
|
|
3
|
-
`,1)[0],(r+i+`
|
|
4
|
-
`+" "*r.expandtabs().length+`^
|
|
5
|
-
`).decode("ascii","backslashreplace")):(r=v(ge(t.slice(o,a),`
|
|
6
|
-
`,1)),i=t.slice(a,l).split(`
|
|
7
|
-
`,1)[0],r+i+`
|
|
8
|
-
`+" "*r.expandtabs().length+`^
|
|
9
|
-
`)}match_examples(t,n,i=!1){fe(n)&&(n=g(n));let r=[null,!1];for(const[a,[o,l]]of F(n))for(const[p,c]of F(l))try{t(c)}catch(_){if(_ instanceof A){if(_.state.eq(this.state)){if(_.token===this.token)return o;i&&_.token.type===this.token.type&&!v(r)&&(r=[o,!0]),r[0]===null&&(r=[o,!1])}}else throw _}return r[0]}_format_expected(t){let n;return this._terminals_by_name&&(n=this._terminals_by_name,t=t.map(i=>i in n?n[i].user_repr():i)),h(`Expected one of:
|
|
10
|
-
* %s
|
|
11
|
-
`,t.join(`
|
|
12
|
-
* `))}}class Sn extends A{constructor(t,n=null,i=null){super(),this.expected=t,this.state=n,this.token=new f("<EOF>",""),this.pos_in_stream=-1,this.line=-1,this.column=-1,this._terminals_by_name=i}}class D extends A{constructor({seq:t,lex_pos:n,line:i,column:r,allowed:a=null,considered_tokens:o=null,state:l=null,token_history:p=null,terminals_by_name:c=null,considered_rules:_=null}={}){super(),this.line=i,this.column=r,this.pos_in_stream=n,this.state=l,this._terminals_by_name=c,this.allowed=a,this.considered_tokens=o,this.considered_rules=_,this.token_history=p,this.char=t[n]}}let P=class extends A{constructor({token:t,expected:n,considered_rules:i=null,state:r=null,interactive_parser:a=null,terminals_by_name:o=null,token_history:l=null}={}){super(),this.line=t&&t.line||"?",this.column=t&&t.column||"?",this.pos_in_stream=t&&t.start_pos||null,this.state=r,this.token=t,this.expected=n,this._accepts=Be,this.considered_rules=i,this.interactive_parser=a,this._terminals_by_name=o,this.token_history=l}get accepts(){return this._accepts===Be&&(this._accepts=this.interactive_parser&&this.interactive_parser.accepts()),this._accepts}};class ve extends q{constructor(t,n,i){let r=h(`Error trying to process rule "%s":
|
|
13
|
-
|
|
14
|
-
%s`,t,i);super(r),this.rule=t,this.obj=n,this.orig_exc=i}}function $n(s,t=null,n=null){let i,r,a=new Map;for(const o of s)i=t!==null?t(o):o,r=n!==null?n(o):o,a.has(i)?a.get(i).push(r):a.set(i,[r]);return a}function K(s,t,n){let i;return fe(s)?"__type__"in s?(i=t[s.__type__],i.deserialize(s,n)):"@"in s?n[s["@"]]:Object.fromEntries(g(s).map(([r,a])=>[r,K(a,t,n)])):Rn(s)?s.map(r=>K(r,t,n)):s}let T=class{static deserialize(t,n){const i=this;let r=i&&i.__serialize_fields__;if("@"in t)return n[t["@"]];let a=me(i);for(const o of r)if(t&&o in t)a[o]=K(t[o],bi,n);else throw new KeyError("Cannot find key for class",i,e);return"_deserialize"in a&&a._deserialize(),a}};class zn extends T{static get __serialize_fields__(){return["memoized"]}constructor(t){super(),this.types_to_memoize=t,this.memoized=new Enumerator}in_types(t){return t instanceof this.types_to_memoize}serialize(){return _serialize(this.memoized.reversed(),null)}static deserialize(t,n,i){return K(t,n,i)}}class it{constructor(){this.empty=!0}}class y{constructor(t,n,i=null){this.data=t,this.children=n,this._meta=i}get meta(){return this._meta===null&&(this._meta=new it),this._meta}repr(){return h("Tree(%r, %r)",this.data,this.children)}_pretty_label(){return this.data}_pretty(t,n){if(this.children.length===1&&!(this.children[0]instanceof y))return[N(n,t).join(""),this._pretty_label()," ",h("%s",this.children[0].value),`
|
|
15
|
-
`];let i=[N(n,t).join(""),this._pretty_label(),`
|
|
16
|
-
`];for(const r of this.children)r instanceof y?i.push(...r._pretty(t+1,n)):i.push(N(n,t+1).join(""),h("%s",r.value),`
|
|
17
|
-
`);return i}pretty(t=" "){return this._pretty(0,t).join("")}eq(t){return t&&this&&t&&this&&t.children&&this.children&&t.data&&this.data?this.data===t.data&&this.children===t.children:!1}iter_subtrees(){let t=[this],n=new Map;for(const i of t)n.set(i,i),t.push(...[...i.children].reverse().filter(r=>r instanceof y&&!n.has(r)).map(r=>r));return t=void 0,[...n.values()].reverse()}find_pred(t){return tt(t,this.iter_subtrees())}find_data(t){return this.find_pred(n=>n.data===t)}*scan_values(t){for(const n of this.children)if(n instanceof y)for(const i of n.scan_values(t))yield i;else t(n)&&(yield n)}*iter_subtrees_topdown(){let t,n=[this];for(;n.length;)if(t=n.pop(),t instanceof y){yield t;for(const i of[...t.children].reverse())n.push(i)}}copy(){return type(this)(this.data,this.children)}set(t,n){this.data=t,this.children=n}}let Z=class extends Ze{static get __visit_tokens__(){return!0}constructor(t=!0){super(),this.__visit_tokens__=t}static fromObj(t,...n){class i extends this{}for(let[r,a]of Object.entries(t))i.prototype[r]=a;return new i(...n)}_call_userfunc(t,n=null){let i,r,a=n!==null?n:t.children;if(t&&t.data&&this&&this[t.data]){i=this&&this[t.data];try{return r=i&&i.visit_wrapper||null,r!==null?i.visit_wrapper(i,t.data,a,t.meta):i(a)}catch(o){throw o instanceof Y?o:o instanceof Error?new ve(t.data,t,o):o}}else return this.__default__(t.data,a,t.meta)}_call_userfunc_token(t){let n;if(t&&t.type&&this&&this[t.type]){n=this&&this[t.type];try{return n(t)}catch(i){throw i instanceof Y?i:i instanceof Error?new ve(t.type,t,i):i}}else return this.__default_token__(t)}*_transform_children(t){let n;for(const i of t)i instanceof y?n=this._transform_tree(i):this.__visit_tokens__&&i instanceof f?n=this._call_userfunc_token(i):n=i,n!==X&&(yield n)}_transform_tree(t){let n=[...this._transform_children(t.children)];return this._call_userfunc(t,n)}transform(t){return this._transform_tree(t)}__default__(t,n,i){return new y(t,n,i)}__default_token__(t){return t}};class st extends Z{_transform_tree(t){return this._call_userfunc(t)}transform(t){for(const n of t.iter_subtrees())n.children=[...this._transform_children(n.children)];return this._transform_tree(t)}}class Dn extends Z{transform(t){let n,i,r,a=[],o=[t];for(;o.length;){const c=o.pop();a.push(c),c instanceof y&&o.push(...c.children)}let l=[];for(const c of[...a].reverse())c instanceof y?(r=c.children.length,r?(n=l.slice(-r),l.splice(-r)):n=[],i=this._call_userfunc(c,n),i!==X&&l.push(i)):this.__visit_tokens__&&c instanceof f?(i=this._call_userfunc_token(c),i!==X&&l.push(i)):l.push(c);let[p]=l;return p}}class Pn extends Z{_transform_tree(t){return t.children=[...this._transform_children(t.children)],this._call_userfunc(t)}}class Te{_call_userfunc(t){const n=this[t.data];return n?n(t):this.__default__(t)}__default__(t){return t}__class_getitem__(t){return cls}}class Ln extends Te{visit(t){for(const n of t.iter_subtrees())this._call_userfunc(n);return t}visit_topdown(t){for(const n of t.iter_subtrees_topdown())this._call_userfunc(n);return t}}class Cn extends Te{visit(t){for(const n of t.children)n instanceof y&&this.visit(n);return this._call_userfunc(t),t}visit_topdown(t){this._call_userfunc(t);for(const n of t.children)n instanceof y&&this.visit_topdown(n);return t}}class Qn extends Ze{visit(t){return t.data in this?this[t.data](t):this.__default__(t)}visit_children(t){return t.children.map(n=>n instanceof y?this.visit(n):n)}__default__(t){return this.visit_children(t)}}var Mn=0;class be extends T{is_term=U;constructor(t){super(),this.name=t}eq(t){return this.is_term===t.is_term&&this.name===t.name}repr(){return h("%s(%r)",type(this).name,this.name)}static get fullrepr(){return property(__repr__)}get fullrepr(){return this.constructor.fullrepr}renamed(t){return type(this)(t(this.name))}}class Ee extends be{static get __serialize_fields__(){return["name","filter_out"]}get is_term(){return!0}constructor(t,n=!1){super(),this.name=t,this.filter_out=n}get fullrepr(){return h("%s(%r, %r)",type(this).name,this.name,this.filter_out)}renamed(t){return type(this)(t(this.name),this.filter_out)}}class Ie extends be{static get __serialize_fields__(){return["name"]}get is_term(){return!1}}class ee extends T{static get __serialize_fields__(){return["keep_all_tokens","expand1","priority","template_source","empty_indices"]}constructor(t=!1,n=!1,i=null,r=null,a=[]){super(),this.keep_all_tokens=t,this.expand1=n,this.priority=i,this.template_source=r,this.empty_indices=a}repr(){return h("RuleOptions(%r, %r, %r, %r)",this.keep_all_tokens,this.expand1,this.priority,this.template_source)}}class M extends T{static get __serialize_fields__(){return["origin","expansion","order","alias","options"]}static get __serialize_namespace__(){return[Ee,Ie,ee]}constructor(t,n,i=0,r=null,a=null){super(),this.origin=t,this.expansion=n,this.alias=r,this.order=i,this.options=a||new ee,this._hash=[this.origin,this.expansion]}_deserialize(){this._hash=[this.origin,this.expansion]}repr(){return h("Rule(%r, %r, %r, %r)",this.origin,this.expansion,this.alias,this.options)}eq(t){return t instanceof M?this.origin===t.origin&&this.expansion===t.expansion:!1}}class Re extends T{constructor(t,n=[],i=null){super(),this.value=t,this.flags=H(n),this.raw=i}repr(){return repr(this.to_regexp())}eq(t){return type(this)===type(t)&&this.value===t.value&&this.flags===t.flags}to_regexp(){throw new NotImplementedError}get min_width(){throw new NotImplementedError}get max_width(){throw new NotImplementedError}_get_flags(t){return t}}class Ne extends Re{static get __serialize_fields__(){return["value","flags"]}static get type(){return"str"}to_regexp(){return this._get_flags(Ge.escape(this.value))}get min_width(){return this.value.length}get max_width(){return this.value.length}}class qe extends Re{static get __serialize_fields__(){return["value","flags","_width"]}static get type(){return"re"}to_regexp(){return this._get_flags(this.value)}_get_width(){return this._width===null&&(this._width=get_regexp_width(this.to_regexp())),this._width}get min_width(){return this._get_width()[0]}get max_width(){return this._get_width()[1]}}let te=class extends T{static get __serialize_fields__(){return["name","pattern","priority"]}static get __serialize_namespace__(){return[Ne,qe]}constructor(t,n,i=Mn){super(),this.name=t,this.pattern=n,this.priority=i}repr(){return h("%s(%r, %r)",type(this).name,this.name,this.pattern)}user_repr(){return this.name.startsWith("__")?this.pattern.raw||this.name:this.name}};class f{value;type;constructor(t,n,i=null,r=null,a=null,o=null,l=null,p=null){this.type=t,this.start_pos=i,this.value=n,this.line=r,this.column=a,this.end_line=o,this.end_column=l,this.end_pos=p}update(t=null,n=null){return f.new_borrow_pos(t!==null?t:this.type,n!==null?n:this.value,this)}static new_borrow_pos(t,n,i){const r=this;return new r(t,n,i.start_pos,i.line,i.column,i.end_line,i.end_column,i.end_pos)}repr(){return h("Token(%r, %r)",this.type,this.value)}eq(t){return t instanceof f&&this.type!==t.type?!1:str.__eq__(this,t)}static get __hash__(){return str.__hash__}}class $e{constructor(t){this.newline_char=t,this.char_pos=0,this.line=1,this.column=1,this.line_start_pos=0}eq(t){return t instanceof $e?this.char_pos===t.char_pos&&this.newline_char===t.newline_char:U}feed(t,n=!0){let i;n&&(i=xe(t,this.newline_char),i&&(this.line+=i,this.line_start_pos=this.char_pos+t.lastIndexOf(this.newline_char)+1)),this.char_pos+=t.length,this.column=this.char_pos-this.line_start_pos+1}}class jn{constructor(t){this.scanner=t}__call__(t){let n,i=this.scanner.match(t.value,0);return i&&([n,t.type]=i),t}}const Un=$(jn);class Fn{constructor(t,n,i){this.callback1=t,this.callback2=n,this.cond=i}__call__(t){let n=this.callback1(t);return this.cond(n)?this.callback2(t):n}}const Bn=$(Fn);function Zn(s,t,n,i){let r,a,o=$n(s,c=>c.pattern.constructor.type),l=new Set,p={};for(const c of o.get("re")||[]){a=[];for(const _ of o.get("str")||[])_.priority===c.priority&&(r=_.pattern.value,r===Tn(n,c.pattern.to_regexp(),r,t)&&(a.push(_),kn(new Set(_.pattern.flags),new Set(c.pattern.flags))&&l.add(_)));a.length&&(p[c.name]=new Un(new Ve(a,t,n,i,!0)))}return[s.filter(c=>!l.has(c)).map(c=>c),p]}function Gn(s){return s.includes(`
|
|
18
|
-
`)||s.includes("\\n")||s.includes("\\s")||s.includes("[^")||s.includes("(?s")&&s.includes(".")}class ze{constructor(t,n=null,i=null){this.text=t,this.line_ctr=n||new $e(`
|
|
19
|
-
`),this.last_token=i}eq(t){return t instanceof ze?this.text===t.text&&this.line_ctr===t.line_ctr&&this.last_token===t.last_token:U}}class rt{constructor(t,n){this.lexer=t,this.state=n}static from_text(t,n){return new this(t,new ze(n))}lex(t){return this.lexer.lex(this.state,t)}}class ne extends Xe{lex(t,n){return U}}function Vn(s,t){s.sort((n,i)=>{let r=t(n),a=t(i);for(let o=0;o<r.length;o++){if(r[o]>a[o])return 1;if(r[o]<a[o])return-1}return 0})}class ie extends ne{constructor(t){super();let n=[...t.terminals];if(this.re=t.re_module,!t.skip_validation){for(const i of n){try{this.re.compile(i.pattern.to_regexp(),t.g_regex_flags)}catch(r){throw r instanceof this.re.error?new B(h("Cannot compile token %s: %s",i.name,i.pattern)):r}if(i.pattern.min_width===0)throw new B(h("Lexer does not allow zero-width terminals. (%s: %s)",i.name,i.pattern))}if(!(new Set(t.ignore)<=new Set(n.map(i=>i.name))))throw new B(h("Ignore terminals are not defined: %s",Ye(new Set(t.ignore),new Set(n.map(i=>i.name)))))}this.newline_types=H(n.filter(i=>Gn(i.pattern.to_regexp())).map(i=>i.name)),this.ignore_types=H(t.ignore),Vn(n,i=>[-i.priority,-i.pattern.max_width,-i.pattern.value.length,i.name]),this.terminals=n,this.user_callbacks=t.callbacks,this.g_regex_flags=t.g_regex_flags,this.use_bytes=t.use_bytes,this.terminals_by_name=t.terminals_by_name,this._scanner=null}_build_scanner(){let t;[t,this.callback]=Zn(this.terminals,this.g_regex_flags,this.re,this.use_bytes);for(const[n,i]of g(this.user_callbacks))n in this.callback?this.callback[n]=new Bn(this.callback[n],i,r=>r.type===n):this.callback[n]=i;this._scanner=new Ve(t,this.g_regex_flags,this.re,this.use_bytes)}get scanner(){return this._scanner===null&&this._build_scanner(),this._scanner}match(t,n){return this.scanner.match(t,n)}*lex(t,n){try{for(;;)yield this.next_token(t,n)}catch(i){if(!(i instanceof ye))throw i}}next_token(t,n=null){let i,r,a,o,l=t.line_ctr;for(;l.char_pos<t.text.length;){if(r=this.match(t.text,l.char_pos),!r)throw i=Ye(this.scanner.allowed_types,this.ignore_types),i||(i=new Set(["<END-OF-FILE>"])),new D({seq:t.text,lex_pos:l.char_pos,line:l.line,column:l.column,allowed:i,token_history:t.last_token&&[t.last_token],state:n,terminals_by_name:this.terminals_by_name});let[p,c]=r;if(this.ignore_types.has(c))c in this.callback&&(o=new f(c,p,l.char_pos,l.line,l.column),this.callback[c](o)),l.feed(p,this.newline_types.has(c));else{if(a=new f(c,p,l.char_pos,l.line,l.column),l.feed(p,this.newline_types.has(c)),a.end_line=l.line,a.end_column=l.column,a.end_pos=l.char_pos,a.type in this.callback&&(a=this.callback[a.type](a),!(a instanceof f)))throw new B(h("Callbacks must return a token (returned %r)",a));return t.last_token=a,a}}throw new ye(this)}}class Wn extends ne{constructor({conf:t,states:n,always_accept:i=[]}={}){super();let r,a,o,l=[...t.terminals],p=t.terminals_by_name,c=R(t);c.terminals=l;let _=new Map;this.lexers={};for(let[d,m]of g(n))r=H(m),_.has(r)?a=_.get(r):(m=In(new Set(m),[...new Set(t.ignore),...new Set(i)]),o=R(c),o.terminals=[...m].filter(u=>u in p).map(u=>p[u]),a=new ie(o),_.set(r,a)),this.lexers[d]=a;this.root_lexer=new ie(c)}*lex(t,n){let i,r,a;try{for(;;)r=this.lexers[n.position],yield r.next_token(t,n)}catch(o){if(!(o instanceof ye))if(o instanceof D)try{throw i=t.last_token,a=this.root_lexer.next_token(t,n),new P({token:a,expected:o.allowed,state:n,token_history:[i],terminals_by_name:this.root_lexer.terminals_by_name})}catch(l){throw l}else throw o}}}class at extends T{static get __serialize_fields__(){return["terminals","ignore","g_regex_flags","use_bytes","lexer_type"]}static get __serialize_namespace__(){return[te]}constructor({terminals:t,re_module:n,ignore:i=[],postlex:r=null,callbacks:a=null,g_regex_flags:o="",skip_validation:l=!1,use_bytes:p=!1}={}){super(),this.terminals=t,this.terminals_by_name=Object.fromEntries(this.terminals.map(c=>[c.name,c])),this.ignore=i,this.postlex=r,this.callbacks=Object.keys(a).length||{},this.g_regex_flags=o,this.re_module=n,this.skip_validation=l,this.use_bytes=p,this.lexer_type=null}_deserialize(){this.terminals_by_name=Object.fromEntries(this.terminals.map(t=>[t.name,t]))}}class ot extends T{static get __serialize_fields__(){return["rules","start","parser_type"]}constructor(t,n,i){super(),this.rules=t,this.callbacks=n,this.start=i,this.parser_type=null}}class Xn{constructor(t){this.node_builder=t}__call__(t){return t.length===1?t[0]:this.node_builder(t)}}const Hn=$(Xn);class Jn{constructor(t,n=null){this.node_builder=t,this.node_filter=n}__call__(t){let n,i,r,a=this.node_builder(t);return a instanceof y&&(r=a.meta,n=this._pp_get_meta(t),n!==null&&("line"in r||(r.line=n&&n.container_line||n.line,r.column=n&&n.container_column||n.column,r.start_pos=n&&n.container_start_pos||n.start_pos,r.empty=!1),r.container_line=n&&n.container_line||n.line,r.container_column=n&&n.container_column||n.column),i=this._pp_get_meta([...t].reverse()),i!==null&&("end_line"in r||(r.end_line=i&&i.container_end_line||i.end_line,r.end_column=i&&i.container_end_column||i.end_column,r.end_pos=i&&i.container_end_pos||i.end_pos,r.empty=!1),r.container_end_line=i&&i.container_end_line||i.end_line,r.container_end_column=i&&i.container_end_column||i.end_column)),a}_pp_get_meta(t){for(const n of t)if(!(this.node_filter!==null&&!this.node_filter(n))){if(n instanceof y){if(!n.meta.empty)return n.meta}else if(n instanceof f)return n}}}const lt=$(Jn);function Yn(s){if(Nn(s))return J({unknown_param_0:lt,node_filter:s});if(s===!0)return lt;if(s===!1)return null;throw new k(h("Invalid option for propagate_positions: %r",s))}class ke{constructor(t,n,i){this.node_builder=i,this.to_include=t,this.append_none=n}__call__(t){let n=[];for(const[i,r,a]of this.to_include)a&&n.push(...N([null],a)),r?n.push(...t[i].children):n.push(t[i]);return this.append_none&&n.push(...N([null],this.append_none)),this.node_builder(n)}}const Kn=$(ke);class ei extends ke{__call__(t){let n=[];for(const[i,r,a]of this.to_include)a&&n.push(...N([null],a)),r?n.length?n.push(...t[i].children):n=t[i].children:n.push(t[i]);return this.append_none&&n.push(...N([null],this.append_none)),this.node_builder(n)}}const ti=$(ei);class ni extends ke{constructor(t,n){super(),this.node_builder=n,this.to_include=t}__call__(t){let n=[];for(const[i,r]of this.to_include)r?n.length?n.push(...t[i].children):n=t[i].children:n.push(t[i]);return this.node_builder(n)}}const ii=$(ni);function si(s){return!s.is_term&&s.name.startsWith("_")}function ri(s,t,n,i){let r,a;i.length?(a=i.map(p=>(0+p).toString()).join(""),r=a.split("0").map(p=>p.length)):r=N([0],s.length+1);let o=[],l=0;for(const[p,c]of F(s))l+=r[p],(t||!(c.is_term&&c.filter_out))&&(o.push([p,si(c),l]),l=0);if(l+=r[s.length],i.length||o.length<s.length||qn(o.map(([p,c,_])=>c)))return(i.length||n).length?J(n?Kn:ti,o,l):J(ii,o.map(([p,c,_])=>[p,c]))}function ai(s){function t(n){let i=new y(s.name,n);return s(i)}return t=wraps(s)(t),t}function oi(s,t,n){if(n===_vargs_meta||n===_vargs_meta_inline)throw new NotImplementedError("Meta args not supported for internal transformer");function i(r){return n(s,t,r,null)}return i=wraps(s)(i),i}class li{constructor(t,n,i=!1,r=!1,a=!1){this.tree_class=n,this.propagate_positions=i,this.ambiguous=r,this.maybe_placeholders=a,this.rule_builders=[...this._init_builders(t)]}*_init_builders(t){let n,i,r,a,o=Yn(this.propagate_positions);for(const l of t)r=l.options,i=r.keep_all_tokens,n=r.expand1,a=[...tt(null,[n&&!l.alias&&Hn,ri(l.expansion,i,this.ambiguous,this.maybe_placeholders?r.empty_indices:[]),o])],yield[l,a]}create_callback(t=null){let n,i,r,a=new Map;for(const[o,l]of this.rule_builders){i=o.alias||o.options.template_source||o.origin.name,t&&t[i]?(n=t&&t[i],r=n&&n.visit_wrapper||null,r!==null?n=oi(n,i,r):t instanceof st&&(n=ai(n))):n=J(this.tree_class,i);for(const p of l)n=p(n);if(a.has(o))throw new Y(h("Rule '%s' already exists",o));a.set(o,n)}return a}}class _t extends T{constructor({parser_conf:t,debug:n=!1}={}){super();let i=new LALR_Analyzer({unknown_param_0:t,debug:n});i.compute_lalr();let r=t.callbacks;this._parse_table=i.parse_table,this.parser_conf=t,this.parser=new ct(i.parse_table,r,n)}static deserialize(t,n,i,r=!1){let a=me(this);return a._parse_table=pi.deserialize(t,n),a.parser=new ct(a._parse_table,i,r),a}serialize(t){return this._parse_table.serialize(t)}parse_interactive(t,n){return this.parser.parse({lexer:t,start:n,start_interactive:!0})}parse({lexer:t,start:n,on_error:i=null}={}){let r,a;try{return this.parser.parse({lexer:t,start:n})}catch(o){if(o instanceof A){if(i===null)throw o;for(;;){if(o instanceof D&&(a=o.interactive_parser.lexer_thread.state,r=a.line_ctr.char_pos),!i(o))throw o;o instanceof D&&r===a.line_ctr.char_pos&&a.line_ctr.feed(a.text.slice(r,r+1));try{return o.interactive_parser.resume_parse()}catch(l){if(l instanceof P){if(o instanceof P&&o.token.type===l.token.type&&l.token.type==="$END"&&o.interactive_parser.eq(l.interactive_parser))throw l;o=l}else if(l instanceof D)o=l;else throw l}}}else throw o}}}class _i{constructor(t,n,i){this.parse_table=t,this.start_state=this.parse_table.start_states[i],this.end_state=this.parse_table.end_states[i],this.states=this.parse_table.states,this.callbacks=n,this.start=i}}class De{constructor(t,n,i=null,r=null){this.parse_conf=t,this.lexer=n,this.state_stack=i||[this.parse_conf.start_state],this.value_stack=r||[]}get position(){return v(this.state_stack)}eq(t){return t instanceof De?this.state_stack.length===t.state_stack.length&&this.position===t.position:U}copy(){return R(this)}feed_token(t,n=!1){let i,r,a,o,l,p,c,_,d,m,u=this.state_stack,b=this.value_stack,x=this.parse_conf.states,At=this.parse_conf.end_state,oe=this.parse_conf.callbacks;for(;;){if(d=v(u),t.type in x[d])[r,a]=x[d][t.type];else throw o=new Set(he(x[d]).filter(le=>nt(le)).map(le=>le)),new P({token:t,expected:o,state:this,interactive_parser:null});if(r===Oe){u.push(a),b.push(t.type in oe?oe[t.type](t):t);return}else if(p=a,_=p.expansion.length,_?(c=b.slice(-_),u.splice(-_),b.splice(-_)):c=[],m=oe.get(p)(c),[i,l]=x[v(u)][p.origin.name],u.push(l),b.push(m),n&&v(u)===At)return v(b)}}}class ct{constructor(t,n,i=!1){this.parse_table=t,this.callbacks=n,this.debug=i}parse({lexer:t,start:n,value_stack:i=null,state_stack:r=null,start_interactive:a=!1}={}){let o=new _i(this.parse_table,this.callbacks,n),l=new De(o,t,r,i);return a?new L(this,l,l.lexer):this.parse_from_state(l)}parse_from_state(t){let n,i;try{i=null;for(i of t.lexer.lex(t))t.feed_token(i);return n=i?f.new_borrow_pos("$END","",i):new f("$END","",0,1,1),t.feed_token(n,!0)}catch(r){if(r instanceof A){try{r.interactive_parser=new L(this,t,t.lexer)}catch(a){if(!(a instanceof ReferenceError))throw a}throw r}else if(r instanceof Error){if(this.debug){console.log(""),console.log("STATE STACK DUMP"),console.log("----------------");for(const[a,o]of F(t.state_stack))console.log(h("%d)",a),o);console.log("")}throw r}else throw r}}}let L=class Ot{constructor(t,n,i){this.parser=t,this.parser_state=n,this.lexer_thread=i,this.result=null}feed_token(t){return this.parser_state.feed_token(t,t.type==="$END")}*iter_parse(){for(const t of this.lexer_thread.lex(this.parser_state))yield t,this.result=this.feed_token(t)}exhaust_lexer(){return[...this.iter_parse()]}feed_eof(t=null){let n=t!==null?f.new_borrow_pos("$END","",t):new f("$END","",0,1,1);return this.feed_token(n)}copy(){return R(this)}eq(t){return t instanceof Ot?this.parser_state===t.parser_state&&this.lexer_thread===t.lexer_thread:!1}as_immutable(){let t=R(this);return new pt(t.parser,t.parser_state,t.lexer_thread)}pretty(){let t=["Parser choices:"];for(const[n,i]of g(this.choices()))t.push(h(" - %s -> %r",n,i));return t.push(h("stack size: %s",this.parser_state.state_stack.length)),t.join(`
|
|
20
|
-
`)}choices(){return this.parser_state.parse_conf.parse_table.states[this.parser_state.position]}accepts(){let t,n=new Set;for(const i of this.choices())if(nt(i)){t=R(this);let r=null;try{t.feed_token(new f(i,""))}catch(a){if(r=a,!(a instanceof P))throw a}r||n.add(i)}return n}resume_parse(){return this.parser.parse_from_state(this.parser_state)}};class pt extends L{result=null;feed_token(t){let n=R(this);return n.result=L.feed_token(n,t),n}exhaust_lexer(){let t=this.as_mutable();return t.exhaust_lexer(),t.as_immutable()}as_mutable(){let t=R(this);return new L(t.parser,t.parser_state,t.lexer_thread)}}class ut{constructor(t){this.name=t}repr(){return this.toString()}}var Oe=new ut("Shift"),dt=new ut("Reduce");class ci{constructor(t,n,i){this.states=t,this.start_states=n,this.end_states=i}serialize(t){let n=new Enumerator,i=Object.fromEntries(g(this.states).map(([r,a])=>[r,Object.fromEntries(g(a).map(([o,[l,p]])=>[He(n,o),l===dt?[1,p.serialize(t)]:[0,p]]))]));return{tokens:n.reversed(),states:i,start_states:this.start_states,end_states:this.end_states}}static deserialize(t,n){const i=this;let r=t.tokens,a=Object.fromEntries(g(t.states).map(([o,l])=>[o,Object.fromEntries(g(l).map(([p,[c,_]])=>[r[p],c===1?[dt,M.deserialize(_,n)]:[Oe,_]]))]));return new i(a,t.start_states,t.end_states)}}class pi extends ci{static from_ParseTable(t){const n=this;let i=[...t.states],r=Object.fromEntries(F(i).map(([p,c])=>[c,p])),a={};for(let[p,c]of g(t.states))c=Object.fromEntries(g(c).map(([_,d])=>[_,d[0]===Oe?[d[0],r[d[1]]]:d])),a[r[p]]=c;let o=Object.fromEntries(g(t.start_states).map(([p,c])=>[p,r[c]])),l=Object.fromEntries(g(t.end_states).map(([p,c])=>[p,r[c]]));return new n(a,o,l)}}function ui(s){if(s&&s.__future_interface__)return s;{class t extends ne{constructor(i){super(),this.lexer=s(i)}lex(i,r){return this.lexer.lex(i.text)}}return t}}function di(s,t,n,i,r){let a=ot.deserialize(s.parser_conf,t),o=_t.deserialize(s.parser,t,i,r.debug);return a.callbacks=i,new hi({lexer_conf:n,parser_conf:a,options:r,parser:o})}var ht={};class hi extends T{static get __serialize_fields__(){return["lexer_conf","parser_conf","parser"]}constructor({lexer_conf:t,parser_conf:n,options:i,parser:r=null}={}){super();let a,o;this.parser_conf=n,this.lexer_conf=t,this.options=i,r?this.parser=r:(o=He(ht,n.parser_type),this.parser=o(t,n,i));let l=t.lexer_type;if(this.skip_lexer=!1,["dynamic","dynamic_complete"].includes(l)){this.skip_lexer=!0;return}const p={basic:gi,contextual:xi};l in p?(a=p[l],this.lexer=a(t,this.parser,t.postlex,i)):this.lexer=ui(l)(t),t.postlex&&(this.lexer=new yi(this.lexer,t.postlex))}_verify_start(t=null){let n;if(t===null){if(n=this.parser_conf.start,n.length>1)throw new k("Lark initialized with more than 1 possible start rule. Must specify which start rule to parse",n);[t]=n}else if(!this.parser_conf.start.includes(t))throw new k(h("Unknown start rule %s. Must be one of %r",t,this.parser_conf.start));return t}_make_lexer_thread(t){return this.skip_lexer?t:rt.from_text(this.lexer,t)}parse(t,n=null,i=null){let r=this._verify_start(n),a=i===null?{}:{on_error:i},o=this._make_lexer_thread(t);return this.parser.parse({lexer:o,start:r,...a})}parse_interactive(t=null,n=null){let i=this._verify_start(n);if(this.parser_conf.parser_type!=="lalr")throw new k("parse_interactive() currently only works with parser='lalr' ");let r=this._make_lexer_thread(t);return this.parser.parse_interactive(r,i)}}function mi(s,t){let n;we(s,["lalr","earley","cyk"]),typeof t!="object"&&(n={lalr:["basic","contextual"],earley:["basic","dynamic","dynamic_complete"],cyk:["basic"]}[s],we(t,n,h("Parser %r does not support lexer %%r, expected one of %%s",s)))}function fi(s,t){let n,i={};for(const r of t)n=s&&s[r.name]||null,n!==null&&(i[r.name]=n);return i}class yi{constructor(t,n){this.lexer=t,this.postlexer=n}lex(t,n){let i=this.lexer.lex(t,n);return this.postlexer.process(i)}}function gi(s,t,n,i){return new ie(s)}function xi(s,t,n,i){let r=Object.fromEntries(g(t._parse_table.states).map(([o,l])=>[o,[...he(l)]])),a=n?n.always_accept:[];return new Wn({conf:s,states:r,always_accept:a})}function wi(s,t,n=null){let i=n?n.debug:!1;return new _t({parser_conf:t,debug:i})}ht.lalr=wi;class mt extends Xe{process(t){return t}always_accept=[]}class vi extends T{OPTIONS_DOC='\n **=== General Options ===**\n\n start\n The start symbol. Either a string, or a list of strings for multiple possible starts (Default: "start")\n debug\n Display debug information and extra warnings. Use only when debugging (Default: ``False``)\n When used with Earley, it generates a forest graph as "sppf.png", if \'dot\' is installed.\n transformer\n Applies the transformer to every parse tree (equivalent to applying it after the parse, but faster)\n propagate_positions\n Propagates (line, column, end_line, end_column) attributes into all tree branches.\n Accepts ``False``, ``True``, or a callable, which will filter which nodes to ignore when propagating.\n maybe_placeholders\n When ``True``, the ``[]`` operator returns ``None`` when not matched.\n When ``False``, ``[]`` behaves like the ``?`` operator, and returns no value at all.\n (default= ``True``)\n cache\n Cache the results of the Lark grammar analysis, for x2 to x3 faster loading. LALR only for now.\n\n - When ``False``, does nothing (default)\n - When ``True``, caches to a temporary file in the local directory\n - When given a string, caches to the path pointed by the string\n regex\n When True, uses the ``regex`` module instead of the stdlib ``re``.\n g_regex_flags\n Flags that are applied to all terminals (both regex and strings)\n keep_all_tokens\n Prevent the tree builder from automagically removing "punctuation" tokens (Default: ``False``)\n tree_class\n Lark will produce trees comprised of instances of this class instead of the default ``lark.Tree``.\n\n **=== Algorithm Options ===**\n\n parser\n Decides which parser engine to use. Accepts "earley" or "lalr". (Default: "earley").\n (there is also a "cyk" option for legacy)\n lexer\n Decides whether or not to use a lexer stage\n\n - "auto" (default): Choose for me based on the parser\n - "basic": Use a basic lexer\n - "contextual": Stronger lexer (only works with parser="lalr")\n - "dynamic": Flexible and powerful (only with parser="earley")\n - "dynamic_complete": Same as dynamic, but tries *every* variation of tokenizing possible.\n ambiguity\n Decides how to handle ambiguity in the parse. Only relevant if parser="earley"\n\n - "resolve": The parser will automatically choose the simplest derivation\n (it chooses consistently: greedy for tokens, non-greedy for rules)\n - "explicit": The parser will return all derivations wrapped in "_ambig" tree nodes (i.e. a forest).\n - "forest": The parser will return the root of the shared packed parse forest.\n\n **=== Misc. / Domain Specific Options ===**\n\n postlex\n Lexer post-processing (Default: ``None``) Only works with the basic and contextual lexers.\n priority\n How priorities should be evaluated - "auto", ``None``, "normal", "invert" (Default: "auto")\n lexer_callbacks\n Dictionary of callbacks for the lexer. May alter tokens during lexing. Use with caution.\n use_bytes\n Accept an input of type ``bytes`` instead of ``str``.\n edit_terminals\n A callback for editing the terminals before parse.\n import_paths\n A List of either paths or loader functions to specify from where grammars are imported\n source_path\n Override the source of from where the grammar was loaded. Useful for relative imports and unconventional grammar loading\n **=== End of Options ===**\n ';_defaults={debug:!1,keep_all_tokens:!1,tree_class:null,cache:!1,postlex:null,parser:"earley",lexer:"auto",transformer:null,start:"start",priority:"auto",ambiguity:"auto",regex:!1,propagate_positions:!1,lexer_callbacks:{},maybe_placeholders:!0,edit_terminals:null,g_regex_flags:"",use_bytes:!1,import_paths:[],source_path:null,_plugins:null};constructor(t){super();let n,i=Ke(t),r=this;for(const[a,o]of g(this._defaults))a in i?(n=bn(i,a),typeof o=="boolean"&&!["cache","use_bytes","propagate_positions"].includes(a)&&(n=et(n))):n=o,r[a]=n;if(typeof r.start=="string"&&(r.start=[r.start]),this.options=r,we(this.parser,["earley","lalr","cyk",null]),this.parser==="earley"&&this.transformer)throw new k("Cannot specify an embedded transformer when using the Earley algorithm. Please use your transformer on the resulting parse tree, or use a different algorithm (i.e. LALR)");if(Object.keys(i).length)throw new k(h("Unknown options: %s",he(i)))}serialize(t){return this.options}static deserialize(t,n){const i=this;return new i(t)}}class ft extends T{static get __serialize_fields__(){return["parser","rules","options"]}_build_lexer(t=!1){let n=this.lexer_conf;return t&&(n=R(n),n.ignore=[]),new ie(n)}_prepare_callbacks(){this._callbacks=new Map,this.options.ambiguity!=="forest"&&(this._parse_tree_builder=new li(this.rules,this.options.tree_class||En(y),this.options.propagate_positions,this.options.parser!=="lalr"&&this.options.ambiguity==="explicit",this.options.maybe_placeholders),this._callbacks=this._parse_tree_builder.create_callback(this.options.transformer)),Je(this._callbacks,fi(this.options.transformer,this.terminals))}_deserialize_lexer_conf(t,n,i){let r=at.deserialize(t.lexer_conf,n);return r.callbacks=i.lexer_callbacks||{},r.re_module=i.regex?regex:Ge,r.use_bytes=i.use_bytes,r.g_regex_flags=i.g_regex_flags||"",r.skip_validation=!0,r.postlex=i.postlex,r}_load({f:t,...n}={}){let i;fe(t)?i=t:i=pickle.load(t);let r=i.memo,a=i.data,o=zn.deserialize(r,{Rule:M,TerminalDef:te},{}),l=Ke(a.options);return Je(l,n),this.options=vi.deserialize(l,o),this.rules=a.rules.map(p=>M.deserialize(p,o)),this.source_path="<deserialized>",mi(this.options.parser,this.options.lexer),this.lexer_conf=this._deserialize_lexer_conf(a.parser,o,this.options),this.terminals=this.lexer_conf.terminals,this._prepare_callbacks(),this._terminals_dict=Object.fromEntries(this.terminals.map(p=>[p.name,p])),this.parser=di(a.parser,o,this.lexer_conf,this._callbacks,this.options),this}static _load_from_dict({data:t,memo:n,...i}={}){return me(this)._load({f:{data:t,memo:n},...i})}repr(){return h("Lark(open(%r), parser=%r, lexer=%r, ...)",this.source_path,this.options.parser,this.options.lexer)}lex(t,n=!1){let i;!("lexer"in this)||n?i=this._build_lexer(n):i=this.lexer;let r=rt.from_text(i,t).lex(null);return this.options.postlex?this.options.postlex.process(r):r}get_terminal(t){return this._terminals_dict[t]}parse_interactive(t=null,n=null){return this.parser.parse_interactive({unknown_param_0:t,start:n})}parse(t,n=null,i=null){return this.parser.parse(t,n,i)}}class yt extends q{}class gt extends mt{constructor(){super(),this.paren_level=0,this.indent_level=[0]}*handle_NL(t){if(this.paren_level>0)return;yield t;let n=ge(t.value,`
|
|
21
|
-
`,1)[1],i=xe(n," ")+xe(n," ")*this.tab_len;if(i>v(this.indent_level))this.indent_level.push(i),yield f.new_borrow_pos(this.INDENT_type,n,t);else{for(;i<v(this.indent_level);)this.indent_level.pop(),yield f.new_borrow_pos(this.DEDENT_type,n,t);if(i!==v(this.indent_level))throw new yt(h("Unexpected dedent to column %s. Expected dedent to %s",i,v(this.indent_level)))}}*_process(t){for(const n of t)n.type===this.NL_type?yield*this.handle_NL(n):yield n,this.OPEN_PAREN_types.includes(n.type)?this.paren_level+=1:this.CLOSE_PAREN_types.includes(n.type)&&(this.paren_level-=1);for(;this.indent_level.length>1;)this.indent_level.pop(),yield new f(this.DEDENT_type,"")}process(t){return this.paren_level=0,this.indent_level=[0],this._process(t)}get always_accept(){return[this.NL_type]}get NL_type(){throw new NotImplementedError}get OPEN_PAREN_types(){throw new NotImplementedError}get CLOSE_PAREN_types(){throw new NotImplementedError}get INDENT_type(){throw new NotImplementedError}get DEDENT_type(){throw new NotImplementedError}get tab_len(){throw new NotImplementedError}}class Ti extends gt{static get NL_type(){return"_NEWLINE"}get NL_type(){return this.constructor.NL_type}static get OPEN_PAREN_types(){return["LPAR","LSQB","LBRACE"]}get OPEN_PAREN_types(){return this.constructor.OPEN_PAREN_types}static get CLOSE_PAREN_types(){return["RPAR","RSQB","RBRACE"]}get CLOSE_PAREN_types(){return this.constructor.CLOSE_PAREN_types}static get INDENT_type(){return"_INDENT"}get INDENT_type(){return this.constructor.INDENT_type}static get DEDENT_type(){return"_DEDENT"}get DEDENT_type(){return this.constructor.DEDENT_type}static get tab_len(){return 8}get tab_len(){return this.constructor.tab_len}}const bi={Terminal:Ee,NonTerminal:Ie,RuleOptions:ee,PatternStr:Ne,PatternRE:qe,TerminalDef:te};var Ei={LarkError:q,ConfigurationError:k,GrammarError:Y,ParseError:An,LexError:B,UnexpectedInput:A,UnexpectedEOF:Sn,UnexpectedCharacters:D,UnexpectedToken:P,VisitError:ve,Meta:it,Tree:y,Discard:X,Transformer:Z,Transformer_InPlace:st,Transformer_NonRecursive:Dn,Transformer_InPlaceRecursive:Pn,VisitorBase:Te,Visitor:Ln,Visitor_Recursive:Cn,Interpreter:Qn,Symbol:be,Terminal:Ee,NonTerminal:Ie,RuleOptions:ee,Rule:M,Pattern:Re,PatternStr:Ne,PatternRE:qe,TerminalDef:te,Token:f,Lexer:ne,LexerConf:at,ParserConf:ot,InteractiveParser:L,ImmutableInteractiveParser:pt,PostLex:mt,Lark:ft,DedentError:yt,Indenter:gt,PythonIndenter:Ti,get_parser:vn},Ii={parser:{lexer_conf:{terminals:[{"@":0},{"@":1},{"@":2},{"@":3},{"@":4},{"@":5},{"@":6},{"@":7},{"@":8},{"@":9},{"@":10},{"@":11},{"@":12},{"@":13},{"@":14},{"@":15},{"@":16},{"@":17},{"@":18},{"@":19}],ignore:["WS"],g_regex_flags:0,use_bytes:!1,lexer_type:"contextual",__type__:"LexerConf"},parser_conf:{rules:[{"@":20},{"@":21},{"@":22},{"@":23},{"@":24},{"@":25},{"@":26},{"@":27},{"@":28},{"@":29},{"@":30},{"@":31},{"@":32},{"@":33},{"@":34},{"@":35},{"@":36},{"@":37},{"@":38},{"@":39},{"@":40},{"@":41},{"@":42},{"@":43},{"@":44},{"@":45},{"@":46},{"@":47},{"@":48}],start:["start"],parser_type:"lalr",__type__:"ParserConf"},parser:{tokens:{0:"STRING",1:"IDENTIFIER",2:"INT",3:"choice_ref",4:"$END",5:"RPAR",6:"LSQB",7:"RSQB",8:"question_id",9:"matrix_statement_id",10:"CONJUNCTION",11:"DOT",12:"top_level_expr",13:"LPAR",14:"OPERATOR",15:"TRUE",16:"__ANON_1",17:"__ANON_0",18:"__ANON_4",19:"question_choice_selected_value_comparison",20:"bool_const",21:"condition",22:"__ANON_5",23:"__ANON_3",24:"question_choice_selected",25:"selected_count_comparison",26:"FALSE",27:"question_choice_text_comparison",28:"NEGATION",29:"start",30:"__ANON_2",31:"bool_expr",32:"question_choice_text_comparison_case_insensitive",33:"choice_selection_count_comparison"},states:{0:{0:[0,25]},1:{1:[0,28],2:[0,23],3:[0,22]},2:{2:[0,21]},3:{2:[0,23],1:[0,28],3:[0,29]},4:{4:[1,{"@":44}],5:[1,{"@":44}]},5:{6:[0,19]},6:{2:[0,37]},7:{2:[0,23],3:[0,75],1:[0,28]},8:{5:[0,43]},9:{2:[0,70]},10:{5:[0,81]},11:{3:[0,50],2:[0,23],1:[0,28]},12:{7:[0,10]},13:{0:[0,34]},14:{2:[0,67]},15:{5:[1,{"@":23}],6:[1,{"@":23}]},16:{8:[0,46],9:[0,39],1:[0,82]},17:{10:[1,{"@":25}],4:[1,{"@":25}],5:[1,{"@":25}]},18:{6:[0,11],11:[0,74]},19:{2:[0,23],3:[0,53],1:[0,28]},20:{10:[0,24],4:[1,{"@":45}]},21:{10:[1,{"@":33}],4:[1,{"@":33}],5:[1,{"@":33}]},22:{7:[0,61]},23:{7:[1,{"@":20}]},24:{12:[0,77],13:[0,38]},25:{10:[1,{"@":31}],4:[1,{"@":31}],5:[1,{"@":31}]},26:{10:[1,{"@":24}],4:[1,{"@":24}],5:[1,{"@":24}]},27:{14:[0,6]},28:{7:[1,{"@":21}]},29:{7:[0,45]},30:{15:[0,33],16:[0,16],17:[0,31],18:[0,78],19:[0,41],20:[0,76],21:[0,52],22:[0,48],23:[0,72],24:[0,64],12:[0,84],25:[0,57],26:[0,36],27:[0,40],13:[0,38],28:[0,59],29:[0,42],30:[0,47],31:[0,68],32:[0,35],33:[0,54]},31:{8:[0,66],1:[0,82],9:[0,65]},32:{7:[0,8]},33:{10:[1,{"@":34}],4:[1,{"@":34}],5:[1,{"@":34}]},34:{10:[1,{"@":30}],4:[1,{"@":30}],5:[1,{"@":30}]},35:{10:[1,{"@":40}],4:[1,{"@":40}],5:[1,{"@":40}]},36:{10:[1,{"@":35}],4:[1,{"@":35}],5:[1,{"@":35}]},37:{10:[1,{"@":32}],4:[1,{"@":32}],5:[1,{"@":32}]},38:{15:[0,33],16:[0,16],17:[0,31],31:[0,62],18:[0,78],19:[0,41],20:[0,76],21:[0,52],22:[0,48],23:[0,72],24:[0,64],25:[0,57],26:[0,36],27:[0,40],28:[0,59],30:[0,47],32:[0,35],33:[0,54]},39:{5:[0,56]},40:{10:[1,{"@":39}],4:[1,{"@":39}],5:[1,{"@":39}]},41:{10:[1,{"@":38}],4:[1,{"@":38}],5:[1,{"@":38}]},42:{},43:{10:[1,{"@":27}],4:[1,{"@":27}],5:[1,{"@":27}]},44:{5:[0,17]},45:{5:[0,79]},46:{11:[0,74],5:[0,51]},47:{8:[0,71],1:[0,82]},48:{1:[0,82],8:[0,60]},49:{5:[0,26]},50:{7:[0,49]},51:{14:[0,14]},52:{10:[0,69],4:[1,{"@":43}],5:[1,{"@":43}]},53:{7:[0,44]},54:{10:[1,{"@":42}],4:[1,{"@":42}],5:[1,{"@":42}]},55:{2:[0,23],1:[0,28],3:[0,12]},56:{14:[0,9]},57:{10:[1,{"@":41}],4:[1,{"@":41}],5:[1,{"@":41}]},58:{6:[0,1]},59:{17:[0,85]},60:{6:[0,3]},61:{5:[0,73]},62:{5:[0,20]},63:{5:[0,80]},64:{10:[1,{"@":37}],4:[1,{"@":37}],5:[1,{"@":37}]},65:{6:[0,83]},66:{11:[0,74],6:[0,55]},67:{10:[1,{"@":28}],4:[1,{"@":28}],5:[1,{"@":28}]},68:{4:[1,{"@":48}]},69:{15:[0,33],16:[0,16],17:[0,31],18:[0,78],19:[0,41],20:[0,76],21:[0,52],22:[0,48],23:[0,72],24:[0,64],25:[0,57],26:[0,36],27:[0,40],28:[0,59],30:[0,47],32:[0,35],31:[0,4],33:[0,54]},70:{10:[1,{"@":29}],4:[1,{"@":29}],5:[1,{"@":29}]},71:{6:[0,7]},72:{8:[0,58],1:[0,82]},73:{14:[0,0]},74:{1:[0,15]},75:{7:[0,63]},76:{10:[1,{"@":36}],4:[1,{"@":36}],5:[1,{"@":36}]},77:{4:[1,{"@":46}]},78:{1:[0,82],8:[0,86]},79:{14:[0,2]},80:{14:[0,13]},81:{10:[1,{"@":26}],4:[1,{"@":26}],5:[1,{"@":26}]},82:{5:[1,{"@":22}],11:[1,{"@":22}],6:[1,{"@":22}]},83:{3:[0,32],2:[0,23],1:[0,28]},84:{4:[1,{"@":47}]},85:{8:[0,18],9:[0,5],1:[0,82]},86:{5:[0,27]}},start_states:{start:30},end_states:{start:42}},__type__:"ParsingFrontend"},rules:[{"@":20},{"@":21},{"@":22},{"@":23},{"@":24},{"@":25},{"@":26},{"@":27},{"@":28},{"@":29},{"@":30},{"@":31},{"@":32},{"@":33},{"@":34},{"@":35},{"@":36},{"@":37},{"@":38},{"@":39},{"@":40},{"@":41},{"@":42},{"@":43},{"@":44},{"@":45},{"@":46},{"@":47},{"@":48}],options:{debug:!1,keep_all_tokens:!1,tree_class:null,cache:!1,postlex:null,parser:"lalr",lexer:"contextual",transformer:null,start:["start"],priority:"normal",ambiguity:"auto",regex:!1,propagate_positions:!1,lexer_callbacks:{},maybe_placeholders:!1,edit_terminals:null,g_regex_flags:0,use_bytes:!1,import_paths:[],source_path:null,_plugins:{}},__type__:"Lark"},Ri={0:{name:"WS",pattern:{value:`(?:[ \f\r
|
|
22
|
-
])+`,flags:[],raw:null,_width:[1,4294967295],__type__:"PatternRE"},priority:0,__type__:"TerminalDef"},1:{name:"IDENTIFIER",pattern:{value:"[a-zA-Z][a-zA-Z0-9_]*[a-zA-Z0-9]",flags:[],raw:"/[a-zA-Z][a-zA-Z0-9_]*[a-zA-Z0-9]/",_width:[2,4294967295],__type__:"PatternRE"},priority:0,__type__:"TerminalDef"},2:{name:"INT",pattern:{value:"-?[0-9]+",flags:[],raw:"/-?[0-9]+/",_width:[1,4294967295],__type__:"PatternRE"},priority:0,__type__:"TerminalDef"},3:{name:"STRING",pattern:{value:`(?:'[^\\']*'|"[^"]*")`,flags:[],raw:null,_width:[2,4294967295],__type__:"PatternRE"},priority:0,__type__:"TerminalDef"},4:{name:"OPERATOR",pattern:{value:"(?:regex_matches|not_contains|contains|==|!=|<=|>=|<|>)",flags:[],raw:null,_width:[1,13],__type__:"PatternRE"},priority:0,__type__:"TerminalDef"},5:{name:"CONJUNCTION",pattern:{value:"(?:and|or)",flags:[],raw:null,_width:[2,3],__type__:"PatternRE"},priority:0,__type__:"TerminalDef"},6:{name:"NEGATION",pattern:{value:"!",flags:[],raw:'"!"',__type__:"PatternStr"},priority:0,__type__:"TerminalDef"},7:{name:"TRUE",pattern:{value:"true",flags:[],raw:'"true"',__type__:"PatternStr"},priority:0,__type__:"TerminalDef"},8:{name:"FALSE",pattern:{value:"false",flags:[],raw:'"false"',__type__:"PatternStr"},priority:0,__type__:"TerminalDef"},9:{name:"DOT",pattern:{value:".",flags:[],raw:'"."',__type__:"PatternStr"},priority:0,__type__:"TerminalDef"},10:{name:"__ANON_0",pattern:{value:"selected(",flags:[],raw:'"selected("',__type__:"PatternStr"},priority:0,__type__:"TerminalDef"},11:{name:"LSQB",pattern:{value:"[",flags:[],raw:'"["',__type__:"PatternStr"},priority:0,__type__:"TerminalDef"},12:{name:"RSQB",pattern:{value:"]",flags:[],raw:'"]"',__type__:"PatternStr"},priority:0,__type__:"TerminalDef"},13:{name:"RPAR",pattern:{value:")",flags:[],raw:'")"',__type__:"PatternStr"},priority:0,__type__:"TerminalDef"},14:{name:"__ANON_1",pattern:{value:"selected_value(",flags:[],raw:'"selected_value("',__type__:"PatternStr"},priority:0,__type__:"TerminalDef"},15:{name:"__ANON_2",pattern:{value:"text(",flags:[],raw:'"text("',__type__:"PatternStr"},priority:0,__type__:"TerminalDef"},16:{name:"__ANON_3",pattern:{value:"text_ignore_case(",flags:[],raw:'"text_ignore_case("',__type__:"PatternStr"},priority:0,__type__:"TerminalDef"},17:{name:"__ANON_4",pattern:{value:"count_selected(",flags:[],raw:'"count_selected("',__type__:"PatternStr"},priority:0,__type__:"TerminalDef"},18:{name:"__ANON_5",pattern:{value:"count_choice_selections(",flags:[],raw:'"count_choice_selections("',__type__:"PatternStr"},priority:0,__type__:"TerminalDef"},19:{name:"LPAR",pattern:{value:"(",flags:[],raw:'"("',__type__:"PatternStr"},priority:0,__type__:"TerminalDef"},20:{origin:{name:"choice_ref",__type__:"NonTerminal"},expansion:[{name:"INT",filter_out:!1,__type__:"Terminal"}],order:0,alias:null,options:{keep_all_tokens:!1,expand1:!1,priority:null,template_source:null,empty_indices:[],__type__:"RuleOptions"},__type__:"Rule"},21:{origin:{name:"choice_ref",__type__:"NonTerminal"},expansion:[{name:"IDENTIFIER",filter_out:!1,__type__:"Terminal"}],order:1,alias:null,options:{keep_all_tokens:!1,expand1:!1,priority:null,template_source:null,empty_indices:[],__type__:"RuleOptions"},__type__:"Rule"},22:{origin:{name:"question_id",__type__:"NonTerminal"},expansion:[{name:"IDENTIFIER",filter_out:!1,__type__:"Terminal"}],order:0,alias:null,options:{keep_all_tokens:!1,expand1:!1,priority:null,template_source:null,empty_indices:[],__type__:"RuleOptions"},__type__:"Rule"},23:{origin:{name:"matrix_statement_id",__type__:"NonTerminal"},expansion:[{name:"question_id",__type__:"NonTerminal"},{name:"DOT",filter_out:!0,__type__:"Terminal"},{name:"IDENTIFIER",filter_out:!1,__type__:"Terminal"}],order:0,alias:null,options:{keep_all_tokens:!1,expand1:!1,priority:null,template_source:null,empty_indices:[],__type__:"RuleOptions"},__type__:"Rule"},24:{origin:{name:"question_choice_selected",__type__:"NonTerminal"},expansion:[{name:"NEGATION",filter_out:!1,__type__:"Terminal"},{name:"__ANON_0",filter_out:!0,__type__:"Terminal"},{name:"question_id",__type__:"NonTerminal"},{name:"LSQB",filter_out:!0,__type__:"Terminal"},{name:"choice_ref",__type__:"NonTerminal"},{name:"RSQB",filter_out:!0,__type__:"Terminal"},{name:"RPAR",filter_out:!0,__type__:"Terminal"}],order:0,alias:null,options:{keep_all_tokens:!1,expand1:!1,priority:null,template_source:null,empty_indices:[],__type__:"RuleOptions"},__type__:"Rule"},25:{origin:{name:"question_choice_selected",__type__:"NonTerminal"},expansion:[{name:"NEGATION",filter_out:!1,__type__:"Terminal"},{name:"__ANON_0",filter_out:!0,__type__:"Terminal"},{name:"matrix_statement_id",__type__:"NonTerminal"},{name:"LSQB",filter_out:!0,__type__:"Terminal"},{name:"choice_ref",__type__:"NonTerminal"},{name:"RSQB",filter_out:!0,__type__:"Terminal"},{name:"RPAR",filter_out:!0,__type__:"Terminal"}],order:1,alias:null,options:{keep_all_tokens:!1,expand1:!1,priority:null,template_source:null,empty_indices:[],__type__:"RuleOptions"},__type__:"Rule"},26:{origin:{name:"question_choice_selected",__type__:"NonTerminal"},expansion:[{name:"__ANON_0",filter_out:!0,__type__:"Terminal"},{name:"question_id",__type__:"NonTerminal"},{name:"LSQB",filter_out:!0,__type__:"Terminal"},{name:"choice_ref",__type__:"NonTerminal"},{name:"RSQB",filter_out:!0,__type__:"Terminal"},{name:"RPAR",filter_out:!0,__type__:"Terminal"}],order:2,alias:null,options:{keep_all_tokens:!1,expand1:!1,priority:null,template_source:null,empty_indices:[],__type__:"RuleOptions"},__type__:"Rule"},27:{origin:{name:"question_choice_selected",__type__:"NonTerminal"},expansion:[{name:"__ANON_0",filter_out:!0,__type__:"Terminal"},{name:"matrix_statement_id",__type__:"NonTerminal"},{name:"LSQB",filter_out:!0,__type__:"Terminal"},{name:"choice_ref",__type__:"NonTerminal"},{name:"RSQB",filter_out:!0,__type__:"Terminal"},{name:"RPAR",filter_out:!0,__type__:"Terminal"}],order:3,alias:null,options:{keep_all_tokens:!1,expand1:!1,priority:null,template_source:null,empty_indices:[],__type__:"RuleOptions"},__type__:"Rule"},28:{origin:{name:"question_choice_selected_value_comparison",__type__:"NonTerminal"},expansion:[{name:"__ANON_1",filter_out:!0,__type__:"Terminal"},{name:"question_id",__type__:"NonTerminal"},{name:"RPAR",filter_out:!0,__type__:"Terminal"},{name:"OPERATOR",filter_out:!1,__type__:"Terminal"},{name:"INT",filter_out:!1,__type__:"Terminal"}],order:0,alias:null,options:{keep_all_tokens:!1,expand1:!1,priority:null,template_source:null,empty_indices:[],__type__:"RuleOptions"},__type__:"Rule"},29:{origin:{name:"question_choice_selected_value_comparison",__type__:"NonTerminal"},expansion:[{name:"__ANON_1",filter_out:!0,__type__:"Terminal"},{name:"matrix_statement_id",__type__:"NonTerminal"},{name:"RPAR",filter_out:!0,__type__:"Terminal"},{name:"OPERATOR",filter_out:!1,__type__:"Terminal"},{name:"INT",filter_out:!1,__type__:"Terminal"}],order:1,alias:null,options:{keep_all_tokens:!1,expand1:!1,priority:null,template_source:null,empty_indices:[],__type__:"RuleOptions"},__type__:"Rule"},30:{origin:{name:"question_choice_text_comparison",__type__:"NonTerminal"},expansion:[{name:"__ANON_2",filter_out:!0,__type__:"Terminal"},{name:"question_id",__type__:"NonTerminal"},{name:"LSQB",filter_out:!0,__type__:"Terminal"},{name:"choice_ref",__type__:"NonTerminal"},{name:"RSQB",filter_out:!0,__type__:"Terminal"},{name:"RPAR",filter_out:!0,__type__:"Terminal"},{name:"OPERATOR",filter_out:!1,__type__:"Terminal"},{name:"STRING",filter_out:!1,__type__:"Terminal"}],order:0,alias:null,options:{keep_all_tokens:!1,expand1:!1,priority:null,template_source:null,empty_indices:[],__type__:"RuleOptions"},__type__:"Rule"},31:{origin:{name:"question_choice_text_comparison_case_insensitive",__type__:"NonTerminal"},expansion:[{name:"__ANON_3",filter_out:!0,__type__:"Terminal"},{name:"question_id",__type__:"NonTerminal"},{name:"LSQB",filter_out:!0,__type__:"Terminal"},{name:"choice_ref",__type__:"NonTerminal"},{name:"RSQB",filter_out:!0,__type__:"Terminal"},{name:"RPAR",filter_out:!0,__type__:"Terminal"},{name:"OPERATOR",filter_out:!1,__type__:"Terminal"},{name:"STRING",filter_out:!1,__type__:"Terminal"}],order:0,alias:null,options:{keep_all_tokens:!1,expand1:!1,priority:null,template_source:null,empty_indices:[],__type__:"RuleOptions"},__type__:"Rule"},32:{origin:{name:"selected_count_comparison",__type__:"NonTerminal"},expansion:[{name:"__ANON_4",filter_out:!0,__type__:"Terminal"},{name:"question_id",__type__:"NonTerminal"},{name:"RPAR",filter_out:!0,__type__:"Terminal"},{name:"OPERATOR",filter_out:!1,__type__:"Terminal"},{name:"INT",filter_out:!1,__type__:"Terminal"}],order:0,alias:null,options:{keep_all_tokens:!1,expand1:!1,priority:null,template_source:null,empty_indices:[],__type__:"RuleOptions"},__type__:"Rule"},33:{origin:{name:"choice_selection_count_comparison",__type__:"NonTerminal"},expansion:[{name:"__ANON_5",filter_out:!0,__type__:"Terminal"},{name:"question_id",__type__:"NonTerminal"},{name:"LSQB",filter_out:!0,__type__:"Terminal"},{name:"choice_ref",__type__:"NonTerminal"},{name:"RSQB",filter_out:!0,__type__:"Terminal"},{name:"RPAR",filter_out:!0,__type__:"Terminal"},{name:"OPERATOR",filter_out:!1,__type__:"Terminal"},{name:"INT",filter_out:!1,__type__:"Terminal"}],order:0,alias:null,options:{keep_all_tokens:!1,expand1:!1,priority:null,template_source:null,empty_indices:[],__type__:"RuleOptions"},__type__:"Rule"},34:{origin:{name:"bool_const",__type__:"NonTerminal"},expansion:[{name:"TRUE",filter_out:!1,__type__:"Terminal"}],order:0,alias:null,options:{keep_all_tokens:!1,expand1:!1,priority:null,template_source:null,empty_indices:[],__type__:"RuleOptions"},__type__:"Rule"},35:{origin:{name:"bool_const",__type__:"NonTerminal"},expansion:[{name:"FALSE",filter_out:!1,__type__:"Terminal"}],order:1,alias:null,options:{keep_all_tokens:!1,expand1:!1,priority:null,template_source:null,empty_indices:[],__type__:"RuleOptions"},__type__:"Rule"},36:{origin:{name:"condition",__type__:"NonTerminal"},expansion:[{name:"bool_const",__type__:"NonTerminal"}],order:0,alias:null,options:{keep_all_tokens:!1,expand1:!1,priority:null,template_source:null,empty_indices:[],__type__:"RuleOptions"},__type__:"Rule"},37:{origin:{name:"condition",__type__:"NonTerminal"},expansion:[{name:"question_choice_selected",__type__:"NonTerminal"}],order:1,alias:null,options:{keep_all_tokens:!1,expand1:!1,priority:null,template_source:null,empty_indices:[],__type__:"RuleOptions"},__type__:"Rule"},38:{origin:{name:"condition",__type__:"NonTerminal"},expansion:[{name:"question_choice_selected_value_comparison",__type__:"NonTerminal"}],order:2,alias:null,options:{keep_all_tokens:!1,expand1:!1,priority:null,template_source:null,empty_indices:[],__type__:"RuleOptions"},__type__:"Rule"},39:{origin:{name:"condition",__type__:"NonTerminal"},expansion:[{name:"question_choice_text_comparison",__type__:"NonTerminal"}],order:3,alias:null,options:{keep_all_tokens:!1,expand1:!1,priority:null,template_source:null,empty_indices:[],__type__:"RuleOptions"},__type__:"Rule"},40:{origin:{name:"condition",__type__:"NonTerminal"},expansion:[{name:"question_choice_text_comparison_case_insensitive",__type__:"NonTerminal"}],order:4,alias:null,options:{keep_all_tokens:!1,expand1:!1,priority:null,template_source:null,empty_indices:[],__type__:"RuleOptions"},__type__:"Rule"},41:{origin:{name:"condition",__type__:"NonTerminal"},expansion:[{name:"selected_count_comparison",__type__:"NonTerminal"}],order:5,alias:null,options:{keep_all_tokens:!1,expand1:!1,priority:null,template_source:null,empty_indices:[],__type__:"RuleOptions"},__type__:"Rule"},42:{origin:{name:"condition",__type__:"NonTerminal"},expansion:[{name:"choice_selection_count_comparison",__type__:"NonTerminal"}],order:6,alias:null,options:{keep_all_tokens:!1,expand1:!1,priority:null,template_source:null,empty_indices:[],__type__:"RuleOptions"},__type__:"Rule"},43:{origin:{name:"bool_expr",__type__:"NonTerminal"},expansion:[{name:"condition",__type__:"NonTerminal"}],order:0,alias:null,options:{keep_all_tokens:!1,expand1:!1,priority:null,template_source:null,empty_indices:[],__type__:"RuleOptions"},__type__:"Rule"},44:{origin:{name:"bool_expr",__type__:"NonTerminal"},expansion:[{name:"condition",__type__:"NonTerminal"},{name:"CONJUNCTION",filter_out:!1,__type__:"Terminal"},{name:"bool_expr",__type__:"NonTerminal"}],order:1,alias:null,options:{keep_all_tokens:!1,expand1:!1,priority:null,template_source:null,empty_indices:[],__type__:"RuleOptions"},__type__:"Rule"},45:{origin:{name:"top_level_expr",__type__:"NonTerminal"},expansion:[{name:"LPAR",filter_out:!0,__type__:"Terminal"},{name:"bool_expr",__type__:"NonTerminal"},{name:"RPAR",filter_out:!0,__type__:"Terminal"}],order:0,alias:null,options:{keep_all_tokens:!1,expand1:!1,priority:null,template_source:null,empty_indices:[],__type__:"RuleOptions"},__type__:"Rule"},46:{origin:{name:"top_level_expr",__type__:"NonTerminal"},expansion:[{name:"LPAR",filter_out:!0,__type__:"Terminal"},{name:"bool_expr",__type__:"NonTerminal"},{name:"RPAR",filter_out:!0,__type__:"Terminal"},{name:"CONJUNCTION",filter_out:!1,__type__:"Terminal"},{name:"top_level_expr",__type__:"NonTerminal"}],order:1,alias:null,options:{keep_all_tokens:!1,expand1:!1,priority:null,template_source:null,empty_indices:[],__type__:"RuleOptions"},__type__:"Rule"},47:{origin:{name:"start",__type__:"NonTerminal"},expansion:[{name:"top_level_expr",__type__:"NonTerminal"}],order:0,alias:null,options:{keep_all_tokens:!1,expand1:!1,priority:null,template_source:null,empty_indices:[],__type__:"RuleOptions"},__type__:"Rule"},48:{origin:{name:"start",__type__:"NonTerminal"},expansion:[{name:"bool_expr",__type__:"NonTerminal"}],order:1,alias:null,options:{keep_all_tokens:!1,expand1:!1,priority:null,template_source:null,empty_indices:[],__type__:"RuleOptions"},__type__:"Rule"}};const Ae=/\$\{q\:(?<locator>[\-a-zA-Z0-9_\/\(\)]+)\}/g,xt=s=>s.choiceId??s.choiceValue??s.text;class se{questions=new Map;responsesByQuestion=new Map;responsesByQuestionStatement=new Map;surveyResponseId;forExport;evaluationCache=new Map;constructor(t,n=[],i="",r=!1){this.questions=new Map((t?de(t):[]).filter(a=>a.id).map(a=>[pe(a.id),a])),n.filter(a=>a.singleAnswer||a.multipleAnswers).forEach(a=>{const o=pe(a.questionId);this.responsesByQuestion.set(o,[...this.responsesByQuestion.get(o)||[],a]),a.statementId&&this.responsesByQuestionStatement.set(`${o}.${a.statementId}`,a)}),this.surveyResponseId=i,this.forExport=r}getQuestionAnswers(t,n){let i;if(n){const r=this.responsesByQuestionStatement.get(`${t}.${n}`);i=r===void 0?[]:[r]}else i=this.responsesByQuestion.get(t)||[];return i.flatMap(r=>{const{multipleAnswers:a,singleAnswer:o}=r;return a||[o]})}#e(t,n,i){return this.getQuestionAnswers(t,n).filter(r=>typeof i>"u"||i===null||xt(r)===i)}#t(t,n){if(t.textInput&&["forced","optional"].includes(t.textInput)){const i=this.textEntry({questionId:n.questionId,choice:t.id||t.value});return i.trim()?{...t,display:i}:t.textInput==="forced"?null:t}return t}evaluateDisplayLogic(t){if(t&&!this.forExport)try{const n=this.evaluationCache.get(t);if(n!==void 0)return n;const i=Se(t,this);return this.evaluationCache.set(t,i),i}catch(n){return console.error(n),!1}return!0}evaluateDynamicExpression(t,n){const i=this.questions.get(t.questionId);if(!i)return[];const r=this.getQuestionChoicesFlattened(i),a=r.filter(_=>this.isSelected({questionId:t.questionId,choice:_.id||_.value})),o=this.getQuestionStatementsFlattened(i),l=_=>n==="choices"?_:{..._,id:_.id||_.value||_.display},p=_=>({id:_.id,display:_.display,value:_.value});let c=[];switch(t.expression){case w.ALL:c=r.map(l);break;case w.ALL_ENTERED_TEXT:c=r.map(_=>this.#t(_,t)).filter(_=>!!_).map(_=>l(_));break;case w.SELECTED:c=a;break;case w.SELECTED_ENTERED_TEXT:c=a.map(_=>this.#t(_,t)).filter(_=>!!_).map(_=>l(_));break;case w.NOT_SELECTED:c=r.filter(_=>!this.isSelected({questionId:t.questionId,choice:_.id||_.value})).map(l);break;case w.FOR_MATRIX_CHOICE:c=o.filter(_=>this.isSelected({questionId:t.questionId,statementId:_.id,choice:t.identifier}));break;case w.UNSELECTED_FOR_MATRIX_CHOICE:c=o.filter(_=>!this.isSelected({questionId:t.questionId,statementId:_.id,choice:t.identifier}));break;default:c=[]}return this.forExport&&(c=t.expression===w.FOR_MATRIX_CHOICE||t.expression===w.UNSELECTED_FOR_MATRIX_CHOICE?o:r.map(l)),c.map(p)}isSelected(t){return!!this.#e(t.questionId,t.statementId,t.choice).length}countSelected(t){return this.getQuestionAnswers(t).length}selectedValue(t){const n=this.getQuestionAnswers(typeof t=="string"?t:t.questionId,typeof t=="string"?void 0:t.statementId);return n.length?xt(n[0]):null}countChoiceSelections(t,n){return this.#e(t,null,n).length}textEntry(t){return this.#e(t.questionId,t.statementId,t.choice).map(n=>n.text).filter(n=>n).join(", ")}getQuestionText(t){if(this.forExport)return t.text;let n=t.text;return n=n.replaceAll(Ae,(i,r)=>{if(r&&je(r)){const a=S(r);return this.evaluateDynamicExpression(a,"choices").map(o=>o.display).join(", ")}return i}),n}getQuestionChoices(t){const n=(t.choices??[]).filter(i=>this.evaluateDisplayLogic(i.displayLogic));if(t.dynamicChoices){const i=S(t.dynamicChoices),r=this.evaluateDynamicExpression(i,"choices");n.push(...r)}return t.type===I.MatrixSingle||t.type===I.MatrixMulti?n:this.applyRandomization(n,t.id,i=>`${i.id??i.value}`,t.randomization)}getQuestionChoiceGroups(t){const n=(t.choiceGroups?.filter(i=>this.evaluateDisplayLogic(i.displayLogic))||[]).map(i=>({...i,choices:this.applyRandomization(i.choices.filter(r=>this.evaluateDisplayLogic(r.displayLogic)),t.id,r=>`${r.id??r.value}`,i.randomization)})).filter(i=>!!i.choices.length);return this.applyRandomization(n,t.id,i=>i.id,t.randomization)}getQuestionStatements(t){const n=(t.statements??[]).filter(i=>this.evaluateDisplayLogic(i.displayLogic));if(t.dynamicStatements){const i=S(t.dynamicStatements),r=this.evaluateDynamicExpression(i,"statements");n.push(...r)}return this.applyRandomization(n,t.id,i=>i.id,t.randomization)}getQuestionStatementGroups(t){const n=(t.statementGroups?.filter(i=>this.evaluateDisplayLogic(i.displayLogic))||[]).map(i=>({...i,statements:this.applyRandomization(i.statements.filter(r=>this.evaluateDisplayLogic(r.displayLogic)),t.id,r=>r.id,i.randomization)})).filter(i=>!!i.statements.length);return this.applyRandomization(n,t.id,i=>i.id,t.randomization)}getQuestionChoicesFlattened(t){return[...this.getQuestionChoices(t),...this.getQuestionChoiceGroups(t).flatMap(n=>n.choices)]}getQuestionStatementsFlattened(t){return[...this.getQuestionStatements(t),...this.getQuestionStatementGroups(t).flatMap(n=>n.statements)]}applyRandomization(t,n,i,r){if(!r||this.forExport)return t;const a=new Map(t.map(u=>[i(u),u])),o=[...a.keys()],l=new Set(o),p=(r.order??["$"]).filter(u=>u==="$"||l.has(u)),c=o.filter(u=>!p.includes(u)).map(u=>({weight:this.keyHash(n,u),key:u}));c.sort((u,b)=>u.weight.localeCompare(b.weight));const _=r.total??o.length,d=Math.min(_-(p.length-1),c.length),m=[];return p.forEach(u=>{u==="$"?m.push(...c.slice(0,d).map(b=>b.key)):m.push(u)}),m.map(u=>a.get(u))}keyHash(t,n){const i=`${t}.${this.surveyResponseId}.${n}`;return Bt.createHash("sha256").update(i).digest("hex")}}function wt(s){if(s.length===1)return s[0];const t=s[1].value;return t==="or"?s[0]||s[2]:t==="and"?s[0]&&s[2]:!1}function re(s,t,n){switch(t){case"==":return s===n;case"!=":return s!==n;case"<=":return s<=n;case">=":return s>=n;case"<":return s<n;case">":return s>n;default:return!1}}function vt(s,t,n,i){const r=i?s.toLowerCase():s,a=i?n.toLowerCase():n;switch(t){case"contains":return r.includes(a);case"not_contains":return!r.includes(a);case"regex_matches":try{return new RegExp(n).test(r)}catch{return!1}default:return re(r,t,a)}}function Ni(s,t){return s.length>0&&s[0].hasOwnProperty("type")&&s[0].type==="NEGATION"?!t(s.slice(1)):t(s)}function qi(s){if(!["INT","IDENTIFIER"].includes(s.type))throw new SyntaxError(`Invalid token type: ${s.type}; expected IDENTIFIER or INT`);return E(s)}function E(s){switch(s.type){case"IDENTIFIER":return s.value;case"INT":return parseInt(s.value,10);case"STRING":{const t=s.value.match(/(?:'(?<single>[^\']*)')|(?:"(?<double>[^\"]*)")/),n=t?.groups?.double||t?.groups?.single;return Ft.default(n),n}case"OPERATOR":return s.value;case"TRUE":return!0;case"FALSE":return!1;default:throw new SyntaxError(`Invalid token type: ${s.type}`)}}function Se(s,t){const n={bool_const:i=>i[0].value==="true",condition:i=>i[0],bool_expr:wt,top_level_expr:wt,start:i=>i[0],question_id:i=>i[0].value,choice_ref:i=>qi(i[0]),matrix_statement_id:i=>({questionId:i[0],statementId:i[1].value}),question_choice_selected:i=>Ni(i,r=>t.isSelected({questionId:typeof r[0]=="string"?r[0]:r[0].questionId,statementId:typeof r[0]=="string"?void 0:r[0].statementId,choice:r[1]})),question_choice_selected_value_comparison:i=>{const r=t.selectedValue(i[0]);return r!==null&&re(r,E(i[1]),E(i[2]))},question_choice_text_comparison:i=>vt(t.textEntry({questionId:i[0],choice:i[1]}),E(i[2]),E(i[3]),!1),question_choice_text_comparison_case_insensitive:i=>vt(t.textEntry({questionId:i[0],choice:i[1]}),E(i[2]),E(i[3]),!0),selected_count_comparison:i=>re(t.countSelected(i[0]),E(i[1]),E(i[2])),choice_selection_count_comparison:i=>re(t.countChoiceSelections(i[0],i[1]),E(i[2]),E(i[3]))};return Ei.get_parser({transformer:n}).parse(s)}const Tt=new jt.default({allowUnionTypes:!0});Ut.default(Tt);const bt=Tt.compile(Ce);let G=class extends Error{};class O extends Error{}class ae extends Error{}class z extends Error{}class ki extends Error{}class Oi{seenQuestions=new Set;seenMultiQuestions=new Set;seenQuestionStatements=new Map;seenQuestionChoices=new Map;seenTextChoices=new Map;evaluator={};constructor(){this.evaluator.isSelected=t=>(this.validateReference(t),!1),this.evaluator.countSelected=t=>(this.validateReference({questionId:t}),0),this.evaluator.selectedValue=t=>(this.validateReference({questionId:typeof t=="string"?t:t.questionId,statementId:typeof t=="string"?void 0:t.statementId,expectMulti:!1}),0),this.evaluator.countChoiceSelections=(t,n)=>(this.validateReference({questionId:t,choice:n}),0),this.evaluator.textEntry=t=>(this.validateReference({...t,expectText:!0}),"")}validateReference=t=>{if(!this.seenQuestions.has(t.questionId))throw new G(`Invalid question: ${t.questionId}`);if(t.statementId!==void 0&&!this.seenQuestionStatements.get(t.questionId)?.has(t.statementId))throw new G(`Invalid statement: ${t.questionId}.${t.statementId}`);if(t.choice!==void 0&&!this.seenQuestionChoices.get(t.questionId)?.has(t.choice))throw new G(`Invalid choice: ${t.questionId}[${t.choice}]`);if(t.choice!==void 0&&t.expectText===!0&&!this.seenTextChoices.get(t.questionId)?.has(t.choice))throw new G(`Invalid text reference: ${t.questionId}[${t.choice}]`);if(typeof t.expectMulti=="boolean"&&t.expectMulti&&!this.seenMultiQuestions.has(t.questionId))throw new O(`Invalid question reference: ${t.questionId}. Expected a multi-answer question.`);if(typeof t.expectMulti=="boolean"&&!t.expectMulti&&this.seenMultiQuestions.has(t.questionId))throw new O(`Invalid question reference: ${t.questionId}. Expected a non-multi-answer question.`)}}const C=(s,t,n)=>{if(n)try{Se(n,s.evaluator)}catch(i){throw i instanceof G||i instanceof O||i instanceof z?i:new Error(`Syntax error parsing display logic at ${t}: ${n}`)}},Ai=(s,t)=>{[...t.matchAll(Ae)].forEach(n=>{const i=S(n.groups.locator);if(!s.seenQuestions.has(i.questionId))throw new O(`Invalid question referenced in locator expression: ${i.questionId}/${i.expression}`);if(i.identifier&&!s.seenQuestionChoices.get(i.questionId)?.has(i.identifier))throw new O(`Invalid question choice referenced in locator expression: ${i.questionId}/${i.expression}(${i.identifier})`)})},Q=(s,t,n)=>{if(n){const i=new Set(t);if(n.order){const r=n.order.split(" "),a=r.filter(o=>o==="$").length;if(a===0)throw new ae(`Wildcard $ is missing in randomization order at ${s.id}`);if(a>1)throw new ae(`Wildcard $ occurred multiples times in randomization order at ${s.id}`);if(r.forEach(o=>{if(o!=="$"&&!i.has(o))throw new ae(`Unknown id ${o} in randomization ordering at ${s.id}`)}),n.total!==void 0&&n.total<r.length)throw new ae(`Total value in randomization is too small at ${s.id}`)}}},Et=(s,t)=>{const n=[w.FOR_MATRIX_CHOICE,w.UNSELECTED_FOR_MATRIX_CHOICE].includes(s.expression),i=(n?t.seenQuestionStatements:t.seenQuestionChoices).get(s.questionId);if(i===void 0)throw new O(`Invalid question referenced in locator expression: ${s.questionId}/${s.expression}`);if(n){const r=t.seenQuestionChoices.get(s.questionId);if(!s.identifier||!r?.has(s.identifier))throw new O(`Invalid choice referenced in locator expression: ${s.questionId}/${s.expression}(${s.identifier})`)}return i},Si=(s,t)=>{if(Ai(t,s.text),s.id!==void 0){if(C(t,s.id,s.display_logic),s.statements?.forEach(i=>{C(t,`${s.id}.${i.id}`,i.display_logic)}),s.choices?.forEach(i=>{C(t,`${s.id}[${i.id||i.value}]`,i.display_logic)}),s.type==="matrix-multi"||s.type==="matrix-single"?s.statement_groups?Q(s,s.statement_groups.map(i=>i.id),s.randomization):Q(s,s.statements?.map(i=>i.id)??[],s.randomization):s.choice_groups?Q(s,s.choice_groups.map(i=>i.id),s.randomization):Q(s,s.choices?.map(i=>`${i.id||i.value}`)??[],s.randomization),s.statement_groups?.forEach(i=>{i.statements.forEach(r=>{C(t,`${s.id}.${r.id}`,r.display_logic)}),Q(s,i.statements.map(r=>r.id),i.randomization)}),s.choice_groups?.forEach(i=>{i.choices.forEach(r=>{C(t,`${s.id}[${r.id||r.value}]`,r.display_logic)}),Q(s,i.choices.map(r=>`${r.id||r.value}`),i.randomization)}),t.seenQuestions.has(s.id))throw new z(`Duplicate question id: ${s.id}`);if(t.seenQuestions.add(s.id),s.type&&["matrix-multi","mc-multi"].includes(s.type)&&t.seenMultiQuestions.add(s.id),s.statements||s.dynamic_statements){const i=new Set;if(t.seenQuestionStatements.set(s.id,i),s.statements?.forEach(r=>{if(i.has(r.id))throw new z(`Duplicate statement id: ${s.id}.${r.id}`);i.add(r.id)}),s.dynamic_statements){const r=S(s.dynamic_statements);Et(r,t).forEach(a=>{if(typeof a=="number")throw new O(`Dynamic statement in question ${s.id} refers to choices with values`);if(i.has(a))throw new z(`Duplicate statement ${a} via dynamic statements in question ${s.id}`);i.add(a)})}}const n=s.choices??[];if(s.choice_groups){if(new Set(s.choice_groups.map(i=>i.id)).size!==s.choice_groups.length)throw new z(`Choice groups must have a unique id in question ${s.id}`);s.choice_groups.forEach(i=>n.push(...i.choices))}if(n||s.dynamic_choices){const i=new Set;t.seenQuestionChoices.set(s.id,i);const r=new Set;if(t.seenTextChoices.set(s.id,r),n.forEach(a=>{const o=a.id??a.value;if(i.has(o))throw new z(`Duplicate choice: ${s.id}[${o}]`);i.add(o),a.text_input&&a.text_input!=="no"&&r.add(o)}),s.dynamic_choices){const a=S(s.dynamic_choices);Et(a,t).forEach(o=>{if(i.has(o))throw new z(`Duplicate choice ${o} via dynamic choices in ${s.id}`);i.add(o)}),t.seenTextChoices.get(a.questionId)?.forEach(o=>r.add(o))}if(new Set([...i].map(a=>typeof a)).size>=2)throw new ki("All choices in a question must either all have id's or all have values")}}},$i=s=>{if(!bt(s))throw new Error(`Invalid template: ${s.template.id}. Reason: ${JSON.stringify(bt.errors,null,4)}`);Qe(s);const t=new Oi;s.sections.forEach(n=>{C(t,n.id,n.display_logic),n.pages.forEach(i=>{i.questions?.forEach(r=>{Si(r,t)})})})};function It(s,t){const n=structuredClone(s);return{...n,sections:n.sections.map(i=>({id:i.id,name:i.name,hideProgressBar:i.hideProgressBar,pages:t.evaluateDisplayLogic(i.displayLogic)?i.pages.map(r=>({...r,questions:zi(r.questions,t)})).filter(r=>r.questions.length):[]})).filter(i=>i.pages.length)}}function zi(s,t){return s.filter(n=>t.evaluateDisplayLogic(n.displayLogic)).map(n=>({...n,text:t.getQuestionText(n),statements:t.getQuestionStatements(n),choices:t.getQuestionChoices(n),statementGroups:t.getQuestionStatementGroups(n),choiceGroups:t.getQuestionChoiceGroups(n),randomization:void 0}))}const Rt=s=>!!s?.singleAnswer||!!s?.multipleAnswers&&s?.multipleAnswers.length>0,Nt=(s,t)=>{let n=!1,i=t,r=new se(s,i);const a=p=>c=>{const _=p.includes(c.questionId);return _&&(n=!0),!_},o=p=>c=>{const _=!c.statementId||p.includes(c.statementId);return _||(n=!0),_},l=p=>c=>{if(c.singleAnswer){const d=!!c.singleAnswer.text||p.includes(c.singleAnswer.choiceId||c.singleAnswer.choiceValue);return d||(n=!0),{...c,singleAnswer:d?c.singleAnswer:void 0}}const _=c.multipleAnswers?.filter(d=>!!d.text||p.includes(d.choiceId||d.choiceValue));return _&&_.length<c.multipleAnswers.length&&(n=!0),{...c,multipleAnswers:_}};for(const p of s.sections){if(!r.evaluateDisplayLogic(p.displayLogic)){const c=p.pages.flatMap(_=>_.questions).map(_=>_.id);i=i.filter(a(c)),n&&(n=!1,r=new se(s,i));continue}for(const c of p.pages)for(const _ of c.questions){if(!r.evaluateDisplayLogic(_.displayLogic))i=i.filter(a([_.id]));else{const d=r.getQuestionStatementsFlattened(_).map(x=>x.id),m=r.getQuestionChoicesFlattened(_).map(x=>x.id||x.value),u=o(d),b=l(m);i=i.filter(x=>x.questionId!==_.id||u(x)),i=i.map(x=>x.questionId!==_.id?x:b(x))}n&&(n=!1,r=new se(s,i))}}return i},qt=(s,t)=>t?`${s}.${t}`:s,Di=(s,t,n,i)=>{if(!t.singleAnswer)return i?.warn("Response validation failed: No SingleAnswer provided in single answer question.",{surveyResponseId:n.surveyResponseId,questionId:t.questionId}),!1;const r=new Set(n.getQuestionChoicesFlattened(s).map(o=>o.id??o.value)),a=t.singleAnswer.choiceId??t.singleAnswer.choiceValue;return r.has(a)?!0:(i?.warn("Response validation failed: Selected choice in single answer question not available",{surveyResponseId:n.surveyResponseId,questionId:s.id,choiceKey:a}),!1)},Pi=(s,t,n,i)=>{if(!t.multipleAnswers)return i?.warn("Response validation failed: No MultipleAnswer provided in multi answer question",{surveyResponseId:n.surveyResponseId,questionId:t.questionId}),!1;const r=new Set(n.getQuestionChoicesFlattened(s).map(o=>o.id??o.value));let a=!1;return t.multipleAnswers.forEach(o=>{const l=o.choiceId??o.choiceValue;r.has(l)||(i?.warn("Response validation failed: Selected choice in multi answer question not available",{surveyResponseId:n.surveyResponseId,questionId:s.id,choiceKey:l}),a=!0)}),!a},Li=(s,t,n)=>s.singleAnswer?.text?!0:(n?.warn("Response validation failed: No text provided",{surveyResponseId:t.surveyResponseId,questionId:s.questionId}),!1);function kt(s,t,n,i){if(!Rt(t))return!0;switch(ue(s.type)){case I.McSingle:case I.MatrixSingle:return Di(s,t,n,i);case I.McMulti:case I.MatrixMulti:return Pi(s,t,n,i);case I.TextSingle:case I.TextMulti:return Li(t,n,i);default:return i?.warn("Response validation failed: Unsupported question type",{questionId:s.id,questionType:s.type,surveyResponseId:n.surveyResponseId}),!1}}function Ci(s,t,n,i){const r={templateId:s.id,surveyResponseId:n.surveyResponseId};i?.debug("Validating response...",{questionResponses:t,...r});const a=It(s,n),o=de(a),l=Nt(a,t);if(new Set(l.map(_=>qt(_.questionId,_.statementId))).size<l.length)return i?.warn("Response validation failed: Duplicate question/statement ID(s) in the response.",{relevantQuestionResponses:l,...r}),!1;const p=Object.fromEntries(o.filter(_=>_.id).map(_=>[_.id,_])),c=new Map;for(const _ of l){const d=p[_.questionId];if(!d)return i?.warn("Response validation failed: Response provided to a question that's not in the template",{questionId:_.questionId,...r}),!1;let m=c.get(_.questionId);if(m===void 0&&(m=new Map(n.getQuestionStatementsFlattened(d).map(u=>[u.id,u])),c.set(_.questionId,m)),_.statementId){if(!m||!m.size)return i?.warn("Response validation failed: Response provided to a statement even to the question has no statements",{questionId:_.questionId,statementId:_.statementId,...r}),!1;if(!m.get(_.statementId))return i?.warn("Response validation failed: Response provided to an invalid question statement",{questionId:_.questionId,statementId:_.statementId,...r}),!1}else if(m&&m.size)return i?.warn("Response validation failed; Response provided to a question with statements but not statement provided.",{questionId:_.questionId,statementId:_.statementId,...r}),!1;if(!kt(d,_,n,i))return!1}return!0}const Qi=Ce,Mi="pulse_default_alpha",ji={allPermissions:Gt,SURVEY_RESOURCE_TYPE:Zt,surveyAdministerPermission:Pe};exports.DEFAULT_TEMPLATE_ID=Mi,exports.LOCATOR_EXPRESSION=w,exports.QUESTION_TEXT_LOCATOR_PATTERN=Ae,exports.TemplateContextEvaluator=se,exports.evaluateExpression=Se,exports.evaluateTemplateNode=It,exports.extractQuestionNodes=de,exports.getExperimentalOptionalBoolean=Vt,exports.getExperimentalOptionalString=Wt,exports.getQualifiedQuestionId=Fe,exports.getQuestionTypeEnum=ue,exports.getRandomizationTypeEnum=Ue,exports.getRawQuestionId=pe,exports.getRelevantQuestionResponses=Nt,exports.getTemplateNode=fn,exports.hasAnswer=Rt,exports.interpolateMacros=_e,exports.interpolateTemplate=Qe,exports.parseLocator=S,exports.permissions=ji,exports.polyfillStructuredClone=Xt,exports.responseRef=qt,exports.templateSchema=Qi,exports.transformCase=W,exports.validateLocator=je,exports.validateQuestionResponse=kt,exports.validateResponse=Ci,exports.validateTemplate=$i;
|
|
1
|
+
"use strict";var t=require("./permissions.cjs.js"),s=require("./config.cjs.js"),p=require("./polyfills.cjs.js"),n=require("./templates/index.cjs.js"),u=require("./transformCase.cjs.js"),T=require("./templates/validateTemplate.cjs.js"),a=require("./templates/evaluation.cjs.js"),e=require("./templates/convertTemplateToNode.cjs.js"),l=require("./templates/interpolation.cjs.js"),r=require("./templates/locators.cjs.js"),i=require("./templates/logic.cjs.js"),o=require("./templates/validateResponse.cjs.js");const m={allPermissions:t.allPermissions,SURVEY_RESOURCE_TYPE:t.SURVEY_RESOURCE_TYPE,surveyAdministerPermission:t.surveyAdministerPermission};exports.getExperimentalOptionalBoolean=s.getExperimentalOptionalBoolean,exports.getExperimentalOptionalString=s.getExperimentalOptionalString,exports.polyfillStructuredClone=p.polyfillStructuredClone,exports.DEFAULT_TEMPLATE_ID=n.DEFAULT_TEMPLATE_ID,exports.templateSchema=n.templateSchema,exports.transformCase=u.transformCase,exports.validateTemplate=T.validateTemplate,exports.evaluateTemplateNode=a.evaluateTemplateNode,exports.getRelevantQuestionResponses=a.getRelevantQuestionResponses,exports.hasAnswer=a.hasAnswer,exports.extractQuestionNodes=e.extractQuestionNodes,exports.getQualifiedQuestionId=e.getQualifiedQuestionId,exports.getQuestionTypeEnum=e.getQuestionTypeEnum,exports.getRandomizationTypeEnum=e.getRandomizationTypeEnum,exports.getRawQuestionId=e.getRawQuestionId,exports.getTemplateNode=e.getTemplateNode,exports.interpolateMacros=l.interpolateMacros,exports.interpolateTemplate=l.interpolateTemplate,exports.LOCATOR_EXPRESSION=r.LOCATOR_EXPRESSION,exports.parseLocator=r.parseLocator,exports.validateLocator=r.validateLocator,exports.QUESTION_TEXT_LOCATOR_PATTERN=i.QUESTION_TEXT_LOCATOR_PATTERN,exports.TemplateContextEvaluator=i.TemplateContextEvaluator,exports.evaluateExpression=i.evaluateExpression,exports.responseRef=o.responseRef,exports.validateQuestionResponse=o.validateQuestionResponse,exports.validateResponse=o.validateResponse,exports.permissions=m;
|
|
23
2
|
//# sourceMappingURL=index.cjs.js.map
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import * as
|
|
1
|
+
import * as _backstage_plugin_permission_common_index from '@backstage/plugin-permission-common/index';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* Types automatically generated by `yarn json2ts`.
|
|
@@ -818,9 +818,9 @@ type SurveyQuestionResponse = {
|
|
|
818
818
|
|
|
819
819
|
/** @public */
|
|
820
820
|
declare const permissions: {
|
|
821
|
-
allPermissions:
|
|
821
|
+
allPermissions: _backstage_plugin_permission_common_index.BasicPermission[];
|
|
822
822
|
SURVEY_RESOURCE_TYPE: string;
|
|
823
|
-
surveyAdministerPermission:
|
|
823
|
+
surveyAdministerPermission: _backstage_plugin_permission_common_index.BasicPermission;
|
|
824
824
|
};
|
|
825
825
|
|
|
826
826
|
export { type Answer, type Choice, DEFAULT_TEMPLATE_ID, LOCATOR_EXPRESSION, type Locator, type Page, type Question, type Randomization, type Section, type Statement, type SurveyQuestionResponse, type SurveyTemplate, interpolateTemplate, parseLocator, permissions, templateSchema, validateLocator, validateTemplate };
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
"use strict";var i=require("@backstage/plugin-permission-common");const e="survey-instance",s=i.createPermission({name:"survey.instance.administer",attributes:{action:"create"}}),r=[s];exports.SURVEY_RESOURCE_TYPE=e,exports.allPermissions=r,exports.surveyAdministerPermission=s;
|
|
2
|
+
//# sourceMappingURL=permissions.cjs.js.map
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
"use strict";var l=require("@ungap/structured-clone");function u(t){return t&&typeof t=="object"&&"default"in t?t:{default:t}}var e=u(l);const r=()=>{"structuredClone"in globalThis||(globalThis.structuredClone=e.default)};exports.polyfillStructuredClone=r;
|
|
2
|
+
//# sourceMappingURL=polyfills.cjs.js.map
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
"use strict";var r=require("../transformCase.cjs.js");function d(e){const n=structuredClone(e);return{...n,...n.template,sections:n.sections.map(t=>({...r.transformCase(t),pages:t.pages.map((o,p)=>({...o,id:`${t.id}-${p}`,questions:m(n,t,o.questions)}))}))}}function m(e,n,t){return t.map(o=>c(e.template.id,n,o))}function c(e,n,t){return{...r.transformCase({...t,choiceGroups:t.choice_groups?.map(o=>({...o,randomization:i(o.randomization)})),statementGroups:t.statement_groups?.map(o=>({...o,randomization:i(o.randomization)})),randomization:i(t.randomization)}),id:u(e,t),type:s(t.type),layout:f(t.layout),required:g(t.required),label:n.name}}function i(e){return e?{type:a(e.type),order:e.order?.split(" "),total:e.total}:void 0}function a(e){return e.toUpperCase()}function u(e,n){return`${e}.${n.id}`}const l=e=>e.split(".").pop();function s(e="description"){return e.replace("-","_").toUpperCase()}function f(e){return e?.toUpperCase()}function g(e="optional"){return e.replace("-","_").toUpperCase()}function y(e){return structuredClone(e).sections.flatMap(n=>n.pages.flatMap(t=>t.questions))}exports.extractQuestionNodes=y,exports.getQualifiedQuestionId=u,exports.getQuestionTypeEnum=s,exports.getRandomizationTypeEnum=a,exports.getRawQuestionId=l,exports.getTemplateNode=d;
|
|
2
|
+
//# sourceMappingURL=convertTemplateToNode.cjs.js.map
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
"use strict";var c=require("./logic.cjs.js");function w(i,o){const e=structuredClone(i);return{...e,sections:e.sections.map(t=>({id:t.id,name:t.name,hideProgressBar:t.hideProgressBar,pages:o.evaluateDisplayLogic(t.displayLogic)?t.pages.map(a=>({...a,questions:v(a.questions,o)})).filter(a=>a.questions.length):[]})).filter(t=>t.pages.length)}}function v(i,o){return i.filter(e=>o.evaluateDisplayLogic(e.displayLogic)).map(e=>({...e,text:o.getQuestionText(e),statements:o.getQuestionStatements(e),choices:o.getQuestionChoices(e),statementGroups:o.getQuestionStatementGroups(e),choiceGroups:o.getQuestionChoiceGroups(e),randomization:void 0}))}const A=i=>!!i?.singleAnswer||!!i?.multipleAnswers&&i?.multipleAnswers.length>0,Q=(i,o)=>{let e=!1,t=o,a=new c.TemplateContextEvaluator(i,t);const g=u=>n=>{const s=u.includes(n.questionId);return s&&(e=!0),!s},p=u=>n=>{const s=!n.statementId||u.includes(n.statementId);return s||(e=!0),s},d=u=>n=>{if(n.singleAnswer){const r=!!n.singleAnswer.text||u.includes(n.singleAnswer.choiceId||n.singleAnswer.choiceValue);return r||(e=!0),{...n,singleAnswer:r?n.singleAnswer:void 0}}const s=n.multipleAnswers?.filter(r=>!!r.text||u.includes(r.choiceId||r.choiceValue));return s&&s.length<n.multipleAnswers.length&&(e=!0),{...n,multipleAnswers:s}};for(const u of i.sections){if(!a.evaluateDisplayLogic(u.displayLogic)){const n=u.pages.flatMap(s=>s.questions).map(s=>s.id);t=t.filter(g(n)),e&&(e=!1,a=new c.TemplateContextEvaluator(i,t));continue}for(const n of u.pages)for(const s of n.questions){if(!a.evaluateDisplayLogic(s.displayLogic))t=t.filter(g([s.id]));else{const r=a.getQuestionStatementsFlattened(s).map(l=>l.id),m=a.getQuestionChoicesFlattened(s).map(l=>l.id||l.value),f=p(r),h=d(m);t=t.filter(l=>l.questionId!==s.id||f(l)),t=t.map(l=>l.questionId!==s.id?l:h(l))}e&&(e=!1,a=new c.TemplateContextEvaluator(i,t))}}return t};exports.evaluateTemplateNode=w,exports.getRelevantQuestionResponses=Q,exports.hasAnswer=A;
|
|
2
|
+
//# sourceMappingURL=evaluation.cjs.js.map
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
"use strict";var a=require("./schema/survey-template-schema.json.cjs.js"),r=require("./validateTemplate.cjs.js");require("assert"),require("crypto"),require("../graphql/schema-types.generated.cjs.js"),require("lodash");var e=require("./locators.cjs.js");require("./schema/logic_parser.cjs.js");const t=a.default,l="pulse_default_alpha";exports.validateTemplate=r.validateTemplate,exports.LOCATOR_EXPRESSION=e.LOCATOR_EXPRESSION,exports.parseLocator=e.parseLocator,exports.validateLocator=e.validateLocator,exports.DEFAULT_TEMPLATE_ID=l,exports.templateSchema=t;
|
|
2
|
+
//# sourceMappingURL=index.cjs.js.map
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
"use strict";const i=/\$\{m:([^\}]+)\}/g,p=100,n=(t,e)=>{if(typeof e=="string"){let o=e,a=0;for(;a<100;){const r=o.replace(i,(l,c)=>{if(t[c]===void 0)throw new Error(`Undefined macro: ${c}`);return t[c]});if(r===o)return r;o=r,a+=1}throw new Error(`Failed to finish interpolate macros - cyclic macros!? Stuck at: ${e}"`)}return typeof e=="object"&&Object.keys(e).forEach(o=>{e[o]=n(t,e[o])}),e},s=t=>(t.sections=n(t.macros||{},t.sections),t);exports.interpolateMacros=n,exports.interpolateTemplate=s;
|
|
2
|
+
//# sourceMappingURL=interpolation.cjs.js.map
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
"use strict";const _="(?<questionId>[a-zA-Z][a-zA-Z0-9_]*)",a="((?<expressionWithoutIdentifier>all|all_entered_text|selected|selected_entered_text|not_selected)|(?<expressionWithIdentifier>for_matrix_choice|unselected_for_matrix_choice)(\\((?<identifier>[\\-a-zA-Z0-9_]+)\\)))",r=new RegExp(`^${_}/${a}$`);var o=(e=>(e.ALL="all",e.ALL_ENTERED_TEXT="all_entered_text",e.SELECTED="selected",e.SELECTED_ENTERED_TEXT="selected_entered_text",e.NOT_SELECTED="not_selected",e.FOR_MATRIX_CHOICE="for_matrix_choice",e.UNSELECTED_FOR_MATRIX_CHOICE="unselected_for_matrix_choice",e))(o||{});const c=e=>r.test(e),d=e=>{const t=e.match(r)?.groups;if(!t)throw new Error(`Invalid locator expression: ${e}`);const n=t.expressionWithoutIdentifier||t.expressionWithIdentifier||"all",i={questionId:t.questionId,expression:n};if(t.identifier){const s=isNaN(parseInt(t.identifier,10))?t.identifier:parseInt(t.identifier,10);i.identifier=s}return i};exports.LOCATOR_EXPRESSION=o,exports.parseLocator=d,exports.validateLocator=c;
|
|
2
|
+
//# sourceMappingURL=locators.cjs.js.map
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
"use strict";var O=require("assert"),C=require("crypto"),I=require("../graphql/schema-types.generated.cjs.js"),y=require("./convertTemplateToNode.cjs.js"),l=require("./locators.cjs.js"),x=require("./schema/logic_parser.cjs.js");function L(s){return s&&typeof s=="object"&&"default"in s?s:{default:s}}function q(s){if(s&&typeof s=="object"&&"default"in s)return s;var e=Object.create(null);return s&&Object.keys(s).forEach(function(i){if(i!=="default"){var t=Object.getOwnPropertyDescriptor(s,i);Object.defineProperty(e,i,t.get?t:{enumerable:!0,get:function(){return s[i]}})}}),e.default=s,Object.freeze(e)}var w=L(O),A=q(C);const g=/\$\{q\:(?<locator>[\-a-zA-Z0-9_\/\(\)]+)\}/g,_=s=>s.choiceId??s.choiceValue??s.text;class Q{questions=new Map;responsesByQuestion=new Map;responsesByQuestionStatement=new Map;surveyResponseId;forExport;evaluationCache=new Map;constructor(e,i=[],t="",n=!1){this.questions=new Map((e?y.extractQuestionNodes(e):[]).filter(a=>a.id).map(a=>[y.getRawQuestionId(a.id),a])),i.filter(a=>a.singleAnswer||a.multipleAnswers).forEach(a=>{const c=y.getRawQuestionId(a.questionId);this.responsesByQuestion.set(c,[...this.responsesByQuestion.get(c)||[],a]),a.statementId&&this.responsesByQuestionStatement.set(`${c}.${a.statementId}`,a)}),this.surveyResponseId=t,this.forExport=n}getQuestionAnswers(e,i){let t;if(i){const n=this.responsesByQuestionStatement.get(`${e}.${i}`);t=n===void 0?[]:[n]}else t=this.responsesByQuestion.get(e)||[];return t.flatMap(n=>{const{multipleAnswers:a,singleAnswer:c}=n;return a||[c]})}#e(e,i,t){return this.getQuestionAnswers(e,i).filter(n=>typeof t>"u"||t===null||_(n)===t)}#t(e,i){if(e.textInput&&["forced","optional"].includes(e.textInput)){const t=this.textEntry({questionId:i.questionId,choice:e.id||e.value});return t.trim()?{...e,display:t}:e.textInput==="forced"?null:e}return e}evaluateDisplayLogic(e){if(e&&!this.forExport)try{const i=this.evaluationCache.get(e);if(i!==void 0)return i;const t=R(e,this);return this.evaluationCache.set(e,t),t}catch(i){return console.error(i),!1}return!0}evaluateDynamicExpression(e,i){const t=this.questions.get(e.questionId);if(!t)return[];const n=this.getQuestionChoicesFlattened(t),a=n.filter(o=>this.isSelected({questionId:e.questionId,choice:o.id||o.value})),c=this.getQuestionStatementsFlattened(t),d=o=>i==="choices"?o:{...o,id:o.id||o.value||o.display},h=o=>({id:o.id,display:o.display,value:o.value});let u=[];switch(e.expression){case l.LOCATOR_EXPRESSION.ALL:u=n.map(d);break;case l.LOCATOR_EXPRESSION.ALL_ENTERED_TEXT:u=n.map(o=>this.#t(o,e)).filter(o=>!!o).map(o=>d(o));break;case l.LOCATOR_EXPRESSION.SELECTED:u=a;break;case l.LOCATOR_EXPRESSION.SELECTED_ENTERED_TEXT:u=a.map(o=>this.#t(o,e)).filter(o=>!!o).map(o=>d(o));break;case l.LOCATOR_EXPRESSION.NOT_SELECTED:u=n.filter(o=>!this.isSelected({questionId:e.questionId,choice:o.id||o.value})).map(d);break;case l.LOCATOR_EXPRESSION.FOR_MATRIX_CHOICE:u=c.filter(o=>this.isSelected({questionId:e.questionId,statementId:o.id,choice:e.identifier}));break;case l.LOCATOR_EXPRESSION.UNSELECTED_FOR_MATRIX_CHOICE:u=c.filter(o=>!this.isSelected({questionId:e.questionId,statementId:o.id,choice:e.identifier}));break;default:u=[]}return this.forExport&&(u=e.expression===l.LOCATOR_EXPRESSION.FOR_MATRIX_CHOICE||e.expression===l.LOCATOR_EXPRESSION.UNSELECTED_FOR_MATRIX_CHOICE?c:n.map(d)),u.map(h)}isSelected(e){return!!this.#e(e.questionId,e.statementId,e.choice).length}countSelected(e){return this.getQuestionAnswers(e).length}selectedValue(e){const i=this.getQuestionAnswers(typeof e=="string"?e:e.questionId,typeof e=="string"?void 0:e.statementId);return i.length?_(i[0]):null}countChoiceSelections(e,i){return this.#e(e,null,i).length}textEntry(e){return this.#e(e.questionId,e.statementId,e.choice).map(i=>i.text).filter(i=>i).join(", ")}getQuestionText(e){if(this.forExport)return e.text;let i=e.text;return i=i.replaceAll(g,(t,n)=>{if(n&&l.validateLocator(n)){const a=l.parseLocator(n);return this.evaluateDynamicExpression(a,"choices").map(c=>c.display).join(", ")}return t}),i}getQuestionChoices(e){const i=(e.choices??[]).filter(t=>this.evaluateDisplayLogic(t.displayLogic));if(e.dynamicChoices){const t=l.parseLocator(e.dynamicChoices),n=this.evaluateDynamicExpression(t,"choices");i.push(...n)}return e.type===I.QuestionType.MatrixSingle||e.type===I.QuestionType.MatrixMulti?i:this.applyRandomization(i,e.id,t=>`${t.id??t.value}`,e.randomization)}getQuestionChoiceGroups(e){const i=(e.choiceGroups?.filter(t=>this.evaluateDisplayLogic(t.displayLogic))||[]).map(t=>({...t,choices:this.applyRandomization(t.choices.filter(n=>this.evaluateDisplayLogic(n.displayLogic)),e.id,n=>`${n.id??n.value}`,t.randomization)})).filter(t=>!!t.choices.length);return this.applyRandomization(i,e.id,t=>t.id,e.randomization)}getQuestionStatements(e){const i=(e.statements??[]).filter(t=>this.evaluateDisplayLogic(t.displayLogic));if(e.dynamicStatements){const t=l.parseLocator(e.dynamicStatements),n=this.evaluateDynamicExpression(t,"statements");i.push(...n)}return this.applyRandomization(i,e.id,t=>t.id,e.randomization)}getQuestionStatementGroups(e){const i=(e.statementGroups?.filter(t=>this.evaluateDisplayLogic(t.displayLogic))||[]).map(t=>({...t,statements:this.applyRandomization(t.statements.filter(n=>this.evaluateDisplayLogic(n.displayLogic)),e.id,n=>n.id,t.randomization)})).filter(t=>!!t.statements.length);return this.applyRandomization(i,e.id,t=>t.id,e.randomization)}getQuestionChoicesFlattened(e){return[...this.getQuestionChoices(e),...this.getQuestionChoiceGroups(e).flatMap(i=>i.choices)]}getQuestionStatementsFlattened(e){return[...this.getQuestionStatements(e),...this.getQuestionStatementGroups(e).flatMap(i=>i.statements)]}applyRandomization(e,i,t,n){if(!n||this.forExport)return e;const a=new Map(e.map(r=>[t(r),r])),c=[...a.keys()],d=new Set(c),h=(n.order??["$"]).filter(r=>r==="$"||d.has(r)),u=c.filter(r=>!h.includes(r)).map(r=>({weight:this.keyHash(i,r),key:r}));u.sort((r,E)=>r.weight.localeCompare(E.weight));const o=n.total??c.length,S=Math.min(o-(h.length-1),u.length),f=[];return h.forEach(r=>{r==="$"?f.push(...u.slice(0,S).map(E=>E.key)):f.push(r)}),f.map(r=>a.get(r))}keyHash(e,i){const t=`${e}.${this.surveyResponseId}.${i}`;return A.createHash("sha256").update(t).digest("hex")}}function v(s){if(s.length===1)return s[0];const e=s[1].value;return e==="or"?s[0]||s[2]:e==="and"?s[0]&&s[2]:!1}function m(s,e,i){switch(e){case"==":return s===i;case"!=":return s!==i;case"<=":return s<=i;case">=":return s>=i;case"<":return s<i;case">":return s>i;default:return!1}}function T(s,e,i,t){const n=t?s.toLowerCase():s,a=t?i.toLowerCase():i;switch(e){case"contains":return n.includes(a);case"not_contains":return!n.includes(a);case"regex_matches":try{return new RegExp(i).test(n)}catch{return!1}default:return m(n,e,a)}}function N(s,e){return s.length>0&&s[0].hasOwnProperty("type")&&s[0].type==="NEGATION"?!e(s.slice(1)):e(s)}function D(s){if(!["INT","IDENTIFIER"].includes(s.type))throw new SyntaxError(`Invalid token type: ${s.type}; expected IDENTIFIER or INT`);return p(s)}function p(s){switch(s.type){case"IDENTIFIER":return s.value;case"INT":return parseInt(s.value,10);case"STRING":{const e=s.value.match(/(?:'(?<single>[^\']*)')|(?:"(?<double>[^\"]*)")/),i=e?.groups?.double||e?.groups?.single;return w.default(i),i}case"OPERATOR":return s.value;case"TRUE":return!0;case"FALSE":return!1;default:throw new SyntaxError(`Invalid token type: ${s.type}`)}}function R(s,e){const i={bool_const:t=>t[0].value==="true",condition:t=>t[0],bool_expr:v,top_level_expr:v,start:t=>t[0],question_id:t=>t[0].value,choice_ref:t=>D(t[0]),matrix_statement_id:t=>({questionId:t[0],statementId:t[1].value}),question_choice_selected:t=>N(t,n=>e.isSelected({questionId:typeof n[0]=="string"?n[0]:n[0].questionId,statementId:typeof n[0]=="string"?void 0:n[0].statementId,choice:n[1]})),question_choice_selected_value_comparison:t=>{const n=e.selectedValue(t[0]);return n!==null&&m(n,p(t[1]),p(t[2]))},question_choice_text_comparison:t=>T(e.textEntry({questionId:t[0],choice:t[1]}),p(t[2]),p(t[3]),!1),question_choice_text_comparison_case_insensitive:t=>T(e.textEntry({questionId:t[0],choice:t[1]}),p(t[2]),p(t[3]),!0),selected_count_comparison:t=>m(e.countSelected(t[0]),p(t[1]),p(t[2])),choice_selection_count_comparison:t=>m(e.countChoiceSelections(t[0],t[1]),p(t[2]),p(t[3]))};return x.default.get_parser({transformer:i}).parse(s)}exports.QUESTION_TEXT_LOCATOR_PATTERN=g,exports.TemplateContextEvaluator=Q,exports.evaluateExpression=R;
|
|
2
|
+
//# sourceMappingURL=logic.cjs.js.map
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});function $e(i={}){return i.transformer&&i.transformer.constructor.name==="object"&&(i.transformer=L.fromObj(i.transformer)),Fe._load_from_dict({data:Jt,memo:Vt,...i})}const me={};class fe{}const j={},de={escape(i){return i.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")},compile(i,t){return new RegExp(i,t)},error:SyntaxError};function We(i,t,r,n){const s=i.compile(t,n).exec(r);if(s!=null)return s[0]}class ye{constructor(t,r,n,s,_=!1){this.terminals=t,this.g_regex_flags=r,this.re_=n,this.use_bytes=s,this.match_whole=_,this.allowed_types=new Set(this.terminals.map(l=>l.name)),this._regexps=this._build_mres(t)}_build_mres(t){let r=this.match_whole?"$":"",n=Ye(t,_=>_.pattern.flags.join("")),s=[];for(let[_,l]of n){const a=l.map(p=>`(?<${p.name}>${p.pattern.to_regexp()+r})`).join("|");s.push(new RegExp(a,this.g_regex_flags+_+"y"))}return s}match(t,r){for(const n of this._regexps){n.lastIndex=r;let s=n.exec(t);if(s){let _=null;for(let[l,a]of Object.entries(s.groups))if(a){_=l;break}return[s[0],_]}}}}const ge=typeof require<"u"&&require("util");class xe{}const D={};function f(i){return Object.entries(i)}function J(i){return Object.keys(i)}function Ge(i,t){t===void 0&&(t=Object.keys(i)[0]);let r=i[t];return delete i[t],r}function we(i,t,r=null){return i[t]||r}function be(i,t){if(i.constructor.name==="Map")for(const[r,n]of f(t))i.set(r,n);else for(const[r,n]of f(t))i[r]=n}function Ze(i){return function(){return new i(...arguments)}}function u(i){let t=0,r=[...arguments].slice(1);return i.replace(/%([sr])/g,function(){const n=arguments[1],s=r[t++];return n==="r"?ge?ge.inspect(s,!1,null,!0):JSON.stringify(s,null,0):s})}function Je(i,t){let r=new Set(i);for(const n of t)r.add(n);return r}function ke(i,t){return[...i].filter(r=>!t.has(r))}function Te(i){return{...i}}function Ne(i){return!!i}function V(i){return Object.create(i.prototype)}function w(i){if(typeof i=="object"){let t=Object.create(Object.getPrototypeOf(i));return Object.assign(t,i)}return i}function C(i){return new Set(i)}function K(i){return i&&i.constructor.name==="Object"}function Ve(i){return i&&i.constructor.name==="Array"}function Ke(i){return typeof i=="function"}function*I(i,t=0){let r=t;for(const n of i)yield[r++,n]}function He(i){for(const t of i)if(t)return!0;return!1}function Re(i,t){return t.filter(i||Ne)}function B(i){let t=[...arguments].slice(1);return function(){return i(...t,...arguments)}}class H extends Error{}function d(i){return i[i.length-1]}function E(i){return function(){let t=new i(...arguments);return t.__call__.bind(t)}}function b(i,t){return Array.from({length:t},()=>i).flat()}function ve(i){return/^[A-Z_$]*$/.test(i)}function X(i,t,r){const n=i.split(t);return r?n.splice(-r-1):n}function Y(i,t){let r=new RegExp(t,"g");return(i.match(r)||[]).length}function Xe(i,t){for(let r of i)if(!t.has(r))return!1;return!0}function*Ye(i,t){let r=[],n=null;for(const s of i){const _=t(s);n&&_!=n&&(yield[n,r],r=[]),r.push(s),n=_}yield[n,r]}class k extends Error{}class T extends k{}function ee(i,t,r="Got %r, expected one of %s"){if(!t.includes(i))throw new T(u(r,i,t))}class F extends k{}class et extends k{}class z extends k{}class N extends k{pos_in_stream=null;_terminals_by_name=null;get_context(t,r=40){let n,s,_=this.pos_in_stream,l=max(_-r,0),a=_+r;return t instanceof bytes?(s=d(X(t.slice(l,_),`
|
|
2
|
+
`,1)),n=t.slice(_,a).split(`
|
|
3
|
+
`,1)[0],(s+n+`
|
|
4
|
+
`+" "*s.expandtabs().length+`^
|
|
5
|
+
`).decode("ascii","backslashreplace")):(s=d(X(t.slice(l,_),`
|
|
6
|
+
`,1)),n=t.slice(_,a).split(`
|
|
7
|
+
`,1)[0],s+n+`
|
|
8
|
+
`+" "*s.expandtabs().length+`^
|
|
9
|
+
`)}match_examples(t,r,n=!1){K(r)&&(r=f(r));let s=[null,!1];for(const[_,[l,a]]of I(r))for(const[p,o]of I(a))try{t(o)}catch(c){if(c instanceof N){if(c.state.eq(this.state)){if(c.token===this.token)return l;n&&c.token.type===this.token.type&&!d(s)&&(s=[l,!0]),s[0]===null&&(s=[l,!1])}}else throw c}return s[0]}_format_expected(t){let r;return this._terminals_by_name&&(r=this._terminals_by_name,t=t.map(n=>n in r?r[n].user_repr():n)),u(`Expected one of:
|
|
10
|
+
* %s
|
|
11
|
+
`,t.join(`
|
|
12
|
+
* `))}}class tt extends N{constructor(t,r=null,n=null){super(),this.expected=t,this.state=r,this.token=new h("<EOF>",""),this.pos_in_stream=-1,this.line=-1,this.column=-1,this._terminals_by_name=n}}class O extends N{constructor({seq:t,lex_pos:r,line:n,column:s,allowed:_=null,considered_tokens:l=null,state:a=null,token_history:p=null,terminals_by_name:o=null,considered_rules:c=null}={}){super(),this.line=n,this.column=s,this.pos_in_stream=r,this.state=a,this._terminals_by_name=o,this.allowed=_,this.considered_tokens=l,this.considered_rules=c,this.token_history=p,this.char=t[r]}}class A extends N{constructor({token:t,expected:r,considered_rules:n=null,state:s=null,interactive_parser:_=null,terminals_by_name:l=null,token_history:a=null}={}){super(),this.line=t&&t.line||"?",this.column=t&&t.column||"?",this.pos_in_stream=t&&t.start_pos||null,this.state=s,this.token=t,this.expected=r,this._accepts=me,this.considered_rules=n,this.interactive_parser=_,this._terminals_by_name=l,this.token_history=a}get accepts(){return this._accepts===me&&(this._accepts=this.interactive_parser&&this.interactive_parser.accepts()),this._accepts}}class te extends k{constructor(t,r,n){let s=u(`Error trying to process rule "%s":
|
|
13
|
+
|
|
14
|
+
%s`,t,n);super(s),this.rule=t,this.obj=r,this.orig_exc=n}}function rt(i,t=null,r=null){let n,s,_=new Map;for(const l of i)n=t!==null?t(l):l,s=r!==null?r(l):l,_.has(n)?_.get(n).push(s):_.set(n,[s]);return _}function Q(i,t,r){let n;return K(i)?"__type__"in i?(n=t[i.__type__],n.deserialize(i,r)):"@"in i?r[i["@"]]:Object.fromEntries(f(i).map(([s,_])=>[s,Q(_,t,r)])):Ve(i)?i.map(s=>Q(s,t,r)):i}class y{static deserialize(t,r){const n=this;let s=n&&n.__serialize_fields__;if("@"in t)return r[t["@"]];let _=V(n);for(const l of s)if(t&&l in t)_[l]=Q(t[l],Gt,r);else throw new KeyError("Cannot find key for class",n,e);return"_deserialize"in _&&_._deserialize(),_}}class nt extends y{static get __serialize_fields__(){return["memoized"]}constructor(t){super(),this.types_to_memoize=t,this.memoized=new Enumerator}in_types(t){return t instanceof this.types_to_memoize}serialize(){return _serialize(this.memoized.reversed(),null)}static deserialize(t,r,n){return Q(t,r,n)}}class Ee{constructor(){this.empty=!0}}class m{constructor(t,r,n=null){this.data=t,this.children=r,this._meta=n}get meta(){return this._meta===null&&(this._meta=new Ee),this._meta}repr(){return u("Tree(%r, %r)",this.data,this.children)}_pretty_label(){return this.data}_pretty(t,r){if(this.children.length===1&&!(this.children[0]instanceof m))return[b(r,t).join(""),this._pretty_label()," ",u("%s",this.children[0].value),`
|
|
15
|
+
`];let n=[b(r,t).join(""),this._pretty_label(),`
|
|
16
|
+
`];for(const s of this.children)s instanceof m?n.push(...s._pretty(t+1,r)):n.push(b(r,t+1).join(""),u("%s",s.value),`
|
|
17
|
+
`);return n}pretty(t=" "){return this._pretty(0,t).join("")}eq(t){return t&&this&&t&&this&&t.children&&this.children&&t.data&&this.data?this.data===t.data&&this.children===t.children:!1}iter_subtrees(){let t=[this],r=new Map;for(const n of t)r.set(n,n),t.push(...[...n.children].reverse().filter(s=>s instanceof m&&!r.has(s)).map(s=>s));return t=void 0,[...r.values()].reverse()}find_pred(t){return Re(t,this.iter_subtrees())}find_data(t){return this.find_pred(r=>r.data===t)}*scan_values(t){for(const r of this.children)if(r instanceof m)for(const n of r.scan_values(t))yield n;else t(r)&&(yield r)}*iter_subtrees_topdown(){let t,r=[this];for(;r.length;)if(t=r.pop(),t instanceof m){yield t;for(const n of[...t.children].reverse())r.push(n)}}copy(){return type(this)(this.data,this.children)}set(t,r){this.data=t,this.children=r}}class L extends fe{static get __visit_tokens__(){return!0}constructor(t=!0){super(),this.__visit_tokens__=t}static fromObj(t,...r){class n extends this{}for(let[s,_]of Object.entries(t))n.prototype[s]=_;return new n(...r)}_call_userfunc(t,r=null){let n,s,_=r!==null?r:t.children;if(t&&t.data&&this&&this[t.data]){n=this&&this[t.data];try{return s=n&&n.visit_wrapper||null,s!==null?n.visit_wrapper(n,t.data,_,t.meta):n(_)}catch(l){throw l instanceof F?l:l instanceof Error?new te(t.data,t,l):l}}else return this.__default__(t.data,_,t.meta)}_call_userfunc_token(t){let r;if(t&&t.type&&this&&this[t.type]){r=this&&this[t.type];try{return r(t)}catch(n){throw n instanceof F?n:n instanceof Error?new te(t.type,t,n):n}}else return this.__default_token__(t)}*_transform_children(t){let r;for(const n of t)n instanceof m?r=this._transform_tree(n):this.__visit_tokens__&&n instanceof h?r=this._call_userfunc_token(n):r=n,r!==j&&(yield r)}_transform_tree(t){let r=[...this._transform_children(t.children)];return this._call_userfunc(t,r)}transform(t){return this._transform_tree(t)}__default__(t,r,n){return new m(t,r,n)}__default_token__(t){return t}}class Oe extends L{_transform_tree(t){return this._call_userfunc(t)}transform(t){for(const r of t.iter_subtrees())r.children=[...this._transform_children(r.children)];return this._transform_tree(t)}}class st extends L{transform(t){let r,n,s,_=[],l=[t];for(;l.length;){const o=l.pop();_.push(o),o instanceof m&&l.push(...o.children)}let a=[];for(const o of[..._].reverse())o instanceof m?(s=o.children.length,s?(r=a.slice(-s),a.splice(-s)):r=[],n=this._call_userfunc(o,r),n!==j&&a.push(n)):this.__visit_tokens__&&o instanceof h?(n=this._call_userfunc_token(o),n!==j&&a.push(n)):a.push(o);let[p]=a;return p}}class it extends L{_transform_tree(t){return t.children=[...this._transform_children(t.children)],this._call_userfunc(t)}}class re{_call_userfunc(t){const r=this[t.data];return r?r(t):this.__default__(t)}__default__(t){return t}__class_getitem__(t){return cls}}class _t extends re{visit(t){for(const r of t.iter_subtrees())this._call_userfunc(r);return t}visit_topdown(t){for(const r of t.iter_subtrees_topdown())this._call_userfunc(r);return t}}class lt extends re{visit(t){for(const r of t.children)r instanceof m&&this.visit(r);return this._call_userfunc(t),t}visit_topdown(t){this._call_userfunc(t);for(const r of t.children)r instanceof m&&this.visit_topdown(r);return t}}class at extends fe{visit(t){return t.data in this?this[t.data](t):this.__default__(t)}visit_children(t){return t.children.map(r=>r instanceof m?this.visit(r):r)}__default__(t){return this.visit_children(t)}}var ot=0;class ne extends y{is_term=D;constructor(t){super(),this.name=t}eq(t){return this.is_term===t.is_term&&this.name===t.name}repr(){return u("%s(%r)",type(this).name,this.name)}static get fullrepr(){return property(__repr__)}get fullrepr(){return this.constructor.fullrepr}renamed(t){return type(this)(t(this.name))}}class se extends ne{static get __serialize_fields__(){return["name","filter_out"]}get is_term(){return!0}constructor(t,r=!1){super(),this.name=t,this.filter_out=r}get fullrepr(){return u("%s(%r, %r)",type(this).name,this.name,this.filter_out)}renamed(t){return type(this)(t(this.name),this.filter_out)}}class ie extends ne{static get __serialize_fields__(){return["name"]}get is_term(){return!1}}class U extends y{static get __serialize_fields__(){return["keep_all_tokens","expand1","priority","template_source","empty_indices"]}constructor(t=!1,r=!1,n=null,s=null,_=[]){super(),this.keep_all_tokens=t,this.expand1=r,this.priority=n,this.template_source=s,this.empty_indices=_}repr(){return u("RuleOptions(%r, %r, %r, %r)",this.keep_all_tokens,this.expand1,this.priority,this.template_source)}}class P extends y{static get __serialize_fields__(){return["origin","expansion","order","alias","options"]}static get __serialize_namespace__(){return[se,ie,U]}constructor(t,r,n=0,s=null,_=null){super(),this.origin=t,this.expansion=r,this.alias=s,this.order=n,this.options=_||new U,this._hash=[this.origin,this.expansion]}_deserialize(){this._hash=[this.origin,this.expansion]}repr(){return u("Rule(%r, %r, %r, %r)",this.origin,this.expansion,this.alias,this.options)}eq(t){return t instanceof P?this.origin===t.origin&&this.expansion===t.expansion:!1}}class _e extends y{constructor(t,r=[],n=null){super(),this.value=t,this.flags=C(r),this.raw=n}repr(){return repr(this.to_regexp())}eq(t){return type(this)===type(t)&&this.value===t.value&&this.flags===t.flags}to_regexp(){throw new NotImplementedError}get min_width(){throw new NotImplementedError}get max_width(){throw new NotImplementedError}_get_flags(t){return t}}class le extends _e{static get __serialize_fields__(){return["value","flags"]}static get type(){return"str"}to_regexp(){return this._get_flags(de.escape(this.value))}get min_width(){return this.value.length}get max_width(){return this.value.length}}class ae extends _e{static get __serialize_fields__(){return["value","flags","_width"]}static get type(){return"re"}to_regexp(){return this._get_flags(this.value)}_get_width(){return this._width===null&&(this._width=get_regexp_width(this.to_regexp())),this._width}get min_width(){return this._get_width()[0]}get max_width(){return this._get_width()[1]}}class M extends y{static get __serialize_fields__(){return["name","pattern","priority"]}static get __serialize_namespace__(){return[le,ae]}constructor(t,r,n=ot){super(),this.name=t,this.pattern=r,this.priority=n}repr(){return u("%s(%r, %r)",type(this).name,this.name,this.pattern)}user_repr(){return this.name.startsWith("__")?this.pattern.raw||this.name:this.name}}class h{value;type;constructor(t,r,n=null,s=null,_=null,l=null,a=null,p=null){this.type=t,this.start_pos=n,this.value=r,this.line=s,this.column=_,this.end_line=l,this.end_column=a,this.end_pos=p}update(t=null,r=null){return h.new_borrow_pos(t!==null?t:this.type,r!==null?r:this.value,this)}static new_borrow_pos(t,r,n){const s=this;return new s(t,r,n.start_pos,n.line,n.column,n.end_line,n.end_column,n.end_pos)}repr(){return u("Token(%r, %r)",this.type,this.value)}eq(t){return t instanceof h&&this.type!==t.type?!1:str.__eq__(this,t)}static get __hash__(){return str.__hash__}}class ce{constructor(t){this.newline_char=t,this.char_pos=0,this.line=1,this.column=1,this.line_start_pos=0}eq(t){return t instanceof ce?this.char_pos===t.char_pos&&this.newline_char===t.newline_char:D}feed(t,r=!0){let n;r&&(n=Y(t,this.newline_char),n&&(this.line+=n,this.line_start_pos=this.char_pos+t.lastIndexOf(this.newline_char)+1)),this.char_pos+=t.length,this.column=this.char_pos-this.line_start_pos+1}}class pt{constructor(t){this.scanner=t}__call__(t){let r,n=this.scanner.match(t.value,0);return n&&([r,t.type]=n),t}}const ct=E(pt);class ut{constructor(t,r,n){this.callback1=t,this.callback2=r,this.cond=n}__call__(t){let r=this.callback1(t);return this.cond(r)?this.callback2(t):r}}const ht=E(ut);function mt(i,t,r,n){let s,_,l=rt(i,o=>o.pattern.constructor.type),a=new Set,p={};for(const o of l.get("re")||[]){_=[];for(const c of l.get("str")||[])c.priority===o.priority&&(s=c.pattern.value,s===We(r,o.pattern.to_regexp(),s,t)&&(_.push(c),Xe(new Set(c.pattern.flags),new Set(o.pattern.flags))&&a.add(c)));_.length&&(p[o.name]=new ct(new ye(_,t,r,n,!0)))}return[i.filter(o=>!a.has(o)).map(o=>o),p]}function ft(i){return i.includes(`
|
|
18
|
+
`)||i.includes("\\n")||i.includes("\\s")||i.includes("[^")||i.includes("(?s")&&i.includes(".")}class ue{constructor(t,r=null,n=null){this.text=t,this.line_ctr=r||new ce(`
|
|
19
|
+
`),this.last_token=n}eq(t){return t instanceof ue?this.text===t.text&&this.line_ctr===t.line_ctr&&this.last_token===t.last_token:D}}class Ae{constructor(t,r){this.lexer=t,this.state=r}static from_text(t,r){return new this(t,new ue(r))}lex(t){return this.lexer.lex(this.state,t)}}class $ extends xe{lex(t,r){return D}}function dt(i,t){i.sort((r,n)=>{let s=t(r),_=t(n);for(let l=0;l<s.length;l++){if(s[l]>_[l])return 1;if(s[l]<_[l])return-1}return 0})}class W extends ${constructor(t){super();let r=[...t.terminals];if(this.re=t.re_module,!t.skip_validation){for(const n of r){try{this.re.compile(n.pattern.to_regexp(),t.g_regex_flags)}catch(s){throw s instanceof this.re.error?new z(u("Cannot compile token %s: %s",n.name,n.pattern)):s}if(n.pattern.min_width===0)throw new z(u("Lexer does not allow zero-width terminals. (%s: %s)",n.name,n.pattern))}if(!(new Set(t.ignore)<=new Set(r.map(n=>n.name))))throw new z(u("Ignore terminals are not defined: %s",ke(new Set(t.ignore),new Set(r.map(n=>n.name)))))}this.newline_types=C(r.filter(n=>ft(n.pattern.to_regexp())).map(n=>n.name)),this.ignore_types=C(t.ignore),dt(r,n=>[-n.priority,-n.pattern.max_width,-n.pattern.value.length,n.name]),this.terminals=r,this.user_callbacks=t.callbacks,this.g_regex_flags=t.g_regex_flags,this.use_bytes=t.use_bytes,this.terminals_by_name=t.terminals_by_name,this._scanner=null}_build_scanner(){let t;[t,this.callback]=mt(this.terminals,this.g_regex_flags,this.re,this.use_bytes);for(const[r,n]of f(this.user_callbacks))r in this.callback?this.callback[r]=new ht(this.callback[r],n,s=>s.type===r):this.callback[r]=n;this._scanner=new ye(t,this.g_regex_flags,this.re,this.use_bytes)}get scanner(){return this._scanner===null&&this._build_scanner(),this._scanner}match(t,r){return this.scanner.match(t,r)}*lex(t,r){try{for(;;)yield this.next_token(t,r)}catch(n){if(!(n instanceof H))throw n}}next_token(t,r=null){let n,s,_,l,a=t.line_ctr;for(;a.char_pos<t.text.length;){if(s=this.match(t.text,a.char_pos),!s)throw n=ke(this.scanner.allowed_types,this.ignore_types),n||(n=new Set(["<END-OF-FILE>"])),new O({seq:t.text,lex_pos:a.char_pos,line:a.line,column:a.column,allowed:n,token_history:t.last_token&&[t.last_token],state:r,terminals_by_name:this.terminals_by_name});let[p,o]=s;if(this.ignore_types.has(o))o in this.callback&&(l=new h(o,p,a.char_pos,a.line,a.column),this.callback[o](l)),a.feed(p,this.newline_types.has(o));else{if(_=new h(o,p,a.char_pos,a.line,a.column),a.feed(p,this.newline_types.has(o)),_.end_line=a.line,_.end_column=a.column,_.end_pos=a.char_pos,_.type in this.callback&&(_=this.callback[_.type](_),!(_ instanceof h)))throw new z(u("Callbacks must return a token (returned %r)",_));return t.last_token=_,_}}throw new H(this)}}class yt extends ${constructor({conf:t,states:r,always_accept:n=[]}={}){super();let s,_,l,a=[...t.terminals],p=t.terminals_by_name,o=w(t);o.terminals=a;let c=new Map;this.lexers={};for(let[g,v]of f(r))s=C(v),c.has(s)?_=c.get(s):(v=Je(new Set(v),[...new Set(t.ignore),...new Set(n)]),l=w(o),l.terminals=[...v].filter(x=>x in p).map(x=>p[x]),_=new W(l),c.set(s,_)),this.lexers[g]=_;this.root_lexer=new W(o)}*lex(t,r){let n,s,_;try{for(;;)s=this.lexers[r.position],yield s.next_token(t,r)}catch(l){if(!(l instanceof H))if(l instanceof O)try{throw n=t.last_token,_=this.root_lexer.next_token(t,r),new A({token:_,expected:l.allowed,state:r,token_history:[n],terminals_by_name:this.root_lexer.terminals_by_name})}catch(a){throw a}else throw l}}}class Pe extends y{static get __serialize_fields__(){return["terminals","ignore","g_regex_flags","use_bytes","lexer_type"]}static get __serialize_namespace__(){return[M]}constructor({terminals:t,re_module:r,ignore:n=[],postlex:s=null,callbacks:_=null,g_regex_flags:l="",skip_validation:a=!1,use_bytes:p=!1}={}){super(),this.terminals=t,this.terminals_by_name=Object.fromEntries(this.terminals.map(o=>[o.name,o])),this.ignore=n,this.postlex=s,this.callbacks=Object.keys(_).length||{},this.g_regex_flags=l,this.re_module=r,this.skip_validation=a,this.use_bytes=p,this.lexer_type=null}_deserialize(){this.terminals_by_name=Object.fromEntries(this.terminals.map(t=>[t.name,t]))}}class Se extends y{static get __serialize_fields__(){return["rules","start","parser_type"]}constructor(t,r,n){super(),this.rules=t,this.callbacks=r,this.start=n,this.parser_type=null}}class gt{constructor(t){this.node_builder=t}__call__(t){return t.length===1?t[0]:this.node_builder(t)}}const xt=E(gt);class wt{constructor(t,r=null){this.node_builder=t,this.node_filter=r}__call__(t){let r,n,s,_=this.node_builder(t);return _ instanceof m&&(s=_.meta,r=this._pp_get_meta(t),r!==null&&("line"in s||(s.line=r&&r.container_line||r.line,s.column=r&&r.container_column||r.column,s.start_pos=r&&r.container_start_pos||r.start_pos,s.empty=!1),s.container_line=r&&r.container_line||r.line,s.container_column=r&&r.container_column||r.column),n=this._pp_get_meta([...t].reverse()),n!==null&&("end_line"in s||(s.end_line=n&&n.container_end_line||n.end_line,s.end_column=n&&n.container_end_column||n.end_column,s.end_pos=n&&n.container_end_pos||n.end_pos,s.empty=!1),s.container_end_line=n&&n.container_end_line||n.end_line,s.container_end_column=n&&n.container_end_column||n.end_column)),_}_pp_get_meta(t){for(const r of t)if(!(this.node_filter!==null&&!this.node_filter(r))){if(r instanceof m){if(!r.meta.empty)return r.meta}else if(r instanceof h)return r}}}const De=E(wt);function bt(i){if(Ke(i))return B({unknown_param_0:De,node_filter:i});if(i===!0)return De;if(i===!1)return null;throw new T(u("Invalid option for propagate_positions: %r",i))}class oe{constructor(t,r,n){this.node_builder=n,this.to_include=t,this.append_none=r}__call__(t){let r=[];for(const[n,s,_]of this.to_include)_&&r.push(...b([null],_)),s?r.push(...t[n].children):r.push(t[n]);return this.append_none&&r.push(...b([null],this.append_none)),this.node_builder(r)}}const kt=E(oe);class Tt extends oe{__call__(t){let r=[];for(const[n,s,_]of this.to_include)_&&r.push(...b([null],_)),s?r.length?r.push(...t[n].children):r=t[n].children:r.push(t[n]);return this.append_none&&r.push(...b([null],this.append_none)),this.node_builder(r)}}const Nt=E(Tt);class Rt extends oe{constructor(t,r){super(),this.node_builder=r,this.to_include=t}__call__(t){let r=[];for(const[n,s]of this.to_include)s?r.length?r.push(...t[n].children):r=t[n].children:r.push(t[n]);return this.node_builder(r)}}const vt=E(Rt);function Et(i){return!i.is_term&&i.name.startsWith("_")}function Ot(i,t,r,n){let s,_;n.length?(_=n.map(p=>(0+p).toString()).join(""),s=_.split("0").map(p=>p.length)):s=b([0],i.length+1);let l=[],a=0;for(const[p,o]of I(i))a+=s[p],(t||!(o.is_term&&o.filter_out))&&(l.push([p,Et(o),a]),a=0);if(a+=s[i.length],n.length||l.length<i.length||He(l.map(([p,o,c])=>o)))return(n.length||r).length?B(r?kt:Nt,l,a):B(vt,l.map(([p,o,c])=>[p,o]))}function At(i){function t(r){let n=new m(i.name,r);return i(n)}return t=wraps(i)(t),t}function Pt(i,t,r){if(r===_vargs_meta||r===_vargs_meta_inline)throw new NotImplementedError("Meta args not supported for internal transformer");function n(s){return r(i,t,s,null)}return n=wraps(i)(n),n}class St{constructor(t,r,n=!1,s=!1,_=!1){this.tree_class=r,this.propagate_positions=n,this.ambiguous=s,this.maybe_placeholders=_,this.rule_builders=[...this._init_builders(t)]}*_init_builders(t){let r,n,s,_,l=bt(this.propagate_positions);for(const a of t)s=a.options,n=s.keep_all_tokens,r=s.expand1,_=[...Re(null,[r&&!a.alias&&xt,Ot(a.expansion,n,this.ambiguous,this.maybe_placeholders?s.empty_indices:[]),l])],yield[a,_]}create_callback(t=null){let r,n,s,_=new Map;for(const[l,a]of this.rule_builders){n=l.alias||l.options.template_source||l.origin.name,t&&t[n]?(r=t&&t[n],s=r&&r.visit_wrapper||null,s!==null?r=Pt(r,n,s):t instanceof Oe&&(r=At(r))):r=B(this.tree_class,n);for(const p of a)r=p(r);if(_.has(l))throw new F(u("Rule '%s' already exists",l));_.set(l,r)}return _}}class Ie extends y{constructor({parser_conf:t,debug:r=!1}={}){super();let n=new LALR_Analyzer({unknown_param_0:t,debug:r});n.compute_lalr();let s=t.callbacks;this._parse_table=n.parse_table,this.parser_conf=t,this.parser=new ze(n.parse_table,s,r)}static deserialize(t,r,n,s=!1){let _=V(this);return _._parse_table=zt.deserialize(t,r),_.parser=new ze(_._parse_table,n,s),_}serialize(t){return this._parse_table.serialize(t)}parse_interactive(t,r){return this.parser.parse({lexer:t,start:r,start_interactive:!0})}parse({lexer:t,start:r,on_error:n=null}={}){let s,_;try{return this.parser.parse({lexer:t,start:r})}catch(l){if(l instanceof N){if(n===null)throw l;for(;;){if(l instanceof O&&(_=l.interactive_parser.lexer_thread.state,s=_.line_ctr.char_pos),!n(l))throw l;l instanceof O&&s===_.line_ctr.char_pos&&_.line_ctr.feed(_.text.slice(s,s+1));try{return l.interactive_parser.resume_parse()}catch(a){if(a instanceof A){if(l instanceof A&&l.token.type===a.token.type&&a.token.type==="$END"&&l.interactive_parser.eq(a.interactive_parser))throw a;l=a}else if(a instanceof O)l=a;else throw a}}}else throw l}}}class Dt{constructor(t,r,n){this.parse_table=t,this.start_state=this.parse_table.start_states[n],this.end_state=this.parse_table.end_states[n],this.states=this.parse_table.states,this.callbacks=r,this.start=n}}class he{constructor(t,r,n=null,s=null){this.parse_conf=t,this.lexer=r,this.state_stack=n||[this.parse_conf.start_state],this.value_stack=s||[]}get position(){return d(this.state_stack)}eq(t){return t instanceof he?this.state_stack.length===t.state_stack.length&&this.position===t.position:D}copy(){return w(this)}feed_token(t,r=!1){let n,s,_,l,a,p,o,c,g,v,x=this.state_stack,S=this.value_stack,q=this.parse_conf.states,Me=this.parse_conf.end_state,G=this.parse_conf.callbacks;for(;;){if(g=d(x),t.type in q[g])[s,_]=q[g][t.type];else throw l=new Set(J(q[g]).filter(Z=>ve(Z)).map(Z=>Z)),new A({token:t,expected:l,state:this,interactive_parser:null});if(s===pe){x.push(_),S.push(t.type in G?G[t.type](t):t);return}else if(p=_,c=p.expansion.length,c?(o=S.slice(-c),x.splice(-c),S.splice(-c)):o=[],v=G.get(p)(o),[n,a]=q[d(x)][p.origin.name],x.push(a),S.push(v),r&&d(x)===Me)return d(S)}}}class ze{constructor(t,r,n=!1){this.parse_table=t,this.callbacks=r,this.debug=n}parse({lexer:t,start:r,value_stack:n=null,state_stack:s=null,start_interactive:_=!1}={}){let l=new Dt(this.parse_table,this.callbacks,r),a=new he(l,t,s,n);return _?new R(this,a,a.lexer):this.parse_from_state(a)}parse_from_state(t){let r,n;try{n=null;for(n of t.lexer.lex(t))t.feed_token(n);return r=n?h.new_borrow_pos("$END","",n):new h("$END","",0,1,1),t.feed_token(r,!0)}catch(s){if(s instanceof N){try{s.interactive_parser=new R(this,t,t.lexer)}catch(_){if(!(_ instanceof ReferenceError))throw _}throw s}else if(s instanceof Error){if(this.debug){console.log(""),console.log("STATE STACK DUMP"),console.log("----------------");for(const[_,l]of I(t.state_stack))console.log(u("%d)",_),l);console.log("")}throw s}else throw s}}}class R{constructor(t,r,n){this.parser=t,this.parser_state=r,this.lexer_thread=n,this.result=null}feed_token(t){return this.parser_state.feed_token(t,t.type==="$END")}*iter_parse(){for(const t of this.lexer_thread.lex(this.parser_state))yield t,this.result=this.feed_token(t)}exhaust_lexer(){return[...this.iter_parse()]}feed_eof(t=null){let r=t!==null?h.new_borrow_pos("$END","",t):new h("$END","",0,1,1);return this.feed_token(r)}copy(){return w(this)}eq(t){return t instanceof R?this.parser_state===t.parser_state&&this.lexer_thread===t.lexer_thread:!1}as_immutable(){let t=w(this);return new Le(t.parser,t.parser_state,t.lexer_thread)}pretty(){let t=["Parser choices:"];for(const[r,n]of f(this.choices()))t.push(u(" - %s -> %r",r,n));return t.push(u("stack size: %s",this.parser_state.state_stack.length)),t.join(`
|
|
20
|
+
`)}choices(){return this.parser_state.parse_conf.parse_table.states[this.parser_state.position]}accepts(){let t,r=new Set;for(const n of this.choices())if(ve(n)){t=w(this);let s=null;try{t.feed_token(new h(n,""))}catch(_){if(s=_,!(_ instanceof A))throw _}s||r.add(n)}return r}resume_parse(){return this.parser.parse_from_state(this.parser_state)}}class Le extends R{result=null;feed_token(t){let r=w(this);return r.result=R.feed_token(r,t),r}exhaust_lexer(){let t=this.as_mutable();return t.exhaust_lexer(),t.as_immutable()}as_mutable(){let t=w(this);return new R(t.parser,t.parser_state,t.lexer_thread)}}class qe{constructor(t){this.name=t}repr(){return this.toString()}}var pe=new qe("Shift"),je=new qe("Reduce");class It{constructor(t,r,n){this.states=t,this.start_states=r,this.end_states=n}serialize(t){let r=new Enumerator,n=Object.fromEntries(f(this.states).map(([s,_])=>[s,Object.fromEntries(f(_).map(([l,[a,p]])=>[we(r,l),a===je?[1,p.serialize(t)]:[0,p]]))]));return{tokens:r.reversed(),states:n,start_states:this.start_states,end_states:this.end_states}}static deserialize(t,r){const n=this;let s=t.tokens,_=Object.fromEntries(f(t.states).map(([l,a])=>[l,Object.fromEntries(f(a).map(([p,[o,c]])=>[s[p],o===1?[je,P.deserialize(c,r)]:[pe,c]]))]));return new n(_,t.start_states,t.end_states)}}class zt extends It{static from_ParseTable(t){const r=this;let n=[...t.states],s=Object.fromEntries(I(n).map(([p,o])=>[o,p])),_={};for(let[p,o]of f(t.states))o=Object.fromEntries(f(o).map(([c,g])=>[c,g[0]===pe?[g[0],s[g[1]]]:g])),_[s[p]]=o;let l=Object.fromEntries(f(t.start_states).map(([p,o])=>[p,s[o]])),a=Object.fromEntries(f(t.end_states).map(([p,o])=>[p,s[o]]));return new r(_,l,a)}}function Lt(i){if(i&&i.__future_interface__)return i;{class t extends ${constructor(n){super(),this.lexer=i(n)}lex(n,s){return this.lexer.lex(n.text)}}return t}}function qt(i,t,r,n,s){let _=Se.deserialize(i.parser_conf,t),l=Ie.deserialize(i.parser,t,n,s.debug);return _.callbacks=n,new jt({lexer_conf:r,parser_conf:_,options:s,parser:l})}var Ce={};class jt extends y{static get __serialize_fields__(){return["lexer_conf","parser_conf","parser"]}constructor({lexer_conf:t,parser_conf:r,options:n,parser:s=null}={}){super();let _,l;this.parser_conf=r,this.lexer_conf=t,this.options=n,s?this.parser=s:(l=we(Ce,r.parser_type),this.parser=l(t,r,n));let a=t.lexer_type;if(this.skip_lexer=!1,["dynamic","dynamic_complete"].includes(a)){this.skip_lexer=!0;return}const p={basic:Qt,contextual:Ut};a in p?(_=p[a],this.lexer=_(t,this.parser,t.postlex,n)):this.lexer=Lt(a)(t),t.postlex&&(this.lexer=new Ft(this.lexer,t.postlex))}_verify_start(t=null){let r;if(t===null){if(r=this.parser_conf.start,r.length>1)throw new T("Lark initialized with more than 1 possible start rule. Must specify which start rule to parse",r);[t]=r}else if(!this.parser_conf.start.includes(t))throw new T(u("Unknown start rule %s. Must be one of %r",t,this.parser_conf.start));return t}_make_lexer_thread(t){return this.skip_lexer?t:Ae.from_text(this.lexer,t)}parse(t,r=null,n=null){let s=this._verify_start(r),_=n===null?{}:{on_error:n},l=this._make_lexer_thread(t);return this.parser.parse({lexer:l,start:s,..._})}parse_interactive(t=null,r=null){let n=this._verify_start(r);if(this.parser_conf.parser_type!=="lalr")throw new T("parse_interactive() currently only works with parser='lalr' ");let s=this._make_lexer_thread(t);return this.parser.parse_interactive(s,n)}}function Ct(i,t){let r;ee(i,["lalr","earley","cyk"]),typeof t!="object"&&(r={lalr:["basic","contextual"],earley:["basic","dynamic","dynamic_complete"],cyk:["basic"]}[i],ee(t,r,u("Parser %r does not support lexer %%r, expected one of %%s",i)))}function Bt(i,t){let r,n={};for(const s of t)r=i&&i[s.name]||null,r!==null&&(n[s.name]=r);return n}class Ft{constructor(t,r){this.lexer=t,this.postlexer=r}lex(t,r){let n=this.lexer.lex(t,r);return this.postlexer.process(n)}}function Qt(i,t,r,n){return new W(i)}function Ut(i,t,r,n){let s=Object.fromEntries(f(t._parse_table.states).map(([l,a])=>[l,[...J(a)]])),_=r?r.always_accept:[];return new yt({conf:i,states:s,always_accept:_})}function Mt(i,t,r=null){let n=r?r.debug:!1;return new Ie({parser_conf:t,debug:n})}Ce.lalr=Mt;class Be extends xe{process(t){return t}always_accept=[]}class $t extends y{OPTIONS_DOC='\n **=== General Options ===**\n\n start\n The start symbol. Either a string, or a list of strings for multiple possible starts (Default: "start")\n debug\n Display debug information and extra warnings. Use only when debugging (Default: ``False``)\n When used with Earley, it generates a forest graph as "sppf.png", if \'dot\' is installed.\n transformer\n Applies the transformer to every parse tree (equivalent to applying it after the parse, but faster)\n propagate_positions\n Propagates (line, column, end_line, end_column) attributes into all tree branches.\n Accepts ``False``, ``True``, or a callable, which will filter which nodes to ignore when propagating.\n maybe_placeholders\n When ``True``, the ``[]`` operator returns ``None`` when not matched.\n When ``False``, ``[]`` behaves like the ``?`` operator, and returns no value at all.\n (default= ``True``)\n cache\n Cache the results of the Lark grammar analysis, for x2 to x3 faster loading. LALR only for now.\n\n - When ``False``, does nothing (default)\n - When ``True``, caches to a temporary file in the local directory\n - When given a string, caches to the path pointed by the string\n regex\n When True, uses the ``regex`` module instead of the stdlib ``re``.\n g_regex_flags\n Flags that are applied to all terminals (both regex and strings)\n keep_all_tokens\n Prevent the tree builder from automagically removing "punctuation" tokens (Default: ``False``)\n tree_class\n Lark will produce trees comprised of instances of this class instead of the default ``lark.Tree``.\n\n **=== Algorithm Options ===**\n\n parser\n Decides which parser engine to use. Accepts "earley" or "lalr". (Default: "earley").\n (there is also a "cyk" option for legacy)\n lexer\n Decides whether or not to use a lexer stage\n\n - "auto" (default): Choose for me based on the parser\n - "basic": Use a basic lexer\n - "contextual": Stronger lexer (only works with parser="lalr")\n - "dynamic": Flexible and powerful (only with parser="earley")\n - "dynamic_complete": Same as dynamic, but tries *every* variation of tokenizing possible.\n ambiguity\n Decides how to handle ambiguity in the parse. Only relevant if parser="earley"\n\n - "resolve": The parser will automatically choose the simplest derivation\n (it chooses consistently: greedy for tokens, non-greedy for rules)\n - "explicit": The parser will return all derivations wrapped in "_ambig" tree nodes (i.e. a forest).\n - "forest": The parser will return the root of the shared packed parse forest.\n\n **=== Misc. / Domain Specific Options ===**\n\n postlex\n Lexer post-processing (Default: ``None``) Only works with the basic and contextual lexers.\n priority\n How priorities should be evaluated - "auto", ``None``, "normal", "invert" (Default: "auto")\n lexer_callbacks\n Dictionary of callbacks for the lexer. May alter tokens during lexing. Use with caution.\n use_bytes\n Accept an input of type ``bytes`` instead of ``str``.\n edit_terminals\n A callback for editing the terminals before parse.\n import_paths\n A List of either paths or loader functions to specify from where grammars are imported\n source_path\n Override the source of from where the grammar was loaded. Useful for relative imports and unconventional grammar loading\n **=== End of Options ===**\n ';_defaults={debug:!1,keep_all_tokens:!1,tree_class:null,cache:!1,postlex:null,parser:"earley",lexer:"auto",transformer:null,start:"start",priority:"auto",ambiguity:"auto",regex:!1,propagate_positions:!1,lexer_callbacks:{},maybe_placeholders:!0,edit_terminals:null,g_regex_flags:"",use_bytes:!1,import_paths:[],source_path:null,_plugins:null};constructor(t){super();let r,n=Te(t),s=this;for(const[_,l]of f(this._defaults))_ in n?(r=Ge(n,_),typeof l=="boolean"&&!["cache","use_bytes","propagate_positions"].includes(_)&&(r=Ne(r))):r=l,s[_]=r;if(typeof s.start=="string"&&(s.start=[s.start]),this.options=s,ee(this.parser,["earley","lalr","cyk",null]),this.parser==="earley"&&this.transformer)throw new T("Cannot specify an embedded transformer when using the Earley algorithm. Please use your transformer on the resulting parse tree, or use a different algorithm (i.e. LALR)");if(Object.keys(n).length)throw new T(u("Unknown options: %s",J(n)))}serialize(t){return this.options}static deserialize(t,r){const n=this;return new n(t)}}class Fe extends y{static get __serialize_fields__(){return["parser","rules","options"]}_build_lexer(t=!1){let r=this.lexer_conf;return t&&(r=w(r),r.ignore=[]),new W(r)}_prepare_callbacks(){this._callbacks=new Map,this.options.ambiguity!=="forest"&&(this._parse_tree_builder=new St(this.rules,this.options.tree_class||Ze(m),this.options.propagate_positions,this.options.parser!=="lalr"&&this.options.ambiguity==="explicit",this.options.maybe_placeholders),this._callbacks=this._parse_tree_builder.create_callback(this.options.transformer)),be(this._callbacks,Bt(this.options.transformer,this.terminals))}_deserialize_lexer_conf(t,r,n){let s=Pe.deserialize(t.lexer_conf,r);return s.callbacks=n.lexer_callbacks||{},s.re_module=n.regex?regex:de,s.use_bytes=n.use_bytes,s.g_regex_flags=n.g_regex_flags||"",s.skip_validation=!0,s.postlex=n.postlex,s}_load({f:t,...r}={}){let n;K(t)?n=t:n=pickle.load(t);let s=n.memo,_=n.data,l=nt.deserialize(s,{Rule:P,TerminalDef:M},{}),a=Te(_.options);return be(a,r),this.options=$t.deserialize(a,l),this.rules=_.rules.map(p=>P.deserialize(p,l)),this.source_path="<deserialized>",Ct(this.options.parser,this.options.lexer),this.lexer_conf=this._deserialize_lexer_conf(_.parser,l,this.options),this.terminals=this.lexer_conf.terminals,this._prepare_callbacks(),this._terminals_dict=Object.fromEntries(this.terminals.map(p=>[p.name,p])),this.parser=qt(_.parser,l,this.lexer_conf,this._callbacks,this.options),this}static _load_from_dict({data:t,memo:r,...n}={}){return V(this)._load({f:{data:t,memo:r},...n})}repr(){return u("Lark(open(%r), parser=%r, lexer=%r, ...)",this.source_path,this.options.parser,this.options.lexer)}lex(t,r=!1){let n;!("lexer"in this)||r?n=this._build_lexer(r):n=this.lexer;let s=Ae.from_text(n,t).lex(null);return this.options.postlex?this.options.postlex.process(s):s}get_terminal(t){return this._terminals_dict[t]}parse_interactive(t=null,r=null){return this.parser.parse_interactive({unknown_param_0:t,start:r})}parse(t,r=null,n=null){return this.parser.parse(t,r,n)}}class Qe extends k{}class Ue extends Be{constructor(){super(),this.paren_level=0,this.indent_level=[0]}*handle_NL(t){if(this.paren_level>0)return;yield t;let r=X(t.value,`
|
|
21
|
+
`,1)[1],n=Y(r," ")+Y(r," ")*this.tab_len;if(n>d(this.indent_level))this.indent_level.push(n),yield h.new_borrow_pos(this.INDENT_type,r,t);else{for(;n<d(this.indent_level);)this.indent_level.pop(),yield h.new_borrow_pos(this.DEDENT_type,r,t);if(n!==d(this.indent_level))throw new Qe(u("Unexpected dedent to column %s. Expected dedent to %s",n,d(this.indent_level)))}}*_process(t){for(const r of t)r.type===this.NL_type?yield*this.handle_NL(r):yield r,this.OPEN_PAREN_types.includes(r.type)?this.paren_level+=1:this.CLOSE_PAREN_types.includes(r.type)&&(this.paren_level-=1);for(;this.indent_level.length>1;)this.indent_level.pop(),yield new h(this.DEDENT_type,"")}process(t){return this.paren_level=0,this.indent_level=[0],this._process(t)}get always_accept(){return[this.NL_type]}get NL_type(){throw new NotImplementedError}get OPEN_PAREN_types(){throw new NotImplementedError}get CLOSE_PAREN_types(){throw new NotImplementedError}get INDENT_type(){throw new NotImplementedError}get DEDENT_type(){throw new NotImplementedError}get tab_len(){throw new NotImplementedError}}class Wt extends Ue{static get NL_type(){return"_NEWLINE"}get NL_type(){return this.constructor.NL_type}static get OPEN_PAREN_types(){return["LPAR","LSQB","LBRACE"]}get OPEN_PAREN_types(){return this.constructor.OPEN_PAREN_types}static get CLOSE_PAREN_types(){return["RPAR","RSQB","RBRACE"]}get CLOSE_PAREN_types(){return this.constructor.CLOSE_PAREN_types}static get INDENT_type(){return"_INDENT"}get INDENT_type(){return this.constructor.INDENT_type}static get DEDENT_type(){return"_DEDENT"}get DEDENT_type(){return this.constructor.DEDENT_type}static get tab_len(){return 8}get tab_len(){return this.constructor.tab_len}}const Gt={Terminal:se,NonTerminal:ie,RuleOptions:U,PatternStr:le,PatternRE:ae,TerminalDef:M};var Zt={LarkError:k,ConfigurationError:T,GrammarError:F,ParseError:et,LexError:z,UnexpectedInput:N,UnexpectedEOF:tt,UnexpectedCharacters:O,UnexpectedToken:A,VisitError:te,Meta:Ee,Tree:m,Discard:j,Transformer:L,Transformer_InPlace:Oe,Transformer_NonRecursive:st,Transformer_InPlaceRecursive:it,VisitorBase:re,Visitor:_t,Visitor_Recursive:lt,Interpreter:at,Symbol:ne,Terminal:se,NonTerminal:ie,RuleOptions:U,Rule:P,Pattern:_e,PatternStr:le,PatternRE:ae,TerminalDef:M,Token:h,Lexer:$,LexerConf:Pe,ParserConf:Se,InteractiveParser:R,ImmutableInteractiveParser:Le,PostLex:Be,Lark:Fe,DedentError:Qe,Indenter:Ue,PythonIndenter:Wt,get_parser:$e},Jt={parser:{lexer_conf:{terminals:[{"@":0},{"@":1},{"@":2},{"@":3},{"@":4},{"@":5},{"@":6},{"@":7},{"@":8},{"@":9},{"@":10},{"@":11},{"@":12},{"@":13},{"@":14},{"@":15},{"@":16},{"@":17},{"@":18},{"@":19}],ignore:["WS"],g_regex_flags:0,use_bytes:!1,lexer_type:"contextual",__type__:"LexerConf"},parser_conf:{rules:[{"@":20},{"@":21},{"@":22},{"@":23},{"@":24},{"@":25},{"@":26},{"@":27},{"@":28},{"@":29},{"@":30},{"@":31},{"@":32},{"@":33},{"@":34},{"@":35},{"@":36},{"@":37},{"@":38},{"@":39},{"@":40},{"@":41},{"@":42},{"@":43},{"@":44},{"@":45},{"@":46},{"@":47},{"@":48}],start:["start"],parser_type:"lalr",__type__:"ParserConf"},parser:{tokens:{0:"STRING",1:"IDENTIFIER",2:"INT",3:"choice_ref",4:"$END",5:"RPAR",6:"LSQB",7:"RSQB",8:"question_id",9:"matrix_statement_id",10:"CONJUNCTION",11:"DOT",12:"top_level_expr",13:"LPAR",14:"OPERATOR",15:"TRUE",16:"__ANON_1",17:"__ANON_0",18:"__ANON_4",19:"question_choice_selected_value_comparison",20:"bool_const",21:"condition",22:"__ANON_5",23:"__ANON_3",24:"question_choice_selected",25:"selected_count_comparison",26:"FALSE",27:"question_choice_text_comparison",28:"NEGATION",29:"start",30:"__ANON_2",31:"bool_expr",32:"question_choice_text_comparison_case_insensitive",33:"choice_selection_count_comparison"},states:{0:{0:[0,25]},1:{1:[0,28],2:[0,23],3:[0,22]},2:{2:[0,21]},3:{2:[0,23],1:[0,28],3:[0,29]},4:{4:[1,{"@":44}],5:[1,{"@":44}]},5:{6:[0,19]},6:{2:[0,37]},7:{2:[0,23],3:[0,75],1:[0,28]},8:{5:[0,43]},9:{2:[0,70]},10:{5:[0,81]},11:{3:[0,50],2:[0,23],1:[0,28]},12:{7:[0,10]},13:{0:[0,34]},14:{2:[0,67]},15:{5:[1,{"@":23}],6:[1,{"@":23}]},16:{8:[0,46],9:[0,39],1:[0,82]},17:{10:[1,{"@":25}],4:[1,{"@":25}],5:[1,{"@":25}]},18:{6:[0,11],11:[0,74]},19:{2:[0,23],3:[0,53],1:[0,28]},20:{10:[0,24],4:[1,{"@":45}]},21:{10:[1,{"@":33}],4:[1,{"@":33}],5:[1,{"@":33}]},22:{7:[0,61]},23:{7:[1,{"@":20}]},24:{12:[0,77],13:[0,38]},25:{10:[1,{"@":31}],4:[1,{"@":31}],5:[1,{"@":31}]},26:{10:[1,{"@":24}],4:[1,{"@":24}],5:[1,{"@":24}]},27:{14:[0,6]},28:{7:[1,{"@":21}]},29:{7:[0,45]},30:{15:[0,33],16:[0,16],17:[0,31],18:[0,78],19:[0,41],20:[0,76],21:[0,52],22:[0,48],23:[0,72],24:[0,64],12:[0,84],25:[0,57],26:[0,36],27:[0,40],13:[0,38],28:[0,59],29:[0,42],30:[0,47],31:[0,68],32:[0,35],33:[0,54]},31:{8:[0,66],1:[0,82],9:[0,65]},32:{7:[0,8]},33:{10:[1,{"@":34}],4:[1,{"@":34}],5:[1,{"@":34}]},34:{10:[1,{"@":30}],4:[1,{"@":30}],5:[1,{"@":30}]},35:{10:[1,{"@":40}],4:[1,{"@":40}],5:[1,{"@":40}]},36:{10:[1,{"@":35}],4:[1,{"@":35}],5:[1,{"@":35}]},37:{10:[1,{"@":32}],4:[1,{"@":32}],5:[1,{"@":32}]},38:{15:[0,33],16:[0,16],17:[0,31],31:[0,62],18:[0,78],19:[0,41],20:[0,76],21:[0,52],22:[0,48],23:[0,72],24:[0,64],25:[0,57],26:[0,36],27:[0,40],28:[0,59],30:[0,47],32:[0,35],33:[0,54]},39:{5:[0,56]},40:{10:[1,{"@":39}],4:[1,{"@":39}],5:[1,{"@":39}]},41:{10:[1,{"@":38}],4:[1,{"@":38}],5:[1,{"@":38}]},42:{},43:{10:[1,{"@":27}],4:[1,{"@":27}],5:[1,{"@":27}]},44:{5:[0,17]},45:{5:[0,79]},46:{11:[0,74],5:[0,51]},47:{8:[0,71],1:[0,82]},48:{1:[0,82],8:[0,60]},49:{5:[0,26]},50:{7:[0,49]},51:{14:[0,14]},52:{10:[0,69],4:[1,{"@":43}],5:[1,{"@":43}]},53:{7:[0,44]},54:{10:[1,{"@":42}],4:[1,{"@":42}],5:[1,{"@":42}]},55:{2:[0,23],1:[0,28],3:[0,12]},56:{14:[0,9]},57:{10:[1,{"@":41}],4:[1,{"@":41}],5:[1,{"@":41}]},58:{6:[0,1]},59:{17:[0,85]},60:{6:[0,3]},61:{5:[0,73]},62:{5:[0,20]},63:{5:[0,80]},64:{10:[1,{"@":37}],4:[1,{"@":37}],5:[1,{"@":37}]},65:{6:[0,83]},66:{11:[0,74],6:[0,55]},67:{10:[1,{"@":28}],4:[1,{"@":28}],5:[1,{"@":28}]},68:{4:[1,{"@":48}]},69:{15:[0,33],16:[0,16],17:[0,31],18:[0,78],19:[0,41],20:[0,76],21:[0,52],22:[0,48],23:[0,72],24:[0,64],25:[0,57],26:[0,36],27:[0,40],28:[0,59],30:[0,47],32:[0,35],31:[0,4],33:[0,54]},70:{10:[1,{"@":29}],4:[1,{"@":29}],5:[1,{"@":29}]},71:{6:[0,7]},72:{8:[0,58],1:[0,82]},73:{14:[0,0]},74:{1:[0,15]},75:{7:[0,63]},76:{10:[1,{"@":36}],4:[1,{"@":36}],5:[1,{"@":36}]},77:{4:[1,{"@":46}]},78:{1:[0,82],8:[0,86]},79:{14:[0,2]},80:{14:[0,13]},81:{10:[1,{"@":26}],4:[1,{"@":26}],5:[1,{"@":26}]},82:{5:[1,{"@":22}],11:[1,{"@":22}],6:[1,{"@":22}]},83:{3:[0,32],2:[0,23],1:[0,28]},84:{4:[1,{"@":47}]},85:{8:[0,18],9:[0,5],1:[0,82]},86:{5:[0,27]}},start_states:{start:30},end_states:{start:42}},__type__:"ParsingFrontend"},rules:[{"@":20},{"@":21},{"@":22},{"@":23},{"@":24},{"@":25},{"@":26},{"@":27},{"@":28},{"@":29},{"@":30},{"@":31},{"@":32},{"@":33},{"@":34},{"@":35},{"@":36},{"@":37},{"@":38},{"@":39},{"@":40},{"@":41},{"@":42},{"@":43},{"@":44},{"@":45},{"@":46},{"@":47},{"@":48}],options:{debug:!1,keep_all_tokens:!1,tree_class:null,cache:!1,postlex:null,parser:"lalr",lexer:"contextual",transformer:null,start:["start"],priority:"normal",ambiguity:"auto",regex:!1,propagate_positions:!1,lexer_callbacks:{},maybe_placeholders:!1,edit_terminals:null,g_regex_flags:0,use_bytes:!1,import_paths:[],source_path:null,_plugins:{}},__type__:"Lark"},Vt={0:{name:"WS",pattern:{value:`(?:[ \f\r
|
|
22
|
+
])+`,flags:[],raw:null,_width:[1,4294967295],__type__:"PatternRE"},priority:0,__type__:"TerminalDef"},1:{name:"IDENTIFIER",pattern:{value:"[a-zA-Z][a-zA-Z0-9_]*[a-zA-Z0-9]",flags:[],raw:"/[a-zA-Z][a-zA-Z0-9_]*[a-zA-Z0-9]/",_width:[2,4294967295],__type__:"PatternRE"},priority:0,__type__:"TerminalDef"},2:{name:"INT",pattern:{value:"-?[0-9]+",flags:[],raw:"/-?[0-9]+/",_width:[1,4294967295],__type__:"PatternRE"},priority:0,__type__:"TerminalDef"},3:{name:"STRING",pattern:{value:`(?:'[^\\']*'|"[^"]*")`,flags:[],raw:null,_width:[2,4294967295],__type__:"PatternRE"},priority:0,__type__:"TerminalDef"},4:{name:"OPERATOR",pattern:{value:"(?:regex_matches|not_contains|contains|==|!=|<=|>=|<|>)",flags:[],raw:null,_width:[1,13],__type__:"PatternRE"},priority:0,__type__:"TerminalDef"},5:{name:"CONJUNCTION",pattern:{value:"(?:and|or)",flags:[],raw:null,_width:[2,3],__type__:"PatternRE"},priority:0,__type__:"TerminalDef"},6:{name:"NEGATION",pattern:{value:"!",flags:[],raw:'"!"',__type__:"PatternStr"},priority:0,__type__:"TerminalDef"},7:{name:"TRUE",pattern:{value:"true",flags:[],raw:'"true"',__type__:"PatternStr"},priority:0,__type__:"TerminalDef"},8:{name:"FALSE",pattern:{value:"false",flags:[],raw:'"false"',__type__:"PatternStr"},priority:0,__type__:"TerminalDef"},9:{name:"DOT",pattern:{value:".",flags:[],raw:'"."',__type__:"PatternStr"},priority:0,__type__:"TerminalDef"},10:{name:"__ANON_0",pattern:{value:"selected(",flags:[],raw:'"selected("',__type__:"PatternStr"},priority:0,__type__:"TerminalDef"},11:{name:"LSQB",pattern:{value:"[",flags:[],raw:'"["',__type__:"PatternStr"},priority:0,__type__:"TerminalDef"},12:{name:"RSQB",pattern:{value:"]",flags:[],raw:'"]"',__type__:"PatternStr"},priority:0,__type__:"TerminalDef"},13:{name:"RPAR",pattern:{value:")",flags:[],raw:'")"',__type__:"PatternStr"},priority:0,__type__:"TerminalDef"},14:{name:"__ANON_1",pattern:{value:"selected_value(",flags:[],raw:'"selected_value("',__type__:"PatternStr"},priority:0,__type__:"TerminalDef"},15:{name:"__ANON_2",pattern:{value:"text(",flags:[],raw:'"text("',__type__:"PatternStr"},priority:0,__type__:"TerminalDef"},16:{name:"__ANON_3",pattern:{value:"text_ignore_case(",flags:[],raw:'"text_ignore_case("',__type__:"PatternStr"},priority:0,__type__:"TerminalDef"},17:{name:"__ANON_4",pattern:{value:"count_selected(",flags:[],raw:'"count_selected("',__type__:"PatternStr"},priority:0,__type__:"TerminalDef"},18:{name:"__ANON_5",pattern:{value:"count_choice_selections(",flags:[],raw:'"count_choice_selections("',__type__:"PatternStr"},priority:0,__type__:"TerminalDef"},19:{name:"LPAR",pattern:{value:"(",flags:[],raw:'"("',__type__:"PatternStr"},priority:0,__type__:"TerminalDef"},20:{origin:{name:"choice_ref",__type__:"NonTerminal"},expansion:[{name:"INT",filter_out:!1,__type__:"Terminal"}],order:0,alias:null,options:{keep_all_tokens:!1,expand1:!1,priority:null,template_source:null,empty_indices:[],__type__:"RuleOptions"},__type__:"Rule"},21:{origin:{name:"choice_ref",__type__:"NonTerminal"},expansion:[{name:"IDENTIFIER",filter_out:!1,__type__:"Terminal"}],order:1,alias:null,options:{keep_all_tokens:!1,expand1:!1,priority:null,template_source:null,empty_indices:[],__type__:"RuleOptions"},__type__:"Rule"},22:{origin:{name:"question_id",__type__:"NonTerminal"},expansion:[{name:"IDENTIFIER",filter_out:!1,__type__:"Terminal"}],order:0,alias:null,options:{keep_all_tokens:!1,expand1:!1,priority:null,template_source:null,empty_indices:[],__type__:"RuleOptions"},__type__:"Rule"},23:{origin:{name:"matrix_statement_id",__type__:"NonTerminal"},expansion:[{name:"question_id",__type__:"NonTerminal"},{name:"DOT",filter_out:!0,__type__:"Terminal"},{name:"IDENTIFIER",filter_out:!1,__type__:"Terminal"}],order:0,alias:null,options:{keep_all_tokens:!1,expand1:!1,priority:null,template_source:null,empty_indices:[],__type__:"RuleOptions"},__type__:"Rule"},24:{origin:{name:"question_choice_selected",__type__:"NonTerminal"},expansion:[{name:"NEGATION",filter_out:!1,__type__:"Terminal"},{name:"__ANON_0",filter_out:!0,__type__:"Terminal"},{name:"question_id",__type__:"NonTerminal"},{name:"LSQB",filter_out:!0,__type__:"Terminal"},{name:"choice_ref",__type__:"NonTerminal"},{name:"RSQB",filter_out:!0,__type__:"Terminal"},{name:"RPAR",filter_out:!0,__type__:"Terminal"}],order:0,alias:null,options:{keep_all_tokens:!1,expand1:!1,priority:null,template_source:null,empty_indices:[],__type__:"RuleOptions"},__type__:"Rule"},25:{origin:{name:"question_choice_selected",__type__:"NonTerminal"},expansion:[{name:"NEGATION",filter_out:!1,__type__:"Terminal"},{name:"__ANON_0",filter_out:!0,__type__:"Terminal"},{name:"matrix_statement_id",__type__:"NonTerminal"},{name:"LSQB",filter_out:!0,__type__:"Terminal"},{name:"choice_ref",__type__:"NonTerminal"},{name:"RSQB",filter_out:!0,__type__:"Terminal"},{name:"RPAR",filter_out:!0,__type__:"Terminal"}],order:1,alias:null,options:{keep_all_tokens:!1,expand1:!1,priority:null,template_source:null,empty_indices:[],__type__:"RuleOptions"},__type__:"Rule"},26:{origin:{name:"question_choice_selected",__type__:"NonTerminal"},expansion:[{name:"__ANON_0",filter_out:!0,__type__:"Terminal"},{name:"question_id",__type__:"NonTerminal"},{name:"LSQB",filter_out:!0,__type__:"Terminal"},{name:"choice_ref",__type__:"NonTerminal"},{name:"RSQB",filter_out:!0,__type__:"Terminal"},{name:"RPAR",filter_out:!0,__type__:"Terminal"}],order:2,alias:null,options:{keep_all_tokens:!1,expand1:!1,priority:null,template_source:null,empty_indices:[],__type__:"RuleOptions"},__type__:"Rule"},27:{origin:{name:"question_choice_selected",__type__:"NonTerminal"},expansion:[{name:"__ANON_0",filter_out:!0,__type__:"Terminal"},{name:"matrix_statement_id",__type__:"NonTerminal"},{name:"LSQB",filter_out:!0,__type__:"Terminal"},{name:"choice_ref",__type__:"NonTerminal"},{name:"RSQB",filter_out:!0,__type__:"Terminal"},{name:"RPAR",filter_out:!0,__type__:"Terminal"}],order:3,alias:null,options:{keep_all_tokens:!1,expand1:!1,priority:null,template_source:null,empty_indices:[],__type__:"RuleOptions"},__type__:"Rule"},28:{origin:{name:"question_choice_selected_value_comparison",__type__:"NonTerminal"},expansion:[{name:"__ANON_1",filter_out:!0,__type__:"Terminal"},{name:"question_id",__type__:"NonTerminal"},{name:"RPAR",filter_out:!0,__type__:"Terminal"},{name:"OPERATOR",filter_out:!1,__type__:"Terminal"},{name:"INT",filter_out:!1,__type__:"Terminal"}],order:0,alias:null,options:{keep_all_tokens:!1,expand1:!1,priority:null,template_source:null,empty_indices:[],__type__:"RuleOptions"},__type__:"Rule"},29:{origin:{name:"question_choice_selected_value_comparison",__type__:"NonTerminal"},expansion:[{name:"__ANON_1",filter_out:!0,__type__:"Terminal"},{name:"matrix_statement_id",__type__:"NonTerminal"},{name:"RPAR",filter_out:!0,__type__:"Terminal"},{name:"OPERATOR",filter_out:!1,__type__:"Terminal"},{name:"INT",filter_out:!1,__type__:"Terminal"}],order:1,alias:null,options:{keep_all_tokens:!1,expand1:!1,priority:null,template_source:null,empty_indices:[],__type__:"RuleOptions"},__type__:"Rule"},30:{origin:{name:"question_choice_text_comparison",__type__:"NonTerminal"},expansion:[{name:"__ANON_2",filter_out:!0,__type__:"Terminal"},{name:"question_id",__type__:"NonTerminal"},{name:"LSQB",filter_out:!0,__type__:"Terminal"},{name:"choice_ref",__type__:"NonTerminal"},{name:"RSQB",filter_out:!0,__type__:"Terminal"},{name:"RPAR",filter_out:!0,__type__:"Terminal"},{name:"OPERATOR",filter_out:!1,__type__:"Terminal"},{name:"STRING",filter_out:!1,__type__:"Terminal"}],order:0,alias:null,options:{keep_all_tokens:!1,expand1:!1,priority:null,template_source:null,empty_indices:[],__type__:"RuleOptions"},__type__:"Rule"},31:{origin:{name:"question_choice_text_comparison_case_insensitive",__type__:"NonTerminal"},expansion:[{name:"__ANON_3",filter_out:!0,__type__:"Terminal"},{name:"question_id",__type__:"NonTerminal"},{name:"LSQB",filter_out:!0,__type__:"Terminal"},{name:"choice_ref",__type__:"NonTerminal"},{name:"RSQB",filter_out:!0,__type__:"Terminal"},{name:"RPAR",filter_out:!0,__type__:"Terminal"},{name:"OPERATOR",filter_out:!1,__type__:"Terminal"},{name:"STRING",filter_out:!1,__type__:"Terminal"}],order:0,alias:null,options:{keep_all_tokens:!1,expand1:!1,priority:null,template_source:null,empty_indices:[],__type__:"RuleOptions"},__type__:"Rule"},32:{origin:{name:"selected_count_comparison",__type__:"NonTerminal"},expansion:[{name:"__ANON_4",filter_out:!0,__type__:"Terminal"},{name:"question_id",__type__:"NonTerminal"},{name:"RPAR",filter_out:!0,__type__:"Terminal"},{name:"OPERATOR",filter_out:!1,__type__:"Terminal"},{name:"INT",filter_out:!1,__type__:"Terminal"}],order:0,alias:null,options:{keep_all_tokens:!1,expand1:!1,priority:null,template_source:null,empty_indices:[],__type__:"RuleOptions"},__type__:"Rule"},33:{origin:{name:"choice_selection_count_comparison",__type__:"NonTerminal"},expansion:[{name:"__ANON_5",filter_out:!0,__type__:"Terminal"},{name:"question_id",__type__:"NonTerminal"},{name:"LSQB",filter_out:!0,__type__:"Terminal"},{name:"choice_ref",__type__:"NonTerminal"},{name:"RSQB",filter_out:!0,__type__:"Terminal"},{name:"RPAR",filter_out:!0,__type__:"Terminal"},{name:"OPERATOR",filter_out:!1,__type__:"Terminal"},{name:"INT",filter_out:!1,__type__:"Terminal"}],order:0,alias:null,options:{keep_all_tokens:!1,expand1:!1,priority:null,template_source:null,empty_indices:[],__type__:"RuleOptions"},__type__:"Rule"},34:{origin:{name:"bool_const",__type__:"NonTerminal"},expansion:[{name:"TRUE",filter_out:!1,__type__:"Terminal"}],order:0,alias:null,options:{keep_all_tokens:!1,expand1:!1,priority:null,template_source:null,empty_indices:[],__type__:"RuleOptions"},__type__:"Rule"},35:{origin:{name:"bool_const",__type__:"NonTerminal"},expansion:[{name:"FALSE",filter_out:!1,__type__:"Terminal"}],order:1,alias:null,options:{keep_all_tokens:!1,expand1:!1,priority:null,template_source:null,empty_indices:[],__type__:"RuleOptions"},__type__:"Rule"},36:{origin:{name:"condition",__type__:"NonTerminal"},expansion:[{name:"bool_const",__type__:"NonTerminal"}],order:0,alias:null,options:{keep_all_tokens:!1,expand1:!1,priority:null,template_source:null,empty_indices:[],__type__:"RuleOptions"},__type__:"Rule"},37:{origin:{name:"condition",__type__:"NonTerminal"},expansion:[{name:"question_choice_selected",__type__:"NonTerminal"}],order:1,alias:null,options:{keep_all_tokens:!1,expand1:!1,priority:null,template_source:null,empty_indices:[],__type__:"RuleOptions"},__type__:"Rule"},38:{origin:{name:"condition",__type__:"NonTerminal"},expansion:[{name:"question_choice_selected_value_comparison",__type__:"NonTerminal"}],order:2,alias:null,options:{keep_all_tokens:!1,expand1:!1,priority:null,template_source:null,empty_indices:[],__type__:"RuleOptions"},__type__:"Rule"},39:{origin:{name:"condition",__type__:"NonTerminal"},expansion:[{name:"question_choice_text_comparison",__type__:"NonTerminal"}],order:3,alias:null,options:{keep_all_tokens:!1,expand1:!1,priority:null,template_source:null,empty_indices:[],__type__:"RuleOptions"},__type__:"Rule"},40:{origin:{name:"condition",__type__:"NonTerminal"},expansion:[{name:"question_choice_text_comparison_case_insensitive",__type__:"NonTerminal"}],order:4,alias:null,options:{keep_all_tokens:!1,expand1:!1,priority:null,template_source:null,empty_indices:[],__type__:"RuleOptions"},__type__:"Rule"},41:{origin:{name:"condition",__type__:"NonTerminal"},expansion:[{name:"selected_count_comparison",__type__:"NonTerminal"}],order:5,alias:null,options:{keep_all_tokens:!1,expand1:!1,priority:null,template_source:null,empty_indices:[],__type__:"RuleOptions"},__type__:"Rule"},42:{origin:{name:"condition",__type__:"NonTerminal"},expansion:[{name:"choice_selection_count_comparison",__type__:"NonTerminal"}],order:6,alias:null,options:{keep_all_tokens:!1,expand1:!1,priority:null,template_source:null,empty_indices:[],__type__:"RuleOptions"},__type__:"Rule"},43:{origin:{name:"bool_expr",__type__:"NonTerminal"},expansion:[{name:"condition",__type__:"NonTerminal"}],order:0,alias:null,options:{keep_all_tokens:!1,expand1:!1,priority:null,template_source:null,empty_indices:[],__type__:"RuleOptions"},__type__:"Rule"},44:{origin:{name:"bool_expr",__type__:"NonTerminal"},expansion:[{name:"condition",__type__:"NonTerminal"},{name:"CONJUNCTION",filter_out:!1,__type__:"Terminal"},{name:"bool_expr",__type__:"NonTerminal"}],order:1,alias:null,options:{keep_all_tokens:!1,expand1:!1,priority:null,template_source:null,empty_indices:[],__type__:"RuleOptions"},__type__:"Rule"},45:{origin:{name:"top_level_expr",__type__:"NonTerminal"},expansion:[{name:"LPAR",filter_out:!0,__type__:"Terminal"},{name:"bool_expr",__type__:"NonTerminal"},{name:"RPAR",filter_out:!0,__type__:"Terminal"}],order:0,alias:null,options:{keep_all_tokens:!1,expand1:!1,priority:null,template_source:null,empty_indices:[],__type__:"RuleOptions"},__type__:"Rule"},46:{origin:{name:"top_level_expr",__type__:"NonTerminal"},expansion:[{name:"LPAR",filter_out:!0,__type__:"Terminal"},{name:"bool_expr",__type__:"NonTerminal"},{name:"RPAR",filter_out:!0,__type__:"Terminal"},{name:"CONJUNCTION",filter_out:!1,__type__:"Terminal"},{name:"top_level_expr",__type__:"NonTerminal"}],order:1,alias:null,options:{keep_all_tokens:!1,expand1:!1,priority:null,template_source:null,empty_indices:[],__type__:"RuleOptions"},__type__:"Rule"},47:{origin:{name:"start",__type__:"NonTerminal"},expansion:[{name:"top_level_expr",__type__:"NonTerminal"}],order:0,alias:null,options:{keep_all_tokens:!1,expand1:!1,priority:null,template_source:null,empty_indices:[],__type__:"RuleOptions"},__type__:"Rule"},48:{origin:{name:"start",__type__:"NonTerminal"},expansion:[{name:"bool_expr",__type__:"NonTerminal"}],order:1,alias:null,options:{keep_all_tokens:!1,expand1:!1,priority:null,template_source:null,empty_indices:[],__type__:"RuleOptions"},__type__:"Rule"}};exports.Token=h,exports.default=Zt;
|
|
23
|
+
//# sourceMappingURL=logic_parser.cjs.js.map
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e="surveyTemplate",t="http://json-schema.org/draft-07/schema",i="Survey Template",r="object",s={template:{type:"object",description:"Meta data about the survey template",properties:{id:{type:"string",description:"An id of the survey template. If there are multiple templates with the same id, they must have different versions.",format:"regex",pattern:"^[a-zA-Z][a-zA-Z0-9_-]*[a-zA-Z0-9]$",minLength:1},version:{type:"string",format:"regex",pattern:"^[0-9]+(\\.[0-9]+)?$",description:"A version of template"},name:{type:"string",description:"The display name of the survey template",minLength:1},description:{type:"string",description:"A longer description of the survey template"},owner:{type:"string",description:"The owner of the survey template",minLength:1}},required:["id","version","name","owner"],additionalProperties:!1},parameters:{type:"array",description:"Template parameters that can or must be set when creating a survey from this template. Parameters are referred to elsewhere in the survey using the ${p:<id>} construct and will get lazily in-place replaced.",items:{type:"object",properties:{id:{type:"string",description:"The id of the parameter",format:"regex",pattern:"^[a-zA-Z][a-zA-Z0-9_]*$"},description:{type:"string",description:"The description of the parameter"},format:{type:"string",enum:["string","number","boolean"],description:"The format of the parameter. Should only be set if a default value is not provided."},default:{type:["string","number","boolean"],description:"An optional default value of this parameter. If this is omitted, the parameter must be provided when creating a survey from the template."}},required:["id","description"],oneOf:[{required:["format"]},{required:["default"]}],additionalProperties:!1}},macros:{type:"object",description:"Expression shortcuts. Macros are referred to elsewhere in the survey using the ${m:<name>} construct (similar to parameters) and will get lazily in-place replaced. Macros can be recursive and contain references to parameters or answers in the survey.",additionalProperties:{type:"string"}},sections:{type:"array",description:"The survey sections, in the order they will appear in the survey",items:{$ref:"#/$defs/section"}}},o=!1,n=["template","parameters","sections"],a={section:{type:"object",description:"A survey section.",properties:{id:{type:"string",description:"The id of this section",format:"regex",pattern:"^[a-zA-Z][a-zA-Z0-9_-]*[a-zA-Z0-9]$"},name:{type:"string",description:"The name of this section"},display_logic:{type:"string",description:"An optional boolean expression that decides if the surveyee should see the questions in this section."},hide_progress_bar:{type:"boolean",description:"When set, the survey progress bar will not be shown during this section."},pages:{type:"array",description:"The questions in the section, split into pages",items:{$ref:"#/$defs/page"}}},additionalProperties:!1,required:["id","name","pages"]},page:{type:"object",properties:{questions:{type:"array",description:"The questions on the page",items:{$ref:"#/$defs/question"}}},required:["questions"],additionalProperties:!1},question:{type:"object",properties:{id:{type:"string",description:"The unique ID of the question",pattern:"^[a-zA-Z][a-zA-Z0-9_]*$"},text:{type:"string",description:"The question description, in markdown"},type:{type:"string",enum:["mc-single","mc-multi","matrix-single","matrix-multi","text-single","text-multi","description"],description:"The type of question"},layout:{type:"string",enum:["vertical","horizontal"],description:"Determines the visual layout of the options in multiple choice questions"},display_logic:{type:"string",description:"A boolean expression with logic if this question should be displayed or not"},required:{type:"string",enum:["required","optional","request"],description:"If the question is required to answer; request means you will get a warning if you skip it but you can."},validation:{type:"object",description:"Validation constraints on the question. Only applied if the user has answered the question, so typically used in combination with required",properties:{min_choices:{type:"integer",description:"The minimum number of choices to user can pick (multiple choice questions only)"},max_choices:{type:"integer",description:"The maximum number of choices to user can pick (multiple choice questions only)"}},additionalProperties:!1},statements:{type:"array",items:{$ref:"#/$defs/statement"}},dynamic_statements:{type:"string",description:"Carry forward statements from a previous question",pattern:"^[a-zA-Z][a-zA-Z0-9_]*/(all|selected|all_entered_text|selected_entered_text|not_selected|for_matrix_choice\\([\\-a-zA-Z0-9_]+\\)|unselected_for_matrix_choice\\([\\-a-zA-Z0-9_]+\\))$"},statement_groups:{type:"array",items:{type:"object",properties:{statements:{type:"array",items:{$ref:"#/$defs/statement"}},id:{type:"string",description:"The id of the group."},display:{type:"string",description:"The display name of the group"},display_logic:{type:"string",description:"A boolean expression determining if the group should be displayed"},randomization:{$ref:"#/$defs/randomization"}},required:["statements","id","display"],additionalProperties:!1}},choices:{type:"array",items:{$ref:"#/$defs/choice"}},dynamic_choices:{type:"string",description:"Carry forward choices from a previous question",pattern:"^[a-zA-Z][a-zA-Z0-9_]*/(all|selected|all_entered_text|selected_entered_text|not_selected|for_matrix_choice\\([\\-a-zA-Z0-9_]+\\)|unselected_for_matrix_choice\\([\\-a-zA-Z0-9_]+\\))$"},choice_groups:{type:"array",items:{type:"object",properties:{choices:{type:"array",items:{$ref:"#/$defs/choice"}},id:{type:"string",description:"The id of the group."},display:{type:"string",description:"The display name of the group"},display_logic:{type:"string",description:"A boolean expression determining if the group should be displayed"},randomization:{$ref:"#/$defs/randomization"}},required:["choices","id","display"],additionalProperties:!1}},randomization:{$ref:"#/$defs/randomization"},configuration:{type:"object",properties:{choice_column_width_pixels:{type:"integer",description:"Size of the column with the choice descriptions in a matrix question"}},additionalProperties:!1}},additionalProperties:!1,required:["text"],oneOf:[{$ref:"#/$defs/question-mc-horizontal"},{$ref:"#/$defs/question-mc-vertical"},{$ref:"#/$defs/question-matrix"},{$ref:"#/$defs/question-text"},{$ref:"#/$defs/question-description"}]},"question-mc-horizontal":{type:"object",properties:{type:{enum:["mc-single","mc-multi"]},position:{const:"horizontal"}},required:["id","type","position","choices"],not:{anyOf:[{required:["choice_groups"]},{required:["dynamic_choices"]},{required:["statements"]},{required:["dynamic_statements"]},{required:["statement_groups"]}]}},"question-mc-vertical":{type:"object",properties:{type:{enum:["mc-single","mc-multi"]},position:{const:"vertical"}},required:["id","type"],not:{anyOf:[{required:["statements"]},{required:["dynamic_statements"]},{required:["statement_groups"]}]},oneOf:[{anyOf:[{required:["choices"]},{required:["dynamic_choices"]}],not:{required:["choice_groups"]}},{required:["choice_groups"],not:{anyOf:[{required:["choices"]},{required:["dynamic_choices"]}]}}]},"question-matrix":{type:"object",properties:{type:{enum:["matrix-single","matrix-multi"]}},required:["id","type","choices"],not:{anyOf:[{required:["dynamic_choices"]},{required:["choice_groups"]}]},oneOf:[{anyOf:[{required:["statements"]},{required:["dynamic_statements"]}],not:{required:["statement_groups"]}},{required:["statement_groups"],not:{anyOf:[{required:["statements"]},{required:["dynamic_statements"]}]}}]},"question-text":{type:"object",properties:{type:{enum:["text-single","text-multi"]}},required:["id","type"],not:{anyOf:[{required:["choices"]},{required:["choice_groups"]},{required:["dynamic_choices"]},{required:["statements"]},{required:["statement_groups"]},{required:["dynamic_statements"]},{required:["randomization"]}]}},"question-description":{type:"object",properties:{type:{const:"description"}},not:{anyOf:[{required:["choices"]},{required:["choice_groups"]},{required:["dynamic_choices"]},{required:["statements"]},{required:["statement_groups"]},{required:["dynamic_statements"]},{required:["randomization"]}]}},statement:{type:"object",properties:{id:{type:"string",pattern:"^[a-zA-Z][a-zA-Z0-9_]*$",description:"The id of the statement"},display:{type:"string",description:"The statement name, as shown to the surveyee"},display_logic:{type:"string",description:"A boolean expression determining if the statement should be displayed"}},required:["id","display"],additionalProperties:!1},choice:{type:"object",properties:{display:{type:"string",description:"The choice name, as shown to the surveyee"},id:{type:"string",pattern:"^[a-zA-Z][a-zA-Z0-9_]*$",description:"The id of the choice"},value:{type:"integer",description:"The value the choice"},display_logic:{type:"string",description:"A boolean expression determining if the choice should be displayed"},text_input:{type:"string",enum:["no","optional","forced"],description:"If a textbox should appear next to the choice, and if it should be mandatory to fill it in if the choice is selected"},exclusive_answer:{type:"boolean",description:"If true, this choice can't be combined with other choices in this question"}},required:["display"],oneOf:[{required:["value"]},{required:["id"]}],additionalProperties:!1},randomization:{type:"object",description:"Configuration of the display order randomization of choices, statements or groups.",properties:{type:{type:"string",description:"The type of randomization: randomize all items, a subset of them, or using constrained randomization",enum:["all","subset","constrained"]},total:{type:"integer",description:"Maximum number of items to show"},order:{type:"string",description:"A space separated string containing the order of the items; each 'word' is either an id of some item or the wildcard $ representing the remaining items"}},required:["type"],oneOf:[{properties:{type:{const:"all"}},not:{required:["total","order"]}},{properties:{type:{const:"subset"}},required:["total"],not:{required:["order"]}},{properties:{type:{const:"constrained"}},required:["order"]}],additionalProperties:!1}},p={$id:e,$schema:t,title:i,type:r,properties:s,additionalProperties:o,required:n,$defs:a};exports.$defs=a,exports.$id=e,exports.$schema=t,exports.additionalProperties=o,exports.default=p,exports.properties=s,exports.required=n,exports.title=i,exports.type=r;
|
|
2
|
+
//# sourceMappingURL=survey-template-schema.json.cjs.js.map
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
"use strict";var l=require("../graphql/schema-types.generated.cjs.js"),R=require("./convertTemplateToNode.cjs.js"),v=require("./evaluation.cjs.js");const q=(s,e)=>e?`${s}.${e}`:s,w=(s,e,n,i)=>{if(!e.singleAnswer)return i?.warn("Response validation failed: No SingleAnswer provided in single answer question.",{surveyResponseId:n.surveyResponseId,questionId:e.questionId}),!1;const o=new Set(n.getQuestionChoicesFlattened(s).map(a=>a.id??a.value)),d=e.singleAnswer.choiceId??e.singleAnswer.choiceValue;return o.has(d)?!0:(i?.warn("Response validation failed: Selected choice in single answer question not available",{surveyResponseId:n.surveyResponseId,questionId:s.id,choiceKey:d}),!1)},y=(s,e,n,i)=>{if(!e.multipleAnswers)return i?.warn("Response validation failed: No MultipleAnswer provided in multi answer question",{surveyResponseId:n.surveyResponseId,questionId:e.questionId}),!1;const o=new Set(n.getQuestionChoicesFlattened(s).map(a=>a.id??a.value));let d=!1;return e.multipleAnswers.forEach(a=>{const u=a.choiceId??a.choiceValue;o.has(u)||(i?.warn("Response validation failed: Selected choice in multi answer question not available",{surveyResponseId:n.surveyResponseId,questionId:s.id,choiceKey:u}),d=!0)}),!d},h=(s,e,n)=>s.singleAnswer?.text?!0:(n?.warn("Response validation failed: No text provided",{surveyResponseId:e.surveyResponseId,questionId:s.questionId}),!1);function m(s,e,n,i){if(!v.hasAnswer(e))return!0;switch(R.getQuestionTypeEnum(s.type)){case l.QuestionType.McSingle:case l.QuestionType.MatrixSingle:return w(s,e,n,i);case l.QuestionType.McMulti:case l.QuestionType.MatrixMulti:return y(s,e,n,i);case l.QuestionType.TextSingle:case l.QuestionType.TextMulti:return h(e,n,i);default:return i?.warn("Response validation failed: Unsupported question type",{questionId:s.id,questionType:s.type,surveyResponseId:n.surveyResponseId}),!1}}function g(s,e,n,i){const o={templateId:s.id,surveyResponseId:n.surveyResponseId};i?.debug("Validating response...",{questionResponses:e,...o});const d=v.evaluateTemplateNode(s,n),a=R.extractQuestionNodes(d),u=v.getRelevantQuestionResponses(d,e);if(new Set(u.map(t=>q(t.questionId,t.statementId))).size<u.length)return i?.warn("Response validation failed: Duplicate question/statement ID(s) in the response.",{relevantQuestionResponses:u,...o}),!1;const f=Object.fromEntries(a.filter(t=>t.id).map(t=>[t.id,t])),I=new Map;for(const t of u){const p=f[t.questionId];if(!p)return i?.warn("Response validation failed: Response provided to a question that's not in the template",{questionId:t.questionId,...o}),!1;let r=I.get(t.questionId);if(r===void 0&&(r=new Map(n.getQuestionStatementsFlattened(p).map(c=>[c.id,c])),I.set(t.questionId,r)),t.statementId){if(!r||!r.size)return i?.warn("Response validation failed: Response provided to a statement even to the question has no statements",{questionId:t.questionId,statementId:t.statementId,...o}),!1;if(!r.get(t.statementId))return i?.warn("Response validation failed: Response provided to an invalid question statement",{questionId:t.questionId,statementId:t.statementId,...o}),!1}else if(r&&r.size)return i?.warn("Response validation failed; Response provided to a question with statements but not statement provided.",{questionId:t.questionId,statementId:t.statementId,...o}),!1;if(!m(p,t,n,i))return!1}return!0}exports.responseRef=q,exports.validateQuestionResponse=m,exports.validateResponse=g;
|
|
2
|
+
//# sourceMappingURL=validateResponse.cjs.js.map
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
"use strict";var I=require("ajv"),q=require("ajv-formats"),E=require("./interpolation.cjs.js"),l=require("./locators.cjs.js"),p=require("./logic.cjs.js"),_=require("./schema/survey-template-schema.json.cjs.js");function m(e){return e&&typeof e=="object"&&"default"in e?e:{default:e}}var g=m(I),x=m(q);const w=new g.default({allowUnionTypes:!0});x.default(w);const v=w.compile(_.default);class h extends Error{}class r extends Error{}class f extends Error{}class c extends Error{}class y extends Error{}class S{seenQuestions=new Set;seenMultiQuestions=new Set;seenQuestionStatements=new Map;seenQuestionChoices=new Map;seenTextChoices=new Map;evaluator={};constructor(){this.evaluator.isSelected=i=>(this.validateReference(i),!1),this.evaluator.countSelected=i=>(this.validateReference({questionId:i}),0),this.evaluator.selectedValue=i=>(this.validateReference({questionId:typeof i=="string"?i:i.questionId,statementId:typeof i=="string"?void 0:i.statementId,expectMulti:!1}),0),this.evaluator.countChoiceSelections=(i,n)=>(this.validateReference({questionId:i,choice:n}),0),this.evaluator.textEntry=i=>(this.validateReference({...i,expectText:!0}),"")}validateReference=i=>{if(!this.seenQuestions.has(i.questionId))throw new h(`Invalid question: ${i.questionId}`);if(i.statementId!==void 0&&!this.seenQuestionStatements.get(i.questionId)?.has(i.statementId))throw new h(`Invalid statement: ${i.questionId}.${i.statementId}`);if(i.choice!==void 0&&!this.seenQuestionChoices.get(i.questionId)?.has(i.choice))throw new h(`Invalid choice: ${i.questionId}[${i.choice}]`);if(i.choice!==void 0&&i.expectText===!0&&!this.seenTextChoices.get(i.questionId)?.has(i.choice))throw new h(`Invalid text reference: ${i.questionId}[${i.choice}]`);if(typeof i.expectMulti=="boolean"&&i.expectMulti&&!this.seenMultiQuestions.has(i.questionId))throw new r(`Invalid question reference: ${i.questionId}. Expected a multi-answer question.`);if(typeof i.expectMulti=="boolean"&&!i.expectMulti&&this.seenMultiQuestions.has(i.questionId))throw new r(`Invalid question reference: ${i.questionId}. Expected a non-multi-answer question.`)}}const d=(e,i,n)=>{if(n)try{p.evaluateExpression(n,e.evaluator)}catch(t){throw t instanceof h||t instanceof r||t instanceof c?t:new Error(`Syntax error parsing display logic at ${i}: ${n}`)}},T=(e,i)=>{[...i.matchAll(p.QUESTION_TEXT_LOCATOR_PATTERN)].forEach(n=>{const t=l.parseLocator(n.groups.locator);if(!e.seenQuestions.has(t.questionId))throw new r(`Invalid question referenced in locator expression: ${t.questionId}/${t.expression}`);if(t.identifier&&!e.seenQuestionChoices.get(t.questionId)?.has(t.identifier))throw new r(`Invalid question choice referenced in locator expression: ${t.questionId}/${t.expression}(${t.identifier})`)})},u=(e,i,n)=>{if(n){const t=new Set(i);if(n.order){const s=n.order.split(" "),o=s.filter(a=>a==="$").length;if(o===0)throw new f(`Wildcard $ is missing in randomization order at ${e.id}`);if(o>1)throw new f(`Wildcard $ occurred multiples times in randomization order at ${e.id}`);if(s.forEach(a=>{if(a!=="$"&&!t.has(a))throw new f(`Unknown id ${a} in randomization ordering at ${e.id}`)}),n.total!==void 0&&n.total<s.length)throw new f(`Total value in randomization is too small at ${e.id}`)}}},$=(e,i)=>{const n=[l.LOCATOR_EXPRESSION.FOR_MATRIX_CHOICE,l.LOCATOR_EXPRESSION.UNSELECTED_FOR_MATRIX_CHOICE].includes(e.expression),t=(n?i.seenQuestionStatements:i.seenQuestionChoices).get(e.questionId);if(t===void 0)throw new r(`Invalid question referenced in locator expression: ${e.questionId}/${e.expression}`);if(n){const s=i.seenQuestionChoices.get(e.questionId);if(!e.identifier||!s?.has(e.identifier))throw new r(`Invalid choice referenced in locator expression: ${e.questionId}/${e.expression}(${e.identifier})`)}return t},C=(e,i)=>{if(T(i,e.text),e.id!==void 0){if(d(i,e.id,e.display_logic),e.statements?.forEach(t=>{d(i,`${e.id}.${t.id}`,t.display_logic)}),e.choices?.forEach(t=>{d(i,`${e.id}[${t.id||t.value}]`,t.display_logic)}),e.type==="matrix-multi"||e.type==="matrix-single"?e.statement_groups?u(e,e.statement_groups.map(t=>t.id),e.randomization):u(e,e.statements?.map(t=>t.id)??[],e.randomization):e.choice_groups?u(e,e.choice_groups.map(t=>t.id),e.randomization):u(e,e.choices?.map(t=>`${t.id||t.value}`)??[],e.randomization),e.statement_groups?.forEach(t=>{t.statements.forEach(s=>{d(i,`${e.id}.${s.id}`,s.display_logic)}),u(e,t.statements.map(s=>s.id),t.randomization)}),e.choice_groups?.forEach(t=>{t.choices.forEach(s=>{d(i,`${e.id}[${s.id||s.value}]`,s.display_logic)}),u(e,t.choices.map(s=>`${s.id||s.value}`),t.randomization)}),i.seenQuestions.has(e.id))throw new c(`Duplicate question id: ${e.id}`);if(i.seenQuestions.add(e.id),e.type&&["matrix-multi","mc-multi"].includes(e.type)&&i.seenMultiQuestions.add(e.id),e.statements||e.dynamic_statements){const t=new Set;if(i.seenQuestionStatements.set(e.id,t),e.statements?.forEach(s=>{if(t.has(s.id))throw new c(`Duplicate statement id: ${e.id}.${s.id}`);t.add(s.id)}),e.dynamic_statements){const s=l.parseLocator(e.dynamic_statements);$(s,i).forEach(o=>{if(typeof o=="number")throw new r(`Dynamic statement in question ${e.id} refers to choices with values`);if(t.has(o))throw new c(`Duplicate statement ${o} via dynamic statements in question ${e.id}`);t.add(o)})}}const n=e.choices??[];if(e.choice_groups){if(new Set(e.choice_groups.map(t=>t.id)).size!==e.choice_groups.length)throw new c(`Choice groups must have a unique id in question ${e.id}`);e.choice_groups.forEach(t=>n.push(...t.choices))}if(n||e.dynamic_choices){const t=new Set;i.seenQuestionChoices.set(e.id,t);const s=new Set;if(i.seenTextChoices.set(e.id,s),n.forEach(o=>{const a=o.id??o.value;if(t.has(a))throw new c(`Duplicate choice: ${e.id}[${a}]`);t.add(a),o.text_input&&o.text_input!=="no"&&s.add(a)}),e.dynamic_choices){const o=l.parseLocator(e.dynamic_choices);$(o,i).forEach(a=>{if(t.has(a))throw new c(`Duplicate choice ${a} via dynamic choices in ${e.id}`);t.add(a)}),i.seenTextChoices.get(o.questionId)?.forEach(a=>s.add(a))}if(new Set([...t].map(o=>typeof o)).size>=2)throw new y("All choices in a question must either all have id's or all have values")}}},Q=e=>{if(!v(e))throw new Error(`Invalid template: ${e.template.id}. Reason: ${JSON.stringify(v.errors,null,4)}`);E.interpolateTemplate(e);const i=new S;e.sections.forEach(n=>{d(i,n.id,n.display_logic),n.pages.forEach(t=>{t.questions?.forEach(s=>{C(s,i)})})})};exports.validateTemplate=Q;
|
|
2
|
+
//# sourceMappingURL=validateTemplate.cjs.js.map
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
"use strict";var c=require("lodash");function l(a){return a&&typeof a=="object"&&"default"in a?a:{default:a}}var e=l(c);const s=(a,r="camelCase")=>{const f=r==="camelCase"?e.default.camelCase:e.default.snakeCase;return e.default.transform(a,(o,t,n)=>{const u=typeof n=="string"?f(n):n;o[u]=e.default.isObject(t)&&!(t instanceof Date)?s(t,r):t})};exports.transformCase=s;
|
|
2
|
+
//# sourceMappingURL=transformCase.cjs.js.map
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@spotify/backstage-plugin-pulse-common",
|
|
3
|
-
"version": "0.12.
|
|
3
|
+
"version": "0.12.3",
|
|
4
4
|
"license": "SEE LICENSE IN LICENSE.md",
|
|
5
5
|
"homepage": "https://backstage.spotify.com",
|
|
6
6
|
"main": "dist/index.cjs.js",
|
|
@@ -30,8 +30,8 @@
|
|
|
30
30
|
"json2ts": "./src/templates/schema/generateSchemaTypes.sh"
|
|
31
31
|
},
|
|
32
32
|
"dependencies": {
|
|
33
|
-
"@backstage/config": "^1.
|
|
34
|
-
"@backstage/plugin-permission-common": "^0.8.
|
|
33
|
+
"@backstage/config": "^1.3.0",
|
|
34
|
+
"@backstage/plugin-permission-common": "^0.8.2",
|
|
35
35
|
"@ungap/structured-clone": "^1.2.0",
|
|
36
36
|
"ajv": "^8.11.2",
|
|
37
37
|
"ajv-formats": "^3.0.0",
|
|
@@ -39,7 +39,7 @@
|
|
|
39
39
|
"lodash": "^4.17.21"
|
|
40
40
|
},
|
|
41
41
|
"devDependencies": {
|
|
42
|
-
"@backstage/cli": "^0.
|
|
42
|
+
"@backstage/cli": "^0.29.2",
|
|
43
43
|
"@types/ungap__structured-clone": "^1.0.0",
|
|
44
44
|
"js-yaml": "^4.1.0",
|
|
45
45
|
"json-schema-to-typescript": "^15.0.0",
|
|
@@ -61,5 +61,12 @@
|
|
|
61
61
|
"yaml"
|
|
62
62
|
]
|
|
63
63
|
},
|
|
64
|
+
"typesVersions": {
|
|
65
|
+
"*": {
|
|
66
|
+
"index": [
|
|
67
|
+
"dist/index.d.ts"
|
|
68
|
+
]
|
|
69
|
+
}
|
|
70
|
+
},
|
|
64
71
|
"module": "dist/index.esm.js"
|
|
65
72
|
}
|