@spotify/backstage-plugin-pulse-common 0.11.5 → 0.11.6
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 +7 -0
- package/dist/config.esm.js +2 -0
- package/dist/graphql/schema-types.generated.esm.js +2 -0
- package/dist/index.esm.js +1 -22
- package/dist/permissions.esm.js +2 -0
- package/dist/polyfills.esm.js +2 -0
- package/dist/templates/convertTemplateToNode.esm.js +2 -0
- package/dist/templates/evaluation.esm.js +2 -0
- package/dist/templates/index.esm.js +2 -0
- package/dist/templates/interpolation.esm.js +2 -0
- package/dist/templates/locators.esm.js +2 -0
- package/dist/templates/logic.esm.js +2 -0
- package/dist/templates/schema/logic_parser.esm.js +23 -0
- package/dist/templates/schema/survey-template-schema.json.esm.js +2 -0
- package/dist/templates/validateResponse.esm.js +2 -0
- package/dist/templates/validateTemplate.esm.js +2 -0
- package/dist/transformCase.esm.js +2 -0
- package/package.json +4 -4
package/CHANGELOG.md
CHANGED
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
const i="pulse.experimentalFlags",a=(t,e)=>{const n=t.getOptionalStringArray(i);return n==null?void 0:n.includes(e)},p=(t,e)=>{var n;const l=t.getOptionalStringArray(i),r=`${e}=`;return(n=l==null?void 0:l.find(o=>o.startsWith(r)))==null?void 0:n.replace(r,"")};export{a as getExperimentalOptionalBoolean,p as getExperimentalOptionalString};
|
|
2
|
+
//# sourceMappingURL=config.esm.js.map
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
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||{}),i=(e=>(e.Horizontal="HORIZONTAL",e.Vertical="VERTICAL",e))(i||{}),t=(e=>(e.Optional="OPTIONAL",e.Request="REQUEST",e.Required="REQUIRED",e))(t||{}),T=(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))(T||{}),E=(e=>(e.All="ALL",e.Constrained="CONSTRAINED",e.Subset="SUBSET",e))(E||{}),S=(e=>(e.Finalized="FINALIZED",e.Partial="PARTIAL",e))(S||{}),a=(e=>(e.Active="ACTIVE",e.Published="PUBLISHED",e))(a||{}),R=(e=>(e.Q1="Q1",e.Q2="Q2",e.Q3="Q3",e.Q4="Q4",e))(R||{});export{I as MutationResponseErrorCode,i as QuestionLayout,t as QuestionRequirement,T as QuestionType,E as RandomizationType,S as SurveyResponseStatus,a as SurveyStatus,R as TargetQuarter};
|
|
2
|
+
//# sourceMappingURL=schema-types.generated.esm.js.map
|
package/dist/index.esm.js
CHANGED
|
@@ -1,23 +1,2 @@
|
|
|
1
|
-
import{createPermission as Ut}from"@backstage/plugin-permission-common";import Ft from"@ungap/structured-clone";import Zt from"ajv";import Bt from"ajv-formats";import Gt from"assert";import*as Vt from"crypto";import te from"lodash";const Wt="survey-instance",Be=Ut({name:"survey.instance.administer",attributes:{action:"create"}}),Xt=[Be],Ge="pulse.experimentalFlags",Ht=(i,t)=>{const n=i.getOptionalStringArray(Ge);return n==null?void 0:n.includes(t)},Jt=(i,t)=>{var n;const s=i.getOptionalStringArray(Ge),r=`${t}=`;return(n=s==null?void 0:s.find(a=>a.startsWith(r)))==null?void 0:n.replace(r,"")},Yt=()=>{"structuredClone"in globalThis||(globalThis.structuredClone=Ft)};var Kt="surveyTemplate",en="http://json-schema.org/draft-07/schema",tn="Survey Template",nn="object",sn={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"}}},rn=!1,an=["template","parameters","sections"],on={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}},Ve={$id:Kt,$schema:en,title:tn,type:nn,properties:sn,additionalProperties:rn,required:an,$defs:on};const ln=/\$\{m:([^\}]+)\}/g,_n=100,ye=(i,t)=>{if(typeof t=="string"){let n=t,s=0;for(;s<_n;){const r=n.replace(ln,(a,o)=>{if(i[o]===void 0)throw new Error(`Undefined macro: ${o}`);return i[o]});if(r===n)return r;n=r,s+=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]=ye(i,t[n])}),t},We=i=>(i.sections=ye(i.macros||{},i.sections),i),cn="(?<questionId>[a-zA-Z][a-zA-Z0-9_]*)",pn="((?<expressionWithoutIdentifier>all|all_entered_text|selected|selected_entered_text|not_selected)|(?<expressionWithIdentifier>for_matrix_choice|unselected_for_matrix_choice)(\\((?<identifier>[\\-a-zA-Z0-9_]+)\\)))",Xe=new RegExp(`^${cn}/${pn}$`);var v=(i=>(i.ALL="all",i.ALL_ENTERED_TEXT="all_entered_text",i.SELECTED="selected",i.SELECTED_ENTERED_TEXT="selected_entered_text",i.NOT_SELECTED="not_selected",i.FOR_MATRIX_CHOICE="for_matrix_choice",i.UNSELECTED_FOR_MATRIX_CHOICE="unselected_for_matrix_choice",i))(v||{});const He=i=>Xe.test(i),D=i=>{var t;const n=(t=i.match(Xe))==null?void 0:t.groups;if(!n)throw new Error(`Invalid locator expression: ${i}`);const s=n.expressionWithoutIdentifier||n.expressionWithIdentifier||"all",r={questionId:n.questionId,expression:s};if(n.identifier){const a=isNaN(parseInt(n.identifier,10))?n.identifier:parseInt(n.identifier,10);r.identifier=a}return r};var un=(i=>(i.DuplicateResponse="DUPLICATE_RESPONSE",i.InternalError="INTERNAL_ERROR",i.InvalidDates="INVALID_DATES",i.InvalidId="INVALID_ID",i.InvalidParticipants="INVALID_PARTICIPANTS",i.InvalidResponse="INVALID_RESPONSE",i.MissingTitle="MISSING_TITLE",i.OverlappingSurveys="OVERLAPPING_SURVEYS",i.ParticipantsFrozen="PARTICIPANTS_FROZEN",i.SurveyIsClosed="SURVEY_IS_CLOSED",i.Unauthorized="UNAUTHORIZED",i))(un||{}),dn=(i=>(i.Horizontal="HORIZONTAL",i.Vertical="VERTICAL",i))(dn||{}),hn=(i=>(i.Optional="OPTIONAL",i.Request="REQUEST",i.Required="REQUIRED",i))(hn||{}),N=(i=>(i.Description="DESCRIPTION",i.MatrixMulti="MATRIX_MULTI",i.MatrixSingle="MATRIX_SINGLE",i.McMulti="MC_MULTI",i.McSingle="MC_SINGLE",i.TextMulti="TEXT_MULTI",i.TextSingle="TEXT_SINGLE",i))(N||{}),mn=(i=>(i.All="ALL",i.Constrained="CONSTRAINED",i.Subset="SUBSET",i))(mn||{}),fn=(i=>(i.Finalized="FINALIZED",i.Partial="PARTIAL",i))(fn||{}),yn=(i=>(i.Active="ACTIVE",i.Published="PUBLISHED",i))(yn||{}),gn=(i=>(i.Q1="Q1",i.Q2="Q2",i.Q3="Q3",i.Q4="Q4",i))(gn||{});const ne=(i,t="camelCase")=>{const n=t==="camelCase"?te.camelCase:te.snakeCase;return te.transform(i,(s,r,a)=>{const o=typeof a=="string"?n(a):a;s[o]=te.isObject(r)&&!(r instanceof Date)?ne(r,t):r})};function xn(i){const t=structuredClone(i);return{...t,...t.template,sections:t.sections.map(n=>({...ne(n),pages:n.pages.map((s,r)=>({...s,id:`${n.id}-${r}`,questions:wn(t,n,s.questions)}))}))}}function wn(i,t,n){return n.map(s=>vn(i.template.id,t,s))}function vn(i,t,n){var s,r;return{...ne({...n,choiceGroups:(s=n.choice_groups)==null?void 0:s.map(a=>({...a,randomization:ge(a.randomization)})),statementGroups:(r=n.statement_groups)==null?void 0:r.map(a=>({...a,randomization:ge(a.randomization)})),randomization:ge(n.randomization)}),id:Ye(i,n),type:we(n.type),layout:Tn(n.layout),required:bn(n.required),label:t.name}}function ge(i){var t;return i?{type:Je(i.type),order:(t=i.order)==null?void 0:t.split(" "),total:i.total}:void 0}function Je(i){return i.toUpperCase()}function Ye(i,t){return`${i}.${t.id}`}const xe=i=>i.split(".").pop();function we(i="description"){return i.replace("-","_").toUpperCase()}function Tn(i){return i==null?void 0:i.toUpperCase()}function bn(i="optional"){return i.replace("-","_").toUpperCase()}function ve(i){return structuredClone(i).sections.flatMap(t=>t.pages.flatMap(n=>n.questions))}var En=Object.defineProperty,In=(i,t,n)=>t in i?En(i,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):i[t]=n,q=(i,t,n)=>(In(i,typeof t!="symbol"?t+"":t,n),n);function Rn(i={}){return i.transformer&&i.transformer.constructor.name==="object"&&(i.transformer=J.fromObj(i.transformer)),It._load_from_dict({data:Ai,memo:Oi,...i})}const Ke={};class et{}const ie={},tt={escape(i){return i.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")},compile(i,t){return new RegExp(i,t)},error:SyntaxError};function Nn(i,t,n,s){const r=i.compile(t,s).exec(n);if(r!=null)return r[0]}class nt{constructor(t,n,s,r,a=!1){this.terminals=t,this.g_regex_flags=n,this.re_=s,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?"$":"",s=Dn(t,a=>a.pattern.flags.join("")),r=[];for(let[a,o]of s){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 s of this._regexps){s.lastIndex=n;let r=s.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 it=typeof require!="undefined"&&require("util");class st{}const W={};function w(i){return Object.entries(i)}function Te(i){return Object.keys(i)}function qn(i,t){t===void 0&&(t=Object.keys(i)[0]);let n=i[t];return delete i[t],n}function rt(i,t,n=null){return i[t]||n}function at(i,t){if(i.constructor.name==="Map")for(const[n,s]of w(t))i.set(n,s);else for(const[n,s]of w(t))i[n]=s}function kn(i){return function(){return new i(...arguments)}}function f(i){let t=0,n=[...arguments].slice(1);return i.replace(/%([sr])/g,function(){const s=arguments[1],r=n[t++];return s==="r"?it?it.inspect(r,!1,null,!0):JSON.stringify(r,null,0):r})}function An(i,t){let n=new Set(i);for(const s of t)n.add(s);return n}function ot(i,t){return[...i].filter(n=>!t.has(n))}function lt(i){return{...i}}function _t(i){return!!i}function be(i){return Object.create(i.prototype)}function k(i){if(typeof i=="object"){let t=Object.create(Object.getPrototypeOf(i));return Object.assign(t,i)}return i}function se(i){return new Set(i)}function Ee(i){return i&&i.constructor.name==="Object"}function On(i){return i&&i.constructor.name==="Array"}function Sn(i){return typeof i=="function"}function*X(i,t=0){let n=t;for(const s of i)yield[n++,s]}function $n(i){for(const t of i)if(t)return!0;return!1}function ct(i,t){return t.filter(i||_t)}function re(i){let t=[...arguments].slice(1);return function(){return i(...t,...arguments)}}class Ie extends Error{}function b(i){return i[i.length-1]}function P(i){return function(){let t=new i(...arguments);return t.__call__.bind(t)}}function O(i,t){return Array.from({length:t},()=>i).flat()}function pt(i){return/^[A-Z_$]*$/.test(i)}function Re(i,t,n){const s=i.split(t);return n?s.splice(-n-1):s}function Ne(i,t){let n=new RegExp(t,"g");return(i.match(n)||[]).length}function zn(i,t){for(let n of i)if(!t.has(n))return!1;return!0}function*Dn(i,t){let n=[],s=null;for(const r of i){const a=t(r);s&&a!=s&&(yield[s,n],n=[]),n.push(r),s=a}yield[s,n]}let S=class extends Error{};class $ extends S{}function qe(i,t,n="Got %r, expected one of %s"){if(!t.includes(i))throw new $(f(n,i,t))}class ae extends S{}class Pn extends S{}let H=class extends S{},Q=class Mt extends S{constructor(){super(...arguments),q(this,"pos_in_stream",null),q(this,"_terminals_by_name",null)}get_context(t,n=40){let s,r,a=this.pos_in_stream,o=max(a-n,0),l=a+n;return t instanceof bytes?(r=b(Re(t.slice(o,a),`
|
|
2
|
-
`,1)),s=t.slice(a,l).split(`
|
|
3
|
-
`,1)[0],(r+s+`
|
|
4
|
-
`+" "*r.expandtabs().length+`^
|
|
5
|
-
`).decode("ascii","backslashreplace")):(r=b(Re(t.slice(o,a),`
|
|
6
|
-
`,1)),s=t.slice(a,l).split(`
|
|
7
|
-
`,1)[0],r+s+`
|
|
8
|
-
`+" "*r.expandtabs().length+`^
|
|
9
|
-
`)}match_examples(t,n,s=!1){Ee(n)&&(n=w(n));let r=[null,!1];for(const[a,[o,l]]of X(n))for(const[p,c]of X(l))try{t(c)}catch(_){if(_ instanceof Mt){if(_.state.eq(this.state)){if(_.token===this.token)return o;s&&_.token.type===this.token.type&&!b(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(s=>s in n?n[s].user_repr():s)),f(`Expected one of:
|
|
10
|
-
* %s
|
|
11
|
-
`,t.join(`
|
|
12
|
-
* `))}};class Ln extends Q{constructor(t,n=null,s=null){super(),this.expected=t,this.state=n,this.token=new x("<EOF>",""),this.pos_in_stream=-1,this.line=-1,this.column=-1,this._terminals_by_name=s}}class M extends Q{constructor({seq:t,lex_pos:n,line:s,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=s,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 j=class extends Q{constructor({token:t,expected:n,considered_rules:s=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=Ke,this.considered_rules=s,this.interactive_parser=a,this._terminals_by_name=o,this.token_history=l}get accepts(){return this._accepts===Ke&&(this._accepts=this.interactive_parser&&this.interactive_parser.accepts()),this._accepts}};class ke extends S{constructor(t,n,s){let r=f(`Error trying to process rule "%s":
|
|
13
|
-
|
|
14
|
-
%s`,t,s);super(r),this.rule=t,this.obj=n,this.orig_exc=s}}function Cn(i,t=null,n=null){let s,r,a=new Map;for(const o of i)s=t!==null?t(o):o,r=n!==null?n(o):o,a.has(s)?a.get(s).push(r):a.set(s,[r]);return a}function oe(i,t,n){let s;return Ee(i)?"__type__"in i?(s=t[i.__type__],s.deserialize(i,n)):"@"in i?n[i["@"]]:Object.fromEntries(w(i).map(([r,a])=>[r,oe(a,t,n)])):On(i)?i.map(r=>oe(r,t,n)):i}class E{static deserialize(t,n){const s=this;let r=s&&s.__serialize_fields__;if("@"in t)return n[t["@"]];let a=be(s);for(const o of r)if(t&&o in t)a[o]=oe(t[o],qi,n);else throw new KeyError("Cannot find key for class",s,e);return"_deserialize"in a&&a._deserialize(),a}}class Qn extends E{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,s){return oe(t,n,s)}}class ut{constructor(){this.empty=!0}}let I=class G{constructor(t,n,s=null){this.data=t,this.children=n,this._meta=s}get meta(){return this._meta===null&&(this._meta=new ut),this._meta}repr(){return f("Tree(%r, %r)",this.data,this.children)}_pretty_label(){return this.data}_pretty(t,n){if(this.children.length===1&&!(this.children[0]instanceof G))return[O(n,t).join(""),this._pretty_label()," ",f("%s",this.children[0].value),`
|
|
15
|
-
`];let s=[O(n,t).join(""),this._pretty_label(),`
|
|
16
|
-
`];for(const r of this.children)r instanceof G?s.push(...r._pretty(t+1,n)):s.push(O(n,t+1).join(""),f("%s",r.value),`
|
|
17
|
-
`);return s}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 s of t)n.set(s,s),t.push(...[...s.children].reverse().filter(r=>r instanceof G&&!n.has(r)).map(r=>r));return t=void 0,[...n.values()].reverse()}find_pred(t){return ct(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 G)for(const s of n.scan_values(t))yield s;else t(n)&&(yield n)}*iter_subtrees_topdown(){let t,n=[this];for(;n.length;)if(t=n.pop(),t instanceof G){yield t;for(const s of[...t.children].reverse())n.push(s)}}copy(){return type(this)(this.data,this.children)}set(t,n){this.data=t,this.children=n}};class J extends et{static get __visit_tokens__(){return!0}constructor(t=!0){super(),this.__visit_tokens__=t}static fromObj(t,...n){class s extends this{}for(let[r,a]of Object.entries(t))s.prototype[r]=a;return new s(...n)}_call_userfunc(t,n=null){let s,r,a=n!==null?n:t.children;if(t&&t.data&&this&&this[t.data]){s=this&&this[t.data];try{return r=s&&s.visit_wrapper||null,r!==null?s.visit_wrapper(s,t.data,a,t.meta):s(a)}catch(o){throw o instanceof ae?o:o instanceof Error?new ke(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(s){throw s instanceof ae?s:s instanceof Error?new ke(t.type,t,s):s}}else return this.__default_token__(t)}*_transform_children(t){let n;for(const s of t)s instanceof I?n=this._transform_tree(s):this.__visit_tokens__&&s instanceof x?n=this._call_userfunc_token(s):n=s,n!==ie&&(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,s){return new I(t,n,s)}__default_token__(t){return t}}class dt extends J{_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 Mn extends J{transform(t){let n,s,r,a=[],o=[t];for(;o.length;){const c=o.pop();a.push(c),c instanceof I&&o.push(...c.children)}let l=[];for(const c of[...a].reverse())c instanceof I?(r=c.children.length,r?(n=l.slice(-r),l.splice(-r)):n=[],s=this._call_userfunc(c,n),s!==ie&&l.push(s)):this.__visit_tokens__&&c instanceof x?(s=this._call_userfunc_token(c),s!==ie&&l.push(s)):l.push(c);let[p]=l;return p}}class jn extends J{_transform_tree(t){return t.children=[...this._transform_children(t.children)],this._call_userfunc(t)}}class Ae{_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 Un extends Ae{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 Fn extends Ae{visit(t){for(const n of t.children)n instanceof I&&this.visit(n);return this._call_userfunc(t),t}visit_topdown(t){this._call_userfunc(t);for(const n of t.children)n instanceof I&&this.visit_topdown(n);return t}}class Zn extends et{visit(t){return t.data in this?this[t.data](t):this.__default__(t)}visit_children(t){return t.children.map(n=>n instanceof I?this.visit(n):n)}__default__(t){return this.visit_children(t)}}var Bn=0;class Oe extends E{constructor(t){super(),q(this,"is_term",W),this.name=t}eq(t){return this.is_term===t.is_term&&this.name===t.name}repr(){return f("%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 Oe{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 f("%s(%r, %r)",type(this).name,this.name,this.filter_out)}renamed(t){return type(this)(t(this.name),this.filter_out)}}class $e extends Oe{static get __serialize_fields__(){return["name"]}get is_term(){return!1}}let le=class extends E{static get __serialize_fields__(){return["keep_all_tokens","expand1","priority","template_source","empty_indices"]}constructor(t=!1,n=!1,s=null,r=null,a=[]){super(),this.keep_all_tokens=t,this.expand1=n,this.priority=s,this.template_source=r,this.empty_indices=a}repr(){return f("RuleOptions(%r, %r, %r, %r)",this.keep_all_tokens,this.expand1,this.priority,this.template_source)}};class V extends E{static get __serialize_fields__(){return["origin","expansion","order","alias","options"]}static get __serialize_namespace__(){return[Se,$e,le]}constructor(t,n,s=0,r=null,a=null){super(),this.origin=t,this.expansion=n,this.alias=r,this.order=s,this.options=a||new le,this._hash=[this.origin,this.expansion]}_deserialize(){this._hash=[this.origin,this.expansion]}repr(){return f("Rule(%r, %r, %r, %r)",this.origin,this.expansion,this.alias,this.options)}eq(t){return t instanceof V?this.origin===t.origin&&this.expansion===t.expansion:!1}}class ze extends E{constructor(t,n=[],s=null){super(),this.value=t,this.flags=se(n),this.raw=s}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 De extends ze{static get __serialize_fields__(){return["value","flags"]}static get type(){return"str"}to_regexp(){return this._get_flags(tt.escape(this.value))}get min_width(){return this.value.length}get max_width(){return this.value.length}}class Pe extends ze{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 _e=class extends E{static get __serialize_fields__(){return["name","pattern","priority"]}static get __serialize_namespace__(){return[De,Pe]}constructor(t,n,s=Bn){super(),this.name=t,this.pattern=n,this.priority=s}repr(){return f("%s(%r, %r)",type(this).name,this.name,this.pattern)}user_repr(){return this.name.startsWith("__")?this.pattern.raw||this.name:this.name}};class x{constructor(t,n,s=null,r=null,a=null,o=null,l=null,p=null){q(this,"value"),q(this,"type"),this.type=t,this.start_pos=s,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 x.new_borrow_pos(t!==null?t:this.type,n!==null?n:this.value,this)}static new_borrow_pos(t,n,s){const r=this;return new r(t,n,s.start_pos,s.line,s.column,s.end_line,s.end_column,s.end_pos)}repr(){return f("Token(%r, %r)",this.type,this.value)}eq(t){return t instanceof x&&this.type!==t.type?!1:str.__eq__(this,t)}static get __hash__(){return str.__hash__}}class Ue{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 Ue?this.char_pos===t.char_pos&&this.newline_char===t.newline_char:W}feed(t,n=!0){let s;n&&(s=Ne(t,this.newline_char),s&&(this.line+=s,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 Gn{constructor(t){this.scanner=t}__call__(t){let n,s=this.scanner.match(t.value,0);return s&&([n,t.type]=s),t}}const Vn=P(Gn);class Wn{constructor(t,n,s){this.callback1=t,this.callback2=n,this.cond=s}__call__(t){let n=this.callback1(t);return this.cond(n)?this.callback2(t):n}}const Xn=P(Wn);function Hn(i,t,n,s){let r,a,o=Cn(i,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===Nn(n,c.pattern.to_regexp(),r,t)&&(a.push(_),zn(new Set(_.pattern.flags),new Set(c.pattern.flags))&&l.add(_)));a.length&&(p[c.name]=new Vn(new nt(a,t,n,s,!0)))}return[i.filter(c=>!l.has(c)).map(c=>c),p]}function Jn(i){return i.includes(`
|
|
18
|
-
`)||i.includes("\\n")||i.includes("\\s")||i.includes("[^")||i.includes("(?s")&&i.includes(".")}class Fe{constructor(t,n=null,s=null){this.text=t,this.line_ctr=n||new Ue(`
|
|
19
|
-
`),this.last_token=s}eq(t){return t instanceof Fe?this.text===t.text&&this.line_ctr===t.line_ctr&&this.last_token===t.last_token:W}}class ht{constructor(t,n){this.lexer=t,this.state=n}static from_text(t,n){return new this(t,new Fe(n))}lex(t){return this.lexer.lex(this.state,t)}}class ce extends st{lex(t,n){return W}}function Yn(i,t){i.sort((n,s)=>{let r=t(n),a=t(s);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 pe extends ce{constructor(t){super();let n=[...t.terminals];if(this.re=t.re_module,!t.skip_validation){for(const s of n){try{this.re.compile(s.pattern.to_regexp(),t.g_regex_flags)}catch(r){throw r instanceof this.re.error?new H(f("Cannot compile token %s: %s",s.name,s.pattern)):r}if(s.pattern.min_width===0)throw new H(f("Lexer does not allow zero-width terminals. (%s: %s)",s.name,s.pattern))}if(!(new Set(t.ignore)<=new Set(n.map(s=>s.name))))throw new H(f("Ignore terminals are not defined: %s",ot(new Set(t.ignore),new Set(n.map(s=>s.name)))))}this.newline_types=se(n.filter(s=>Jn(s.pattern.to_regexp())).map(s=>s.name)),this.ignore_types=se(t.ignore),Yn(n,s=>[-s.priority,-s.pattern.max_width,-s.pattern.value.length,s.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]=Hn(this.terminals,this.g_regex_flags,this.re,this.use_bytes);for(const[n,s]of w(this.user_callbacks))n in this.callback?this.callback[n]=new Xn(this.callback[n],s,r=>r.type===n):this.callback[n]=s;this._scanner=new nt(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(s){if(!(s instanceof Ie))throw s}}next_token(t,n=null){let s,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 s=ot(this.scanner.allowed_types,this.ignore_types),s||(s=new Set(["<END-OF-FILE>"])),new M({seq:t.text,lex_pos:l.char_pos,line:l.line,column:l.column,allowed:s,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 x(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 x(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 x)))throw new H(f("Callbacks must return a token (returned %r)",a));return t.last_token=a,a}}throw new Ie(this)}}class Kn extends ce{constructor({conf:t,states:n,always_accept:s=[]}={}){super();let r,a,o,l=[...t.terminals],p=t.terminals_by_name,c=k(t);c.terminals=l;let _=new Map;this.lexers={};for(let[m,h]of w(n))r=se(h),_.has(r)?a=_.get(r):(h=An(new Set(h),[...new Set(t.ignore),...new Set(s)]),o=k(c),o.terminals=[...h].filter(y=>y in p).map(y=>p[y]),a=new pe(o),_.set(r,a)),this.lexers[m]=a;this.root_lexer=new pe(c)}*lex(t,n){let s,r,a;try{for(;;)r=this.lexers[n.position],yield r.next_token(t,n)}catch(o){if(!(o instanceof Ie))if(o instanceof M)try{throw s=t.last_token,a=this.root_lexer.next_token(t,n),new j({token:a,expected:o.allowed,state:n,token_history:[s],terminals_by_name:this.root_lexer.terminals_by_name})}catch(l){throw l}else throw o}}}class mt extends E{static get __serialize_fields__(){return["terminals","ignore","g_regex_flags","use_bytes","lexer_type"]}static get __serialize_namespace__(){return[_e]}constructor({terminals:t,re_module:n,ignore:s=[],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=s,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 ft extends E{static get __serialize_fields__(){return["rules","start","parser_type"]}constructor(t,n,s){super(),this.rules=t,this.callbacks=n,this.start=s,this.parser_type=null}}class ei{constructor(t){this.node_builder=t}__call__(t){return t.length===1?t[0]:this.node_builder(t)}}const ti=P(ei);class ni{constructor(t,n=null){this.node_builder=t,this.node_filter=n}__call__(t){let n,s,r,a=this.node_builder(t);return a instanceof I&&(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),s=this._pp_get_meta([...t].reverse()),s!==null&&("end_line"in r||(r.end_line=s&&s.container_end_line||s.end_line,r.end_column=s&&s.container_end_column||s.end_column,r.end_pos=s&&s.container_end_pos||s.end_pos,r.empty=!1),r.container_end_line=s&&s.container_end_line||s.end_line,r.container_end_column=s&&s.container_end_column||s.end_column)),a}_pp_get_meta(t){for(const n of t)if(!(this.node_filter!==null&&!this.node_filter(n))){if(n instanceof I){if(!n.meta.empty)return n.meta}else if(n instanceof x)return n}}}const yt=P(ni);function ii(i){if(Sn(i))return re({unknown_param_0:yt,node_filter:i});if(i===!0)return yt;if(i===!1)return null;throw new $(f("Invalid option for propagate_positions: %r",i))}class Le{constructor(t,n,s){this.node_builder=s,this.to_include=t,this.append_none=n}__call__(t){let n=[];for(const[s,r,a]of this.to_include)a&&n.push(...O([null],a)),r?n.push(...t[s].children):n.push(t[s]);return this.append_none&&n.push(...O([null],this.append_none)),this.node_builder(n)}}const si=P(Le);class ri extends Le{__call__(t){let n=[];for(const[s,r,a]of this.to_include)a&&n.push(...O([null],a)),r?n.length?n.push(...t[s].children):n=t[s].children:n.push(t[s]);return this.append_none&&n.push(...O([null],this.append_none)),this.node_builder(n)}}const ai=P(ri);class oi extends Le{constructor(t,n){super(),this.node_builder=n,this.to_include=t}__call__(t){let n=[];for(const[s,r]of this.to_include)r?n.length?n.push(...t[s].children):n=t[s].children:n.push(t[s]);return this.node_builder(n)}}const li=P(oi);function _i(i){return!i.is_term&&i.name.startsWith("_")}function ci(i,t,n,s){let r,a;s.length?(a=s.map(p=>(0+p).toString()).join(""),r=a.split("0").map(p=>p.length)):r=O([0],i.length+1);let o=[],l=0;for(const[p,c]of X(i))l+=r[p],(t||!(c.is_term&&c.filter_out))&&(o.push([p,_i(c),l]),l=0);if(l+=r[i.length],s.length||o.length<i.length||$n(o.map(([p,c,_])=>c)))return(s.length||n).length?re(n?si:ai,o,l):re(li,o.map(([p,c,_])=>[p,c]))}function pi(i){function t(n){let s=new I(i.name,n);return i(s)}return t=wraps(i)(t),t}function ui(i,t,n){if(n===_vargs_meta||n===_vargs_meta_inline)throw new NotImplementedError("Meta args not supported for internal transformer");function s(r){return n(i,t,r,null)}return s=wraps(i)(s),s}class di{constructor(t,n,s=!1,r=!1,a=!1){this.tree_class=n,this.propagate_positions=s,this.ambiguous=r,this.maybe_placeholders=a,this.rule_builders=[...this._init_builders(t)]}*_init_builders(t){let n,s,r,a,o=ii(this.propagate_positions);for(const l of t)r=l.options,s=r.keep_all_tokens,n=r.expand1,a=[...ct(null,[n&&!l.alias&&ti,ci(l.expansion,s,this.ambiguous,this.maybe_placeholders?r.empty_indices:[]),o])],yield[l,a]}create_callback(t=null){let n,s,r,a=new Map;for(const[o,l]of this.rule_builders){s=o.alias||o.options.template_source||o.origin.name,t&&t[s]?(n=t&&t[s],r=n&&n.visit_wrapper||null,r!==null?n=ui(n,s,r):t instanceof dt&&(n=pi(n))):n=re(this.tree_class,s);for(const p of l)n=p(n);if(a.has(o))throw new ae(f("Rule '%s' already exists",o));a.set(o,n)}return a}}class gt extends E{constructor({parser_conf:t,debug:n=!1}={}){super();let s=new LALR_Analyzer({unknown_param_0:t,debug:n});s.compute_lalr();let r=t.callbacks;this._parse_table=s.parse_table,this.parser_conf=t,this.parser=new xt(s.parse_table,r,n)}static deserialize(t,n,s,r=!1){let a=be(this);return a._parse_table=fi.deserialize(t,n),a.parser=new xt(a._parse_table,s,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:s=null}={}){let r,a;try{return this.parser.parse({lexer:t,start:n})}catch(o){if(o instanceof Q){if(s===null)throw o;for(;;){if(o instanceof M&&(a=o.interactive_parser.lexer_thread.state,r=a.line_ctr.char_pos),!s(o))throw o;o instanceof M&&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 j){if(o instanceof j&&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 M)o=l;else throw l}}}else throw o}}}class hi{constructor(t,n,s){this.parse_table=t,this.start_state=this.parse_table.start_states[s],this.end_state=this.parse_table.end_states[s],this.states=this.parse_table.states,this.callbacks=n,this.start=s}}class Ze{constructor(t,n,s=null,r=null){this.parse_conf=t,this.lexer=n,this.state_stack=s||[this.parse_conf.start_state],this.value_stack=r||[]}get position(){return b(this.state_stack)}eq(t){return t instanceof Ze?this.state_stack.length===t.state_stack.length&&this.position===t.position:W}copy(){return k(this)}feed_token(t,n=!1){let s,r,a,o,l,p,c,_,m,h,y=this.state_stack,d=this.value_stack,u=this.parse_conf.states,g=this.parse_conf.end_state,T=this.parse_conf.callbacks;for(;;){if(m=b(y),t.type in u[m])[r,a]=u[m][t.type];else throw o=new Set(Te(u[m]).filter(A=>pt(A)).map(A=>A)),new j({token:t,expected:o,state:this,interactive_parser:null});if(r===Ce){y.push(a),d.push(t.type in T?T[t.type](t):t);return}else if(p=a,_=p.expansion.length,_?(c=d.slice(-_),y.splice(-_),d.splice(-_)):c=[],h=T.get(p)(c),[s,l]=u[b(y)][p.origin.name],y.push(l),d.push(h),n&&b(y)===g)return b(d)}}}class xt{constructor(t,n,s=!1){this.parse_table=t,this.callbacks=n,this.debug=s}parse({lexer:t,start:n,value_stack:s=null,state_stack:r=null,start_interactive:a=!1}={}){let o=new hi(this.parse_table,this.callbacks,n),l=new Ze(o,t,r,s);return a?new U(this,l,l.lexer):this.parse_from_state(l)}parse_from_state(t){let n,s;try{s=null;for(s of t.lexer.lex(t))t.feed_token(s);return n=s?x.new_borrow_pos("$END","",s):new x("$END","",0,1,1),t.feed_token(n,!0)}catch(r){if(r instanceof Q){try{r.interactive_parser=new U(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 X(t.state_stack))console.log(f("%d)",a),o);console.log("")}throw r}else throw r}}}let U=class jt{constructor(t,n,s){this.parser=t,this.parser_state=n,this.lexer_thread=s,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?x.new_borrow_pos("$END","",t):new x("$END","",0,1,1);return this.feed_token(n)}copy(){return k(this)}eq(t){return t instanceof jt?this.parser_state===t.parser_state&&this.lexer_thread===t.lexer_thread:!1}as_immutable(){let t=k(this);return new wt(t.parser,t.parser_state,t.lexer_thread)}pretty(){let t=["Parser choices:"];for(const[n,s]of w(this.choices()))t.push(f(" - %s -> %r",n,s));return t.push(f("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 s of this.choices())if(pt(s)){t=k(this);let r=null;try{t.feed_token(new x(s,""))}catch(a){if(r=a,!(a instanceof j))throw a}r||n.add(s)}return n}resume_parse(){return this.parser.parse_from_state(this.parser_state)}};class wt extends U{constructor(){super(...arguments),q(this,"result",null)}feed_token(t){let n=k(this);return n.result=U.feed_token(n,t),n}exhaust_lexer(){let t=this.as_mutable();return t.exhaust_lexer(),t.as_immutable()}as_mutable(){let t=k(this);return new U(t.parser,t.parser_state,t.lexer_thread)}}class vt{constructor(t){this.name=t}repr(){return this.toString()}}var Ce=new vt("Shift"),Tt=new vt("Reduce");class mi{constructor(t,n,s){this.states=t,this.start_states=n,this.end_states=s}serialize(t){let n=new Enumerator,s=Object.fromEntries(w(this.states).map(([r,a])=>[r,Object.fromEntries(w(a).map(([o,[l,p]])=>[rt(n,o),l===Tt?[1,p.serialize(t)]:[0,p]]))]));return{tokens:n.reversed(),states:s,start_states:this.start_states,end_states:this.end_states}}static deserialize(t,n){const s=this;let r=t.tokens,a=Object.fromEntries(w(t.states).map(([o,l])=>[o,Object.fromEntries(w(l).map(([p,[c,_]])=>[r[p],c===1?[Tt,V.deserialize(_,n)]:[Ce,_]]))]));return new s(a,t.start_states,t.end_states)}}class fi extends mi{static from_ParseTable(t){const n=this;let s=[...t.states],r=Object.fromEntries(X(s).map(([p,c])=>[c,p])),a={};for(let[p,c]of w(t.states))c=Object.fromEntries(w(c).map(([_,m])=>[_,m[0]===Ce?[m[0],r[m[1]]]:m])),a[r[p]]=c;let o=Object.fromEntries(w(t.start_states).map(([p,c])=>[p,r[c]])),l=Object.fromEntries(w(t.end_states).map(([p,c])=>[p,r[c]]));return new n(a,o,l)}}function yi(i){if(i&&i.__future_interface__)return i;{class t extends ce{constructor(s){super(),this.lexer=i(s)}lex(s,r){return this.lexer.lex(s.text)}}return t}}function gi(i,t,n,s,r){let a=ft.deserialize(i.parser_conf,t),o=gt.deserialize(i.parser,t,s,r.debug);return a.callbacks=s,new xi({lexer_conf:n,parser_conf:a,options:r,parser:o})}var bt={};class xi extends E{static get __serialize_fields__(){return["lexer_conf","parser_conf","parser"]}constructor({lexer_conf:t,parser_conf:n,options:s,parser:r=null}={}){super();let a,o;this.parser_conf=n,this.lexer_conf=t,this.options=s,r?this.parser=r:(o=rt(bt,n.parser_type),this.parser=o(t,n,s));let l=t.lexer_type;if(this.skip_lexer=!1,["dynamic","dynamic_complete"].includes(l)){this.skip_lexer=!0;return}const p={basic:bi,contextual:Ei};l in p?(a=p[l],this.lexer=a(t,this.parser,t.postlex,s)):this.lexer=yi(l)(t),t.postlex&&(this.lexer=new Ti(this.lexer,t.postlex))}_verify_start(t=null){let n;if(t===null){if(n=this.parser_conf.start,n.length>1)throw new $("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 $(f("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:ht.from_text(this.lexer,t)}parse(t,n=null,s=null){let r=this._verify_start(n),a=s===null?{}:{on_error:s},o=this._make_lexer_thread(t);return this.parser.parse({lexer:o,start:r,...a})}parse_interactive(t=null,n=null){let s=this._verify_start(n);if(this.parser_conf.parser_type!=="lalr")throw new $("parse_interactive() currently only works with parser='lalr' ");let r=this._make_lexer_thread(t);return this.parser.parse_interactive(r,s)}}function wi(i,t){let n;qe(i,["lalr","earley","cyk"]),typeof t!="object"&&(n={lalr:["basic","contextual"],earley:["basic","dynamic","dynamic_complete"],cyk:["basic"]}[i],qe(t,n,f("Parser %r does not support lexer %%r, expected one of %%s",i)))}function vi(i,t){let n,s={};for(const r of t)n=i&&i[r.name]||null,n!==null&&(s[r.name]=n);return s}class Ti{constructor(t,n){this.lexer=t,this.postlexer=n}lex(t,n){let s=this.lexer.lex(t,n);return this.postlexer.process(s)}}function bi(i,t,n,s){return new pe(i)}function Ei(i,t,n,s){let r=Object.fromEntries(w(t._parse_table.states).map(([o,l])=>[o,[...Te(l)]])),a=n?n.always_accept:[];return new Kn({conf:i,states:r,always_accept:a})}function Ii(i,t,n=null){let s=n?n.debug:!1;return new gt({parser_conf:t,debug:s})}bt.lalr=Ii;class Et extends st{constructor(){super(...arguments),q(this,"always_accept",[])}process(t){return t}}class Ri extends E{constructor(t){super(),q(this,"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 '),q(this,"_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});let n,s=lt(t),r=this;for(const[a,o]of w(this._defaults))a in s?(n=qn(s,a),typeof o=="boolean"&&!["cache","use_bytes","propagate_positions"].includes(a)&&(n=_t(n))):n=o,r[a]=n;if(typeof r.start=="string"&&(r.start=[r.start]),this.options=r,qe(this.parser,["earley","lalr","cyk",null]),this.parser==="earley"&&this.transformer)throw new $("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(s).length)throw new $(f("Unknown options: %s",Te(s)))}serialize(t){return this.options}static deserialize(t,n){const s=this;return new s(t)}}class It extends E{static get __serialize_fields__(){return["parser","rules","options"]}_build_lexer(t=!1){let n=this.lexer_conf;return t&&(n=k(n),n.ignore=[]),new pe(n)}_prepare_callbacks(){this._callbacks=new Map,this.options.ambiguity!=="forest"&&(this._parse_tree_builder=new di(this.rules,this.options.tree_class||kn(I),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)),at(this._callbacks,vi(this.options.transformer,this.terminals))}_deserialize_lexer_conf(t,n,s){let r=mt.deserialize(t.lexer_conf,n);return r.callbacks=s.lexer_callbacks||{},r.re_module=s.regex?regex:tt,r.use_bytes=s.use_bytes,r.g_regex_flags=s.g_regex_flags||"",r.skip_validation=!0,r.postlex=s.postlex,r}_load({f:t,...n}={}){let s;Ee(t)?s=t:s=pickle.load(t);let r=s.memo,a=s.data,o=Qn.deserialize(r,{Rule:V,TerminalDef:_e},{}),l=lt(a.options);return at(l,n),this.options=Ri.deserialize(l,o),this.rules=a.rules.map(p=>V.deserialize(p,o)),this.source_path="<deserialized>",wi(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=gi(a.parser,o,this.lexer_conf,this._callbacks,this.options),this}static _load_from_dict({data:t,memo:n,...s}={}){return be(this)._load({f:{data:t,memo:n},...s})}repr(){return f("Lark(open(%r), parser=%r, lexer=%r, ...)",this.source_path,this.options.parser,this.options.lexer)}lex(t,n=!1){let s;!("lexer"in this)||n?s=this._build_lexer(n):s=this.lexer;let r=ht.from_text(s,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,s=null){return this.parser.parse(t,n,s)}}class Rt extends S{}class Nt extends Et{constructor(){super(),this.paren_level=0,this.indent_level=[0]}*handle_NL(t){if(this.paren_level>0)return;yield t;let n=Re(t.value,`
|
|
21
|
-
`,1)[1],s=Ne(n," ")+Ne(n," ")*this.tab_len;if(s>b(this.indent_level))this.indent_level.push(s),yield x.new_borrow_pos(this.INDENT_type,n,t);else{for(;s<b(this.indent_level);)this.indent_level.pop(),yield x.new_borrow_pos(this.DEDENT_type,n,t);if(s!==b(this.indent_level))throw new Rt(f("Unexpected dedent to column %s. Expected dedent to %s",s,b(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 x(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 Ni extends Nt{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 qi={Terminal:Se,NonTerminal:$e,RuleOptions:le,PatternStr:De,PatternRE:Pe,TerminalDef:_e};var ki={LarkError:S,ConfigurationError:$,GrammarError:ae,ParseError:Pn,LexError:H,UnexpectedInput:Q,UnexpectedEOF:Ln,UnexpectedCharacters:M,UnexpectedToken:j,VisitError:ke,Meta:ut,Tree:I,Discard:ie,Transformer:J,Transformer_InPlace:dt,Transformer_NonRecursive:Mn,Transformer_InPlaceRecursive:jn,VisitorBase:Ae,Visitor:Un,Visitor_Recursive:Fn,Interpreter:Zn,Symbol:Oe,Terminal:Se,NonTerminal:$e,RuleOptions:le,Rule:V,Pattern:ze,PatternStr:De,PatternRE:Pe,TerminalDef:_e,Token:x,Lexer:ce,LexerConf:mt,ParserConf:ft,InteractiveParser:U,ImmutableInteractiveParser:wt,PostLex:Et,Lark:It,DedentError:Rt,Indenter:Nt,PythonIndenter:Ni,get_parser:Rn},Ai={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"},Oi={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"}},Si=Object.defineProperty,$i=(i,t,n)=>t in i?Si(i,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):i[t]=n,F=(i,t,n)=>($i(i,typeof t!="symbol"?t+"":t,n),n),zi=(i,t,n)=>{if(!t.has(i))throw TypeError("Cannot "+n)},qt=(i,t,n)=>{if(t.has(i))throw TypeError("Cannot add the same private member more than once");t instanceof WeakSet?t.add(i):t.set(i,n)},Y=(i,t,n)=>(zi(i,t,"access private method"),n),K,ue,de,Qe;const Me=/\$\{q\:(?<locator>[\-a-zA-Z0-9_\/\(\)]+)\}/g,kt=i=>{var t,n;return(n=(t=i.choiceId)!=null?t:i.choiceValue)!=null?n:i.text};class he{constructor(t,n=[],s="",r=!1){qt(this,K),qt(this,de),F(this,"questions",new Map),F(this,"responsesByQuestion",new Map),F(this,"responsesByQuestionStatement",new Map),F(this,"surveyResponseId"),F(this,"forExport"),F(this,"evaluationCache",new Map),this.questions=new Map((t?ve(t):[]).filter(a=>a.id).map(a=>[xe(a.id),a])),n.filter(a=>a.singleAnswer||a.multipleAnswers).forEach(a=>{const o=xe(a.questionId);this.responsesByQuestion.set(o,[...this.responsesByQuestion.get(o)||[],a]),a.statementId&&this.responsesByQuestionStatement.set(`${o}.${a.statementId}`,a)}),this.surveyResponseId=s,this.forExport=r}getQuestionAnswers(t,n){let s;if(n){const r=this.responsesByQuestionStatement.get(`${t}.${n}`);s=r===void 0?[]:[r]}else s=this.responsesByQuestion.get(t)||[];return s.flatMap(r=>{const{multipleAnswers:a,singleAnswer:o}=r;return a||[o]})}evaluateDisplayLogic(t){if(t&&!this.forExport)try{const n=this.evaluationCache.get(t);if(n!==void 0)return n;const s=je(t,this);return this.evaluationCache.set(t,s),s}catch(n){return console.error(n),!1}return!0}evaluateDynamicExpression(t,n){const s=this.questions.get(t.questionId);if(!s)return[];const r=this.getQuestionChoicesFlattened(s),a=r.filter(_=>this.isSelected({questionId:t.questionId,choice:_.id||_.value})),o=this.getQuestionStatementsFlattened(s),l=_=>n==="choices"?_:{..._,id:_.id||_.value||_.display},p=_=>({id:_.id,display:_.display,value:_.value});let c=[];switch(t.expression){case v.ALL:c=r.map(l);break;case v.ALL_ENTERED_TEXT:c=r.map(_=>Y(this,de,Qe).call(this,_,t)).filter(_=>!!_).map(_=>l(_));break;case v.SELECTED:c=a;break;case v.SELECTED_ENTERED_TEXT:c=a.map(_=>Y(this,de,Qe).call(this,_,t)).filter(_=>!!_).map(_=>l(_));break;case v.NOT_SELECTED:c=r.filter(_=>!this.isSelected({questionId:t.questionId,choice:_.id||_.value})).map(l);break;case v.FOR_MATRIX_CHOICE:c=o.filter(_=>this.isSelected({questionId:t.questionId,statementId:_.id,choice:t.identifier}));break;case v.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===v.FOR_MATRIX_CHOICE||t.expression===v.UNSELECTED_FOR_MATRIX_CHOICE?o:r.map(l)),c.map(p)}isSelected(t){return!!Y(this,K,ue).call(this,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?kt(n[0]):null}countChoiceSelections(t,n){return Y(this,K,ue).call(this,t,null,n).length}textEntry(t){return Y(this,K,ue).call(this,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(Me,(s,r)=>{if(r&&He(r)){const a=D(r);return this.evaluateDynamicExpression(a,"choices").map(o=>o.display).join(", ")}return s}),n}getQuestionChoices(t){var n;const s=((n=t.choices)!=null?n:[]).filter(r=>this.evaluateDisplayLogic(r.displayLogic));if(t.dynamicChoices){const r=D(t.dynamicChoices),a=this.evaluateDynamicExpression(r,"choices");s.push(...a)}return t.type===N.MatrixSingle||t.type===N.MatrixMulti?s:this.applyRandomization(s,t.id,r=>{var a;return`${(a=r.id)!=null?a:r.value}`},t.randomization)}getQuestionChoiceGroups(t){var n;const s=(((n=t.choiceGroups)==null?void 0:n.filter(r=>this.evaluateDisplayLogic(r.displayLogic)))||[]).map(r=>({...r,choices:this.applyRandomization(r.choices.filter(a=>this.evaluateDisplayLogic(a.displayLogic)),t.id,a=>{var o;return`${(o=a.id)!=null?o:a.value}`},r.randomization)})).filter(r=>!!r.choices.length);return this.applyRandomization(s,t.id,r=>r.id,t.randomization)}getQuestionStatements(t){var n;const s=((n=t.statements)!=null?n:[]).filter(r=>this.evaluateDisplayLogic(r.displayLogic));if(t.dynamicStatements){const r=D(t.dynamicStatements),a=this.evaluateDynamicExpression(r,"statements");s.push(...a)}return this.applyRandomization(s,t.id,r=>r.id,t.randomization)}getQuestionStatementGroups(t){var n;const s=(((n=t.statementGroups)==null?void 0:n.filter(r=>this.evaluateDisplayLogic(r.displayLogic)))||[]).map(r=>({...r,statements:this.applyRandomization(r.statements.filter(a=>this.evaluateDisplayLogic(a.displayLogic)),t.id,a=>a.id,r.randomization)})).filter(r=>!!r.statements.length);return this.applyRandomization(s,t.id,r=>r.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,s,r){var a,o;if(!r||this.forExport)return t;const l=new Map(t.map(u=>[s(u),u])),p=[...l.keys()],c=new Set(p),_=((a=r.order)!=null?a:["$"]).filter(u=>u==="$"||c.has(u)),m=p.filter(u=>!_.includes(u)).map(u=>({weight:this.keyHash(n,u),key:u}));m.sort((u,g)=>u.weight.localeCompare(g.weight));const h=(o=r.total)!=null?o:p.length,y=Math.min(h-(_.length-1),m.length),d=[];return _.forEach(u=>{u==="$"?d.push(...m.slice(0,y).map(g=>g.key)):d.push(u)}),d.map(u=>l.get(u))}keyHash(t,n){const s=`${t}.${this.surveyResponseId}.${n}`;return Vt.createHash("sha256").update(s).digest("hex")}}K=new WeakSet,ue=function(i,t,n){return this.getQuestionAnswers(i,t).filter(s=>typeof n=="undefined"||n===null||kt(s)===n)},de=new WeakSet,Qe=function(i,t){if(i.textInput&&["forced","optional"].includes(i.textInput)){const n=this.textEntry({questionId:t.questionId,choice:i.id||i.value});return n.trim()?{...i,display:n}:i.textInput==="forced"?null:i}return i};function At(i){if(i.length===1)return i[0];const t=i[1].value;return t==="or"?i[0]||i[2]:t==="and"?i[0]&&i[2]:!1}function me(i,t,n){switch(t){case"==":return i===n;case"!=":return i!==n;case"<=":return i<=n;case">=":return i>=n;case"<":return i<n;case">":return i>n;default:return!1}}function Ot(i,t,n,s){const r=s?i.toLowerCase():i,a=s?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 me(r,t,a)}}function Di(i,t){return i.length>0&&i[0].hasOwnProperty("type")&&i[0].type==="NEGATION"?!t(i.slice(1)):t(i)}function Pi(i){if(!["INT","IDENTIFIER"].includes(i.type))throw new SyntaxError(`Invalid token type: ${i.type}; expected IDENTIFIER or INT`);return R(i)}function R(i){var t,n;switch(i.type){case"IDENTIFIER":return i.value;case"INT":return parseInt(i.value,10);case"STRING":{const s=i.value.match(/(?:'(?<single>[^\']*)')|(?:"(?<double>[^\"]*)")/),r=((t=s==null?void 0:s.groups)==null?void 0:t.double)||((n=s==null?void 0:s.groups)==null?void 0:n.single);return Gt(r),r}case"OPERATOR":return i.value;case"TRUE":return!0;case"FALSE":return!1;default:throw new SyntaxError(`Invalid token type: ${i.type}`)}}function je(i,t){const n={bool_const:s=>s[0].value==="true",condition:s=>s[0],bool_expr:At,top_level_expr:At,start:s=>s[0],question_id:s=>s[0].value,choice_ref:s=>Pi(s[0]),matrix_statement_id:s=>({questionId:s[0],statementId:s[1].value}),question_choice_selected:s=>Di(s,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:s=>{const r=t.selectedValue(s[0]);return r!==null&&me(r,R(s[1]),R(s[2]))},question_choice_text_comparison:s=>Ot(t.textEntry({questionId:s[0],choice:s[1]}),R(s[2]),R(s[3]),!1),question_choice_text_comparison_case_insensitive:s=>Ot(t.textEntry({questionId:s[0],choice:s[1]}),R(s[2]),R(s[3]),!0),selected_count_comparison:s=>me(t.countSelected(s[0]),R(s[1]),R(s[2])),choice_selection_count_comparison:s=>me(t.countChoiceSelections(s[0],s[1]),R(s[2]),R(s[3]))};return ki.get_parser({transformer:n}).parse(i)}var Li=Object.defineProperty,Ci=(i,t,n)=>t in i?Li(i,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):i[t]=n,L=(i,t,n)=>(Ci(i,typeof t!="symbol"?t+"":t,n),n);const St=new Zt({allowUnionTypes:!0});Bt(St);const $t=St.compile(Ve);class ee extends Error{}class z extends Error{}class fe extends Error{}class C extends Error{}class Qi extends Error{}class Mi{constructor(){L(this,"seenQuestions",new Set),L(this,"seenMultiQuestions",new Set),L(this,"seenQuestionStatements",new Map),L(this,"seenQuestionChoices",new Map),L(this,"seenTextChoices",new Map),L(this,"evaluator",{}),L(this,"validateReference",t=>{var n,s,r;if(!this.seenQuestions.has(t.questionId))throw new ee(`Invalid question: ${t.questionId}`);if(t.statementId!==void 0&&!((n=this.seenQuestionStatements.get(t.questionId))!=null&&n.has(t.statementId)))throw new ee(`Invalid statement: ${t.questionId}.${t.statementId}`);if(t.choice!==void 0&&!((s=this.seenQuestionChoices.get(t.questionId))!=null&&s.has(t.choice)))throw new ee(`Invalid choice: ${t.questionId}[${t.choice}]`);if(t.choice!==void 0&&t.expectText===!0&&!((r=this.seenTextChoices.get(t.questionId))!=null&&r.has(t.choice)))throw new ee(`Invalid text reference: ${t.questionId}[${t.choice}]`);if(typeof t.expectMulti=="boolean"&&t.expectMulti&&!this.seenMultiQuestions.has(t.questionId))throw new z(`Invalid question reference: ${t.questionId}. Expected a multi-answer question.`);if(typeof t.expectMulti=="boolean"&&!t.expectMulti&&this.seenMultiQuestions.has(t.questionId))throw new z(`Invalid question reference: ${t.questionId}. Expected a non-multi-answer question.`)}),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}),"")}}const Z=(i,t,n)=>{if(n)try{je(n,i.evaluator)}catch(s){throw s instanceof ee||s instanceof z||s instanceof C?s:new Error(`Syntax error parsing display logic at ${t}: ${n}`)}},ji=(i,t)=>{[...t.matchAll(Me)].forEach(n=>{var s;const r=D(n.groups.locator);if(!i.seenQuestions.has(r.questionId))throw new z(`Invalid question referenced in locator expression: ${r.questionId}/${r.expression}`);if(r.identifier&&!((s=i.seenQuestionChoices.get(r.questionId))!=null&&s.has(r.identifier)))throw new z(`Invalid question choice referenced in locator expression: ${r.questionId}/${r.expression}(${r.identifier})`)})},B=(i,t,n)=>{if(n){const s=new Set(t);if(n.order){const r=n.order.split(" "),a=r.filter(o=>o==="$").length;if(a===0)throw new fe(`Wildcard $ is missing in randomization order at ${i.id}`);if(a>1)throw new fe(`Wildcard $ occurred multiples times in randomization order at ${i.id}`);if(r.forEach(o=>{if(o!=="$"&&!s.has(o))throw new fe(`Unknown id ${o} in randomization ordering at ${i.id}`)}),n.total!==void 0&&n.total<r.length)throw new fe(`Total value in randomization is too small at ${i.id}`)}}},zt=(i,t)=>{const n=[v.FOR_MATRIX_CHOICE,v.UNSELECTED_FOR_MATRIX_CHOICE].includes(i.expression),s=(n?t.seenQuestionStatements:t.seenQuestionChoices).get(i.questionId);if(s===void 0)throw new z(`Invalid question referenced in locator expression: ${i.questionId}/${i.expression}`);if(n){const r=t.seenQuestionChoices.get(i.questionId);if(!i.identifier||!(r!=null&&r.has(i.identifier)))throw new z(`Invalid choice referenced in locator expression: ${i.questionId}/${i.expression}(${i.identifier})`)}return s},Ui=(i,t)=>{var n,s,r,a,o,l,p,c,_,m,h;if(ji(t,i.text),i.id!==void 0){if(Z(t,i.id,i.display_logic),(n=i.statements)==null||n.forEach(d=>{Z(t,`${i.id}.${d.id}`,d.display_logic)}),(s=i.choices)==null||s.forEach(d=>{Z(t,`${i.id}[${d.id||d.value}]`,d.display_logic)}),i.type==="matrix-multi"||i.type==="matrix-single"?i.statement_groups?B(i,i.statement_groups.map(d=>d.id),i.randomization):B(i,(a=(r=i.statements)==null?void 0:r.map(d=>d.id))!=null?a:[],i.randomization):i.choice_groups?B(i,i.choice_groups.map(d=>d.id),i.randomization):B(i,(l=(o=i.choices)==null?void 0:o.map(d=>`${d.id||d.value}`))!=null?l:[],i.randomization),(p=i.statement_groups)==null||p.forEach(d=>{d.statements.forEach(u=>{Z(t,`${i.id}.${u.id}`,u.display_logic)}),B(i,d.statements.map(u=>u.id),d.randomization)}),(c=i.choice_groups)==null||c.forEach(d=>{d.choices.forEach(u=>{Z(t,`${i.id}[${u.id||u.value}]`,u.display_logic)}),B(i,d.choices.map(u=>`${u.id||u.value}`),d.randomization)}),t.seenQuestions.has(i.id))throw new C(`Duplicate question id: ${i.id}`);if(t.seenQuestions.add(i.id),i.type&&["matrix-multi","mc-multi"].includes(i.type)&&t.seenMultiQuestions.add(i.id),i.statements||i.dynamic_statements){const d=new Set;if(t.seenQuestionStatements.set(i.id,d),(_=i.statements)==null||_.forEach(u=>{if(d.has(u.id))throw new C(`Duplicate statement id: ${i.id}.${u.id}`);d.add(u.id)}),i.dynamic_statements){const u=D(i.dynamic_statements);zt(u,t).forEach(g=>{if(typeof g=="number")throw new z(`Dynamic statement in question ${i.id} refers to choices with values`);if(d.has(g))throw new C(`Duplicate statement ${g} via dynamic statements in question ${i.id}`);d.add(g)})}}const y=(m=i.choices)!=null?m:[];if(i.choice_groups){if(new Set(i.choice_groups.map(d=>d.id)).size!==i.choice_groups.length)throw new C(`Choice groups must have a unique id in question ${i.id}`);i.choice_groups.forEach(d=>y.push(...d.choices))}if(y||i.dynamic_choices){const d=new Set;t.seenQuestionChoices.set(i.id,d);const u=new Set;if(t.seenTextChoices.set(i.id,u),y.forEach(g=>{var T;const A=(T=g.id)!=null?T:g.value;if(d.has(A))throw new C(`Duplicate choice: ${i.id}[${A}]`);d.add(A),g.text_input&&g.text_input!=="no"&&u.add(A)}),i.dynamic_choices){const g=D(i.dynamic_choices);zt(g,t).forEach(T=>{if(d.has(T))throw new C(`Duplicate choice ${T} via dynamic choices in ${i.id}`);d.add(T)}),(h=t.seenTextChoices.get(g.questionId))==null||h.forEach(T=>u.add(T))}if(new Set([...d].map(g=>typeof g)).size>=2)throw new Qi("All choices in a question must either all have id's or all have values")}}},Fi=i=>{if(!$t(i))throw new Error(`Invalid template: ${i.template.id}. Reason: ${JSON.stringify($t.errors,null,4)}`);We(i);const t=new Mi;i.sections.forEach(n=>{Z(t,n.id,n.display_logic),n.pages.forEach(s=>{var r;(r=s.questions)==null||r.forEach(a=>{Ui(a,t)})})})};function Dt(i,t){const n=structuredClone(i);return{...n,sections:n.sections.map(s=>({id:s.id,name:s.name,hideProgressBar:s.hideProgressBar,pages:t.evaluateDisplayLogic(s.displayLogic)?s.pages.map(r=>({...r,questions:Zi(r.questions,t)})).filter(r=>r.questions.length):[]})).filter(s=>s.pages.length)}}function Zi(i,t){return i.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 Pt=i=>!!(i!=null&&i.singleAnswer)||!!(i!=null&&i.multipleAnswers)&&(i==null?void 0:i.multipleAnswers.length)>0,Lt=(i,t)=>{let n=!1,s=t,r=new he(i,s);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=>{var _;if(c.singleAnswer){const h=!!c.singleAnswer.text||p.includes(c.singleAnswer.choiceId||c.singleAnswer.choiceValue);return h||(n=!0),{...c,singleAnswer:h?c.singleAnswer:void 0}}const m=(_=c.multipleAnswers)==null?void 0:_.filter(h=>!!h.text||p.includes(h.choiceId||h.choiceValue));return m&&m.length<c.multipleAnswers.length&&(n=!0),{...c,multipleAnswers:m}};for(const p of i.sections){if(!r.evaluateDisplayLogic(p.displayLogic)){const c=p.pages.flatMap(_=>_.questions).map(_=>_.id);s=s.filter(a(c)),n&&(n=!1,r=new he(i,s));continue}for(const c of p.pages)for(const _ of c.questions){if(!r.evaluateDisplayLogic(_.displayLogic))s=s.filter(a([_.id]));else{const m=r.getQuestionStatementsFlattened(_).map(u=>u.id),h=r.getQuestionChoicesFlattened(_).map(u=>u.id||u.value),y=o(m),d=l(h);s=s.filter(u=>u.questionId!==_.id||y(u)),s=s.map(u=>u.questionId!==_.id?u:d(u))}n&&(n=!1,r=new he(i,s))}}return s},Ct=(i,t)=>t?`${i}.${t}`:i,Bi=(i,t,n,s)=>{var r;if(!t.singleAnswer)return s==null||s.warn("Response validation failed: No SingleAnswer provided in single answer question.",{surveyResponseId:n.surveyResponseId,questionId:t.questionId}),!1;const a=new Set(n.getQuestionChoicesFlattened(i).map(l=>{var p;return(p=l.id)!=null?p:l.value})),o=(r=t.singleAnswer.choiceId)!=null?r:t.singleAnswer.choiceValue;return a.has(o)?!0:(s==null||s.warn("Response validation failed: Selected choice in single answer question not available",{surveyResponseId:n.surveyResponseId,questionId:i.id,choiceKey:o}),!1)},Gi=(i,t,n,s)=>{if(!t.multipleAnswers)return s==null||s.warn("Response validation failed: No MultipleAnswer provided in multi answer question",{surveyResponseId:n.surveyResponseId,questionId:t.questionId}),!1;const r=new Set(n.getQuestionChoicesFlattened(i).map(o=>{var l;return(l=o.id)!=null?l:o.value}));let a=!1;return t.multipleAnswers.forEach(o=>{var l;const p=(l=o.choiceId)!=null?l:o.choiceValue;r.has(p)||(s==null||s.warn("Response validation failed: Selected choice in multi answer question not available",{surveyResponseId:n.surveyResponseId,questionId:i.id,choiceKey:p}),a=!0)}),!a},Vi=(i,t,n)=>{var s;return(s=i.singleAnswer)!=null&&s.text?!0:(n==null||n.warn("Response validation failed: No text provided",{surveyResponseId:t.surveyResponseId,questionId:i.questionId}),!1)};function Qt(i,t,n,s){if(!Pt(t))return!0;switch(we(i.type)){case N.McSingle:case N.MatrixSingle:return Bi(i,t,n,s);case N.McMulti:case N.MatrixMulti:return Gi(i,t,n,s);case N.TextSingle:case N.TextMulti:return Vi(t,n,s);default:return s==null||s.warn("Response validation failed: Unsupported question type",{questionId:i.id,questionType:i.type,surveyResponseId:n.surveyResponseId}),!1}}function Wi(i,t,n,s){const r={templateId:i.id,surveyResponseId:n.surveyResponseId};s==null||s.debug("Validating response...",{questionResponses:t,...r});const a=Dt(i,n),o=ve(a),l=Lt(a,t);if(new Set(l.map(_=>Ct(_.questionId,_.statementId))).size<l.length)return s==null||s.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 m=p[_.questionId];if(!m)return s==null||s.warn("Response validation failed: Response provided to a question that's not in the template",{questionId:_.questionId,...r}),!1;let h=c.get(_.questionId);if(h===void 0&&(h=new Map(n.getQuestionStatementsFlattened(m).map(y=>[y.id,y])),c.set(_.questionId,h)),_.statementId){if(!h||!h.size)return s==null||s.warn("Response validation failed: Response provided to a statement even to the question has no statements",{questionId:_.questionId,statementId:_.statementId,...r}),!1;if(!h.get(_.statementId))return s==null||s.warn("Response validation failed: Response provided to an invalid question statement",{questionId:_.questionId,statementId:_.statementId,...r}),!1}else if(h&&h.size)return s==null||s.warn("Response validation failed; Response provided to a question with statements but not statement provided.",{questionId:_.questionId,statementId:_.statementId,...r}),!1;if(!Qt(m,_,n,s))return!1}return!0}const Xi=Ve,Hi="pulse_default_alpha",Ji={allPermissions:Xt,SURVEY_RESOURCE_TYPE:Wt,surveyAdministerPermission:Be};export{Hi as DEFAULT_TEMPLATE_ID,v as LOCATOR_EXPRESSION,Me as QUESTION_TEXT_LOCATOR_PATTERN,he as TemplateContextEvaluator,je as evaluateExpression,Dt as evaluateTemplateNode,ve as extractQuestionNodes,Ht as getExperimentalOptionalBoolean,Jt as getExperimentalOptionalString,Ye as getQualifiedQuestionId,we as getQuestionTypeEnum,Je as getRandomizationTypeEnum,xe as getRawQuestionId,Lt as getRelevantQuestionResponses,xn as getTemplateNode,Pt as hasAnswer,ye as interpolateMacros,We as interpolateTemplate,D as parseLocator,Ji as permissions,Yt as polyfillStructuredClone,Ct as responseRef,Xi as templateSchema,ne as transformCase,He as validateLocator,Qt as validateQuestionResponse,Wi as validateResponse,Fi as validateTemplate};
|
|
1
|
+
import{allPermissions as e,SURVEY_RESOURCE_TYPE as t,surveyAdministerPermission as o}from"./permissions.esm.js";import{getExperimentalOptionalBoolean as n,getExperimentalOptionalString as p}from"./config.esm.js";import{polyfillStructuredClone as l}from"./polyfills.esm.js";import{DEFAULT_TEMPLATE_ID as T,templateSchema as x}from"./templates/index.esm.js";import{transformCase as f}from"./transformCase.esm.js";import{validateTemplate as d}from"./templates/validateTemplate.esm.js";import{evaluateTemplateNode as O,getRelevantQuestionResponses as S,hasAnswer as _}from"./templates/evaluation.esm.js";import{extractQuestionNodes as P,getQualifiedQuestionId as A,getQuestionTypeEnum as Q,getRandomizationTypeEnum as c,getRawQuestionId as C,getTemplateNode as L}from"./templates/convertTemplateToNode.esm.js";import{interpolateMacros as U,interpolateTemplate as y}from"./templates/interpolation.esm.js";import{LOCATOR_EXPRESSION as Y,parseLocator as h,validateLocator as w}from"./templates/locators.esm.js";import{QUESTION_TEXT_LOCATOR_PATTERN as M,TemplateContextEvaluator as V,evaluateExpression as X}from"./templates/logic.esm.js";import{responseRef as B,validateQuestionResponse as F,validateResponse as b}from"./templates/validateResponse.esm.js";const r={allPermissions:e,SURVEY_RESOURCE_TYPE:t,surveyAdministerPermission:o};export{T as DEFAULT_TEMPLATE_ID,Y as LOCATOR_EXPRESSION,M as QUESTION_TEXT_LOCATOR_PATTERN,V as TemplateContextEvaluator,X as evaluateExpression,O as evaluateTemplateNode,P as extractQuestionNodes,n as getExperimentalOptionalBoolean,p as getExperimentalOptionalString,A as getQualifiedQuestionId,Q as getQuestionTypeEnum,c as getRandomizationTypeEnum,C as getRawQuestionId,S as getRelevantQuestionResponses,L as getTemplateNode,_ as hasAnswer,U as interpolateMacros,y as interpolateTemplate,h as parseLocator,r as permissions,l as polyfillStructuredClone,B as responseRef,x as templateSchema,f as transformCase,w as validateLocator,F as validateQuestionResponse,b as validateResponse,d as validateTemplate};
|
|
23
2
|
//# sourceMappingURL=index.esm.js.map
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import{createPermission as s}from"@backstage/plugin-permission-common";const i="survey-instance",e=s({name:"survey.instance.administer",attributes:{action:"create"}}),r=[e];export{i as SURVEY_RESOURCE_TYPE,r as allPermissions,e as surveyAdministerPermission};
|
|
2
|
+
//# sourceMappingURL=permissions.esm.js.map
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import{transformCase as u}from"../transformCase.esm.js";function l(t){const n=structuredClone(t);return{...n,...n.template,sections:n.sections.map(e=>({...u(e),pages:e.pages.map((o,r)=>({...o,id:`${e.id}-${r}`,questions:c(n,e,o.questions)}))}))}}function c(t,n,e){return e.map(o=>m(t.template.id,n,o))}function m(t,n,e){var o,r;return{...u({...e,choiceGroups:(o=e.choice_groups)==null?void 0:o.map(i=>({...i,randomization:a(i.randomization)})),statementGroups:(r=e.statement_groups)==null?void 0:r.map(i=>({...i,randomization:a(i.randomization)})),randomization:a(e.randomization)}),id:s(t,e),type:d(e.type),layout:g(e.layout),required:y(e.required),label:n.name}}function a(t){var n;return t?{type:p(t.type),order:(n=t.order)==null?void 0:n.split(" "),total:t.total}:void 0}function p(t){return t.toUpperCase()}function s(t,n){return`${t}.${n.id}`}const f=t=>t.split(".").pop();function d(t="description"){return t.replace("-","_").toUpperCase()}function g(t){return t==null?void 0:t.toUpperCase()}function y(t="optional"){return t.replace("-","_").toUpperCase()}function v(t){return structuredClone(t).sections.flatMap(n=>n.pages.flatMap(e=>e.questions))}export{v as extractQuestionNodes,s as getQualifiedQuestionId,d as getQuestionTypeEnum,p as getRandomizationTypeEnum,f as getRawQuestionId,l as getTemplateNode};
|
|
2
|
+
//# sourceMappingURL=convertTemplateToNode.esm.js.map
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import{TemplateContextEvaluator as p}from"./logic.esm.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(l=>({...l,questions:v(l.questions,o)})).filter(l=>l.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!=null&&i.singleAnswer)||!!(i!=null&&i.multipleAnswers)&&(i==null?void 0:i.multipleAnswers.length)>0,y=(i,o)=>{let e=!1,t=o,l=new p(i,t);const g=u=>n=>{const s=u.includes(n.questionId);return s&&(e=!0),!s},d=u=>n=>{const s=!n.statementId||u.includes(n.statementId);return s||(e=!0),s},m=u=>n=>{var s;if(n.singleAnswer){const a=!!n.singleAnswer.text||u.includes(n.singleAnswer.choiceId||n.singleAnswer.choiceValue);return a||(e=!0),{...n,singleAnswer:a?n.singleAnswer:void 0}}const c=(s=n.multipleAnswers)==null?void 0:s.filter(a=>!!a.text||u.includes(a.choiceId||a.choiceValue));return c&&c.length<n.multipleAnswers.length&&(e=!0),{...n,multipleAnswers:c}};for(const u of i.sections){if(!l.evaluateDisplayLogic(u.displayLogic)){const n=u.pages.flatMap(s=>s.questions).map(s=>s.id);t=t.filter(g(n)),e&&(e=!1,l=new p(i,t));continue}for(const n of u.pages)for(const s of n.questions){if(!l.evaluateDisplayLogic(s.displayLogic))t=t.filter(g([s.id]));else{const c=l.getQuestionStatementsFlattened(s).map(r=>r.id),a=l.getQuestionChoicesFlattened(s).map(r=>r.id||r.value),f=d(c),h=m(a);t=t.filter(r=>r.questionId!==s.id||f(r)),t=t.map(r=>r.questionId!==s.id?r:h(r))}e&&(e=!1,l=new p(i,t))}}return t};export{w as evaluateTemplateNode,y as getRelevantQuestionResponses,A as hasAnswer};
|
|
2
|
+
//# sourceMappingURL=evaluation.esm.js.map
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import t from"./schema/survey-template-schema.json.esm.js";import{validateTemplate as l}from"./validateTemplate.esm.js";import{QUESTION_TEXT_LOCATOR_PATTERN as _,TemplateContextEvaluator as i,evaluateExpression as s}from"./logic.esm.js";import"lodash";import{LOCATOR_EXPRESSION as L,parseLocator as O,validateLocator as c}from"./locators.esm.js";import"../graphql/schema-types.generated.esm.js";const o=t,e="pulse_default_alpha";export{e as DEFAULT_TEMPLATE_ID,L as LOCATOR_EXPRESSION,_ as QUESTION_TEXT_LOCATOR_PATTERN,i as TemplateContextEvaluator,s as evaluateExpression,O as parseLocator,o as templateSchema,c as validateLocator,l as validateTemplate};
|
|
2
|
+
//# sourceMappingURL=index.esm.js.map
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
const a=/\$\{m:([^\}]+)\}/g,l=100,n=(t,o)=>{if(typeof o=="string"){let e=o,i=0;for(;i<100;){const r=e.replace(a,(f,c)=>{if(t[c]===void 0)throw new Error(`Undefined macro: ${c}`);return t[c]});if(r===e)return r;e=r,i+=1}throw new Error(`Failed to finish interpolate macros - cyclic macros!? Stuck at: ${o}"`)}return typeof o=="object"&&Object.keys(o).forEach(e=>{o[e]=n(t,o[e])}),o},s=t=>(t.sections=n(t.macros||{},t.sections),t);export{n as interpolateMacros,s as interpolateTemplate};
|
|
2
|
+
//# sourceMappingURL=interpolation.esm.js.map
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
const d="(?<questionId>[a-zA-Z][a-zA-Z0-9_]*)",c="((?<expressionWithoutIdentifier>all|all_entered_text|selected|selected_entered_text|not_selected)|(?<expressionWithIdentifier>for_matrix_choice|unselected_for_matrix_choice)(\\((?<identifier>[\\-a-zA-Z0-9_]+)\\)))",n=new RegExp(`^${d}/${c}$`);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 E=e=>n.test(e),a=e=>{var i;const t=(i=e.match(n))==null?void 0:i.groups;if(!t)throw new Error(`Invalid locator expression: ${e}`);const s=t.expressionWithoutIdentifier||t.expressionWithIdentifier||"all",r={questionId:t.questionId,expression:s};if(t.identifier){const _=isNaN(parseInt(t.identifier,10))?t.identifier:parseInt(t.identifier,10);r.identifier=_}return r};export{o as LOCATOR_EXPRESSION,a as parseLocator,E as validateLocator};
|
|
2
|
+
//# sourceMappingURL=locators.esm.js.map
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import b from"assert";import*as k from"crypto";import{QuestionType as w}from"../graphql/schema-types.generated.esm.js";import{extractQuestionNodes as M,getRawQuestionId as C}from"./convertTemplateToNode.esm.js";import{LOCATOR_EXPRESSION as p,validateLocator as $,parseLocator as T}from"./locators.esm.js";import z from"./schema/logic_parser.esm.js";var F=Object.defineProperty,G=(n,t,e)=>t in n?F(n,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):n[t]=e,d=(n,t,e)=>(G(n,typeof t!="symbol"?t+"":t,e),e),X=(n,t,e)=>{if(!t.has(n))throw TypeError("Cannot "+e)},R=(n,t,e)=>{if(t.has(n))throw TypeError("Cannot add the same private member more than once");t instanceof WeakSet?t.add(n):t.set(n,e)},f=(n,t,e)=>(X(n,t,"access private method"),e),y,v,g,S;const q=/\$\{q\:(?<locator>[\-a-zA-Z0-9_\/\(\)]+)\}/g,L=n=>{var t,e;return(e=(t=n.choiceId)!=null?t:n.choiceValue)!=null?e:n.text};class B{constructor(t,e=[],i="",s=!1){R(this,y),R(this,g),d(this,"questions",new Map),d(this,"responsesByQuestion",new Map),d(this,"responsesByQuestionStatement",new Map),d(this,"surveyResponseId"),d(this,"forExport"),d(this,"evaluationCache",new Map),this.questions=new Map((t?M(t):[]).filter(o=>o.id).map(o=>[C(o.id),o])),e.filter(o=>o.singleAnswer||o.multipleAnswers).forEach(o=>{const a=C(o.questionId);this.responsesByQuestion.set(a,[...this.responsesByQuestion.get(a)||[],o]),o.statementId&&this.responsesByQuestionStatement.set(`${a}.${o.statementId}`,o)}),this.surveyResponseId=i,this.forExport=s}getQuestionAnswers(t,e){let i;if(e){const s=this.responsesByQuestionStatement.get(`${t}.${e}`);i=s===void 0?[]:[s]}else i=this.responsesByQuestion.get(t)||[];return i.flatMap(s=>{const{multipleAnswers:o,singleAnswer:a}=s;return o||[a]})}evaluateDisplayLogic(t){if(t&&!this.forExport)try{const e=this.evaluationCache.get(t);if(e!==void 0)return e;const i=D(t,this);return this.evaluationCache.set(t,i),i}catch(e){return console.error(e),!1}return!0}evaluateDynamicExpression(t,e){const i=this.questions.get(t.questionId);if(!i)return[];const s=this.getQuestionChoicesFlattened(i),o=s.filter(r=>this.isSelected({questionId:t.questionId,choice:r.id||r.value})),a=this.getQuestionStatementsFlattened(i),h=r=>e==="choices"?r:{...r,id:r.id||r.value||r.display},m=r=>({id:r.id,display:r.display,value:r.value});let u=[];switch(t.expression){case p.ALL:u=s.map(h);break;case p.ALL_ENTERED_TEXT:u=s.map(r=>f(this,g,S).call(this,r,t)).filter(r=>!!r).map(r=>h(r));break;case p.SELECTED:u=o;break;case p.SELECTED_ENTERED_TEXT:u=o.map(r=>f(this,g,S).call(this,r,t)).filter(r=>!!r).map(r=>h(r));break;case p.NOT_SELECTED:u=s.filter(r=>!this.isSelected({questionId:t.questionId,choice:r.id||r.value})).map(h);break;case p.FOR_MATRIX_CHOICE:u=a.filter(r=>this.isSelected({questionId:t.questionId,statementId:r.id,choice:t.identifier}));break;case p.UNSELECTED_FOR_MATRIX_CHOICE:u=a.filter(r=>!this.isSelected({questionId:t.questionId,statementId:r.id,choice:t.identifier}));break;default:u=[]}return this.forExport&&(u=t.expression===p.FOR_MATRIX_CHOICE||t.expression===p.UNSELECTED_FOR_MATRIX_CHOICE?a:s.map(h)),u.map(m)}isSelected(t){return!!f(this,y,v).call(this,t.questionId,t.statementId,t.choice).length}countSelected(t){return this.getQuestionAnswers(t).length}selectedValue(t){const e=this.getQuestionAnswers(typeof t=="string"?t:t.questionId,typeof t=="string"?void 0:t.statementId);return e.length?L(e[0]):null}countChoiceSelections(t,e){return f(this,y,v).call(this,t,null,e).length}textEntry(t){return f(this,y,v).call(this,t.questionId,t.statementId,t.choice).map(e=>e.text).filter(e=>e).join(", ")}getQuestionText(t){if(this.forExport)return t.text;let e=t.text;return e=e.replaceAll(q,(i,s)=>{if(s&&$(s)){const o=T(s);return this.evaluateDynamicExpression(o,"choices").map(a=>a.display).join(", ")}return i}),e}getQuestionChoices(t){var e;const i=((e=t.choices)!=null?e:[]).filter(s=>this.evaluateDisplayLogic(s.displayLogic));if(t.dynamicChoices){const s=T(t.dynamicChoices),o=this.evaluateDynamicExpression(s,"choices");i.push(...o)}return t.type===w.MatrixSingle||t.type===w.MatrixMulti?i:this.applyRandomization(i,t.id,s=>{var o;return`${(o=s.id)!=null?o:s.value}`},t.randomization)}getQuestionChoiceGroups(t){var e;const i=(((e=t.choiceGroups)==null?void 0:e.filter(s=>this.evaluateDisplayLogic(s.displayLogic)))||[]).map(s=>({...s,choices:this.applyRandomization(s.choices.filter(o=>this.evaluateDisplayLogic(o.displayLogic)),t.id,o=>{var a;return`${(a=o.id)!=null?a:o.value}`},s.randomization)})).filter(s=>!!s.choices.length);return this.applyRandomization(i,t.id,s=>s.id,t.randomization)}getQuestionStatements(t){var e;const i=((e=t.statements)!=null?e:[]).filter(s=>this.evaluateDisplayLogic(s.displayLogic));if(t.dynamicStatements){const s=T(t.dynamicStatements),o=this.evaluateDynamicExpression(s,"statements");i.push(...o)}return this.applyRandomization(i,t.id,s=>s.id,t.randomization)}getQuestionStatementGroups(t){var e;const i=(((e=t.statementGroups)==null?void 0:e.filter(s=>this.evaluateDisplayLogic(s.displayLogic)))||[]).map(s=>({...s,statements:this.applyRandomization(s.statements.filter(o=>this.evaluateDisplayLogic(o.displayLogic)),t.id,o=>o.id,s.randomization)})).filter(s=>!!s.statements.length);return this.applyRandomization(i,t.id,s=>s.id,t.randomization)}getQuestionChoicesFlattened(t){return[...this.getQuestionChoices(t),...this.getQuestionChoiceGroups(t).flatMap(e=>e.choices)]}getQuestionStatementsFlattened(t){return[...this.getQuestionStatements(t),...this.getQuestionStatementGroups(t).flatMap(e=>e.statements)]}applyRandomization(t,e,i,s){var o,a;if(!s||this.forExport)return t;const h=new Map(t.map(c=>[i(c),c])),m=[...h.keys()],u=new Set(m),r=((o=s.order)!=null?o:["$"]).filter(c=>c==="$"||u.has(c)),E=m.filter(c=>!r.includes(c)).map(c=>({weight:this.keyHash(e,c),key:c}));E.sort((c,x)=>c.weight.localeCompare(x.weight));const O=(a=s.total)!=null?a:m.length,N=Math.min(O-(r.length-1),E.length),_=[];return r.forEach(c=>{c==="$"?_.push(...E.slice(0,N).map(x=>x.key)):_.push(c)}),_.map(c=>h.get(c))}keyHash(t,e){const i=`${t}.${this.surveyResponseId}.${e}`;return k.createHash("sha256").update(i).digest("hex")}}y=new WeakSet,v=function(n,t,e){return this.getQuestionAnswers(n,t).filter(i=>typeof e=="undefined"||e===null||L(i)===e)},g=new WeakSet,S=function(n,t){if(n.textInput&&["forced","optional"].includes(n.textInput)){const e=this.textEntry({questionId:t.questionId,choice:n.id||n.value});return e.trim()?{...n,display:e}:n.textInput==="forced"?null:n}return n};function Q(n){if(n.length===1)return n[0];const t=n[1].value;return t==="or"?n[0]||n[2]:t==="and"?n[0]&&n[2]:!1}function I(n,t,e){switch(t){case"==":return n===e;case"!=":return n!==e;case"<=":return n<=e;case">=":return n>=e;case"<":return n<e;case">":return n>e;default:return!1}}function A(n,t,e,i){const s=i?n.toLowerCase():n,o=i?e.toLowerCase():e;switch(t){case"contains":return s.includes(o);case"not_contains":return!s.includes(o);case"regex_matches":try{return new RegExp(e).test(s)}catch{return!1}default:return I(s,t,o)}}function H(n,t){return n.length>0&&n[0].hasOwnProperty("type")&&n[0].type==="NEGATION"?!t(n.slice(1)):t(n)}function P(n){if(!["INT","IDENTIFIER"].includes(n.type))throw new SyntaxError(`Invalid token type: ${n.type}; expected IDENTIFIER or INT`);return l(n)}function l(n){var t,e;switch(n.type){case"IDENTIFIER":return n.value;case"INT":return parseInt(n.value,10);case"STRING":{const i=n.value.match(/(?:'(?<single>[^\']*)')|(?:"(?<double>[^\"]*)")/),s=((t=i==null?void 0:i.groups)==null?void 0:t.double)||((e=i==null?void 0:i.groups)==null?void 0:e.single);return b(s),s}case"OPERATOR":return n.value;case"TRUE":return!0;case"FALSE":return!1;default:throw new SyntaxError(`Invalid token type: ${n.type}`)}}function D(n,t){const e={bool_const:i=>i[0].value==="true",condition:i=>i[0],bool_expr:Q,top_level_expr:Q,start:i=>i[0],question_id:i=>i[0].value,choice_ref:i=>P(i[0]),matrix_statement_id:i=>({questionId:i[0],statementId:i[1].value}),question_choice_selected:i=>H(i,s=>t.isSelected({questionId:typeof s[0]=="string"?s[0]:s[0].questionId,statementId:typeof s[0]=="string"?void 0:s[0].statementId,choice:s[1]})),question_choice_selected_value_comparison:i=>{const s=t.selectedValue(i[0]);return s!==null&&I(s,l(i[1]),l(i[2]))},question_choice_text_comparison:i=>A(t.textEntry({questionId:i[0],choice:i[1]}),l(i[2]),l(i[3]),!1),question_choice_text_comparison_case_insensitive:i=>A(t.textEntry({questionId:i[0],choice:i[1]}),l(i[2]),l(i[3]),!0),selected_count_comparison:i=>I(t.countSelected(i[0]),l(i[1]),l(i[2])),choice_selection_count_comparison:i=>I(t.countChoiceSelections(i[0],i[1]),l(i[2]),l(i[3]))};return z.get_parser({transformer:e}).parse(n)}export{q as QUESTION_TEXT_LOCATOR_PATTERN,B as TemplateContextEvaluator,D as evaluateExpression};
|
|
2
|
+
//# sourceMappingURL=logic.esm.js.map
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
var We=Object.defineProperty,Ge=(s,t,r)=>t in s?We(s,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):s[t]=r,w=(s,t,r)=>(Ge(s,typeof t!="symbol"?t+"":t,r),r);function Ze(s={}){return s.transformer&&s.transformer.constructor.name==="object"&&(s.transformer=q.fromObj(s.transformer)),Qe._load_from_dict({data:Ht,memo:Xt,...s})}const fe={};class de{}const C={},ye={escape(s){return s.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")},compile(s,t){return new RegExp(s,t)},error:SyntaxError};function Je(s,t,r,n){const i=s.compile(t,n).exec(r);if(i!=null)return i[0]}class ge{constructor(t,r,n,i,_=!1){this.terminals=t,this.g_regex_flags=r,this.re_=n,this.use_bytes=i,this.match_whole=_,this.allowed_types=new Set(this.terminals.map(a=>a.name)),this._regexps=this._build_mres(t)}_build_mres(t){let r=this.match_whole?"$":"",n=rt(t,_=>_.pattern.flags.join("")),i=[];for(let[_,a]of n){const l=a.map(p=>`(?<${p.name}>${p.pattern.to_regexp()+r})`).join("|");i.push(new RegExp(l,this.g_regex_flags+_+"y"))}return i}match(t,r){for(const n of this._regexps){n.lastIndex=r;let i=n.exec(t);if(i){let _=null;for(let[a,l]of Object.entries(i.groups))if(l){_=a;break}return[i[0],_]}}}}const xe=typeof require!="undefined"&&require("util");class we{}const I={};function f(s){return Object.entries(s)}function V(s){return Object.keys(s)}function Ve(s,t){t===void 0&&(t=Object.keys(s)[0]);let r=s[t];return delete s[t],r}function be(s,t,r=null){return s[t]||r}function ke(s,t){if(s.constructor.name==="Map")for(const[r,n]of f(t))s.set(r,n);else for(const[r,n]of f(t))s[r]=n}function Ke(s){return function(){return new s(...arguments)}}function u(s){let t=0,r=[...arguments].slice(1);return s.replace(/%([sr])/g,function(){const n=arguments[1],i=r[t++];return n==="r"?xe?xe.inspect(i,!1,null,!0):JSON.stringify(i,null,0):i})}function He(s,t){let r=new Set(s);for(const n of t)r.add(n);return r}function Te(s,t){return[...s].filter(r=>!t.has(r))}function Ne(s){return{...s}}function Re(s){return!!s}function K(s){return Object.create(s.prototype)}function b(s){if(typeof s=="object"){let t=Object.create(Object.getPrototypeOf(s));return Object.assign(t,s)}return s}function B(s){return new Set(s)}function H(s){return s&&s.constructor.name==="Object"}function Xe(s){return s&&s.constructor.name==="Array"}function Ye(s){return typeof s=="function"}function*z(s,t=0){let r=t;for(const n of s)yield[r++,n]}function et(s){for(const t of s)if(t)return!0;return!1}function ve(s,t){return t.filter(s||Re)}function F(s){let t=[...arguments].slice(1);return function(){return s(...t,...arguments)}}class X extends Error{}function d(s){return s[s.length-1]}function O(s){return function(){let t=new s(...arguments);return t.__call__.bind(t)}}function k(s,t){return Array.from({length:t},()=>s).flat()}function Ee(s){return/^[A-Z_$]*$/.test(s)}function Y(s,t,r){const n=s.split(t);return r?n.splice(-r-1):n}function ee(s,t){let r=new RegExp(t,"g");return(s.match(r)||[]).length}function tt(s,t){for(let r of s)if(!t.has(r))return!1;return!0}function*rt(s,t){let r=[],n=null;for(const i of s){const _=t(i);n&&_!=n&&(yield[n,r],r=[]),r.push(i),n=_}yield[n,r]}class T extends Error{}class N extends T{}function te(s,t,r="Got %r, expected one of %s"){if(!t.includes(s))throw new N(u(r,s,t))}class Q extends T{}class nt extends T{}class L extends T{}class R extends T{constructor(){super(...arguments),w(this,"pos_in_stream",null),w(this,"_terminals_by_name",null)}get_context(t,r=40){let n,i,_=this.pos_in_stream,a=max(_-r,0),l=_+r;return t instanceof bytes?(i=d(Y(t.slice(a,_),`
|
|
2
|
+
`,1)),n=t.slice(_,l).split(`
|
|
3
|
+
`,1)[0],(i+n+`
|
|
4
|
+
`+" "*i.expandtabs().length+`^
|
|
5
|
+
`).decode("ascii","backslashreplace")):(i=d(Y(t.slice(a,_),`
|
|
6
|
+
`,1)),n=t.slice(_,l).split(`
|
|
7
|
+
`,1)[0],i+n+`
|
|
8
|
+
`+" "*i.expandtabs().length+`^
|
|
9
|
+
`)}match_examples(t,r,n=!1){H(r)&&(r=f(r));let i=[null,!1];for(const[_,[a,l]]of z(r))for(const[p,o]of z(l))try{t(o)}catch(c){if(c instanceof R){if(c.state.eq(this.state)){if(c.token===this.token)return a;n&&c.token.type===this.token.type&&!d(i)&&(i=[a,!0]),i[0]===null&&(i=[a,!1])}}else throw c}return i[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 st extends R{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 A extends R{constructor({seq:t,lex_pos:r,line:n,column:i,allowed:_=null,considered_tokens:a=null,state:l=null,token_history:p=null,terminals_by_name:o=null,considered_rules:c=null}={}){super(),this.line=n,this.column=i,this.pos_in_stream=r,this.state=l,this._terminals_by_name=o,this.allowed=_,this.considered_tokens=a,this.considered_rules=c,this.token_history=p,this.char=t[r]}}class P extends R{constructor({token:t,expected:r,considered_rules:n=null,state:i=null,interactive_parser:_=null,terminals_by_name:a=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=i,this.token=t,this.expected=r,this._accepts=fe,this.considered_rules=n,this.interactive_parser=_,this._terminals_by_name=a,this.token_history=l}get accepts(){return this._accepts===fe&&(this._accepts=this.interactive_parser&&this.interactive_parser.accepts()),this._accepts}}class re extends T{constructor(t,r,n){let i=u(`Error trying to process rule "%s":
|
|
13
|
+
|
|
14
|
+
%s`,t,n);super(i),this.rule=t,this.obj=r,this.orig_exc=n}}function it(s,t=null,r=null){let n,i,_=new Map;for(const a of s)n=t!==null?t(a):a,i=r!==null?r(a):a,_.has(n)?_.get(n).push(i):_.set(n,[i]);return _}function U(s,t,r){let n;return H(s)?"__type__"in s?(n=t[s.__type__],n.deserialize(s,r)):"@"in s?r[s["@"]]:Object.fromEntries(f(s).map(([i,_])=>[i,U(_,t,r)])):Xe(s)?s.map(i=>U(i,t,r)):s}class y{static deserialize(t,r){const n=this;let i=n&&n.__serialize_fields__;if("@"in t)return r[t["@"]];let _=K(n);for(const a of i)if(t&&a in t)_[a]=U(t[a],Vt,r);else throw new KeyError("Cannot find key for class",n,e);return"_deserialize"in _&&_._deserialize(),_}}class _t 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 U(t,r,n)}}class Oe{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 Oe),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[k(r,t).join(""),this._pretty_label()," ",u("%s",this.children[0].value),`
|
|
15
|
+
`];let n=[k(r,t).join(""),this._pretty_label(),`
|
|
16
|
+
`];for(const i of this.children)i instanceof m?n.push(...i._pretty(t+1,r)):n.push(k(r,t+1).join(""),u("%s",i.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(i=>i instanceof m&&!r.has(i)).map(i=>i));return t=void 0,[...r.values()].reverse()}find_pred(t){return ve(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 q extends de{static get __visit_tokens__(){return!0}constructor(t=!0){super(),this.__visit_tokens__=t}static fromObj(t,...r){class n extends this{}for(let[i,_]of Object.entries(t))n.prototype[i]=_;return new n(...r)}_call_userfunc(t,r=null){let n,i,_=r!==null?r:t.children;if(t&&t.data&&this&&this[t.data]){n=this&&this[t.data];try{return i=n&&n.visit_wrapper||null,i!==null?n.visit_wrapper(n,t.data,_,t.meta):n(_)}catch(a){throw a instanceof Q?a:a instanceof Error?new re(t.data,t,a):a}}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 Q?n:n instanceof Error?new re(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!==C&&(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 Ae extends q{_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 at extends q{transform(t){let r,n,i,_=[],a=[t];for(;a.length;){const o=a.pop();_.push(o),o instanceof m&&a.push(...o.children)}let l=[];for(const o of[..._].reverse())o instanceof m?(i=o.children.length,i?(r=l.slice(-i),l.splice(-i)):r=[],n=this._call_userfunc(o,r),n!==C&&l.push(n)):this.__visit_tokens__&&o instanceof h?(n=this._call_userfunc_token(o),n!==C&&l.push(n)):l.push(o);let[p]=l;return p}}class lt extends q{_transform_tree(t){return t.children=[...this._transform_children(t.children)],this._call_userfunc(t)}}class ne{_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 ot extends ne{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 pt extends ne{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 ct extends de{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 ut=0;class se extends y{constructor(t){super(),w(this,"is_term",I),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 ie extends se{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 _e extends se{static get __serialize_fields__(){return["name"]}get is_term(){return!1}}class $ extends y{static get __serialize_fields__(){return["keep_all_tokens","expand1","priority","template_source","empty_indices"]}constructor(t=!1,r=!1,n=null,i=null,_=[]){super(),this.keep_all_tokens=t,this.expand1=r,this.priority=n,this.template_source=i,this.empty_indices=_}repr(){return u("RuleOptions(%r, %r, %r, %r)",this.keep_all_tokens,this.expand1,this.priority,this.template_source)}}class S extends y{static get __serialize_fields__(){return["origin","expansion","order","alias","options"]}static get __serialize_namespace__(){return[ie,_e,$]}constructor(t,r,n=0,i=null,_=null){super(),this.origin=t,this.expansion=r,this.alias=i,this.order=n,this.options=_||new $,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 S?this.origin===t.origin&&this.expansion===t.expansion:!1}}class ae extends y{constructor(t,r=[],n=null){super(),this.value=t,this.flags=B(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 ae{static get __serialize_fields__(){return["value","flags"]}static get type(){return"str"}to_regexp(){return this._get_flags(ye.escape(this.value))}get min_width(){return this.value.length}get max_width(){return this.value.length}}class oe extends ae{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,oe]}constructor(t,r,n=ut){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{constructor(t,r,n=null,i=null,_=null,a=null,l=null,p=null){w(this,"value"),w(this,"type"),this.type=t,this.start_pos=n,this.value=r,this.line=i,this.column=_,this.end_line=a,this.end_column=l,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 i=this;return new i(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 ue{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 ue?this.char_pos===t.char_pos&&this.newline_char===t.newline_char:I}feed(t,r=!0){let n;r&&(n=ee(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 ht{constructor(t){this.scanner=t}__call__(t){let r,n=this.scanner.match(t.value,0);return n&&([r,t.type]=n),t}}const mt=O(ht);class ft{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 dt=O(ft);function yt(s,t,r,n){let i,_,a=it(s,o=>o.pattern.constructor.type),l=new Set,p={};for(const o of a.get("re")||[]){_=[];for(const c of a.get("str")||[])c.priority===o.priority&&(i=c.pattern.value,i===Je(r,o.pattern.to_regexp(),i,t)&&(_.push(c),tt(new Set(c.pattern.flags),new Set(o.pattern.flags))&&l.add(c)));_.length&&(p[o.name]=new mt(new ge(_,t,r,n,!0)))}return[s.filter(o=>!l.has(o)).map(o=>o),p]}function gt(s){return s.includes(`
|
|
18
|
+
`)||s.includes("\\n")||s.includes("\\s")||s.includes("[^")||s.includes("(?s")&&s.includes(".")}class he{constructor(t,r=null,n=null){this.text=t,this.line_ctr=r||new ue(`
|
|
19
|
+
`),this.last_token=n}eq(t){return t instanceof he?this.text===t.text&&this.line_ctr===t.line_ctr&&this.last_token===t.last_token:I}}class Pe{constructor(t,r){this.lexer=t,this.state=r}static from_text(t,r){return new this(t,new he(r))}lex(t){return this.lexer.lex(this.state,t)}}class W extends we{lex(t,r){return I}}function xt(s,t){s.sort((r,n)=>{let i=t(r),_=t(n);for(let a=0;a<i.length;a++){if(i[a]>_[a])return 1;if(i[a]<_[a])return-1}return 0})}class G extends W{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(i){throw i instanceof this.re.error?new L(u("Cannot compile token %s: %s",n.name,n.pattern)):i}if(n.pattern.min_width===0)throw new L(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 L(u("Ignore terminals are not defined: %s",Te(new Set(t.ignore),new Set(r.map(n=>n.name)))))}this.newline_types=B(r.filter(n=>gt(n.pattern.to_regexp())).map(n=>n.name)),this.ignore_types=B(t.ignore),xt(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]=yt(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 dt(this.callback[r],n,i=>i.type===r):this.callback[r]=n;this._scanner=new ge(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 X))throw n}}next_token(t,r=null){let n,i,_,a,l=t.line_ctr;for(;l.char_pos<t.text.length;){if(i=this.match(t.text,l.char_pos),!i)throw n=Te(this.scanner.allowed_types,this.ignore_types),n||(n=new Set(["<END-OF-FILE>"])),new A({seq:t.text,lex_pos:l.char_pos,line:l.line,column:l.column,allowed:n,token_history:t.last_token&&[t.last_token],state:r,terminals_by_name:this.terminals_by_name});let[p,o]=i;if(this.ignore_types.has(o))o in this.callback&&(a=new h(o,p,l.char_pos,l.line,l.column),this.callback[o](a)),l.feed(p,this.newline_types.has(o));else{if(_=new h(o,p,l.char_pos,l.line,l.column),l.feed(p,this.newline_types.has(o)),_.end_line=l.line,_.end_column=l.column,_.end_pos=l.char_pos,_.type in this.callback&&(_=this.callback[_.type](_),!(_ instanceof h)))throw new L(u("Callbacks must return a token (returned %r)",_));return t.last_token=_,_}}throw new X(this)}}class wt extends W{constructor({conf:t,states:r,always_accept:n=[]}={}){super();let i,_,a,l=[...t.terminals],p=t.terminals_by_name,o=b(t);o.terminals=l;let c=new Map;this.lexers={};for(let[g,E]of f(r))i=B(E),c.has(i)?_=c.get(i):(E=He(new Set(E),[...new Set(t.ignore),...new Set(n)]),a=b(o),a.terminals=[...E].filter(x=>x in p).map(x=>p[x]),_=new G(a),c.set(i,_)),this.lexers[g]=_;this.root_lexer=new G(o)}*lex(t,r){let n,i,_;try{for(;;)i=this.lexers[r.position],yield i.next_token(t,r)}catch(a){if(!(a instanceof X))if(a instanceof A)try{throw n=t.last_token,_=this.root_lexer.next_token(t,r),new P({token:_,expected:a.allowed,state:r,token_history:[n],terminals_by_name:this.root_lexer.terminals_by_name})}catch(l){throw l}else throw a}}}class Se 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:i=null,callbacks:_=null,g_regex_flags:a="",skip_validation:l=!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=i,this.callbacks=Object.keys(_).length||{},this.g_regex_flags=a,this.re_module=r,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 De 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 bt{constructor(t){this.node_builder=t}__call__(t){return t.length===1?t[0]:this.node_builder(t)}}const kt=O(bt);class Tt{constructor(t,r=null){this.node_builder=t,this.node_filter=r}__call__(t){let r,n,i,_=this.node_builder(t);return _ instanceof m&&(i=_.meta,r=this._pp_get_meta(t),r!==null&&("line"in i||(i.line=r&&r.container_line||r.line,i.column=r&&r.container_column||r.column,i.start_pos=r&&r.container_start_pos||r.start_pos,i.empty=!1),i.container_line=r&&r.container_line||r.line,i.container_column=r&&r.container_column||r.column),n=this._pp_get_meta([...t].reverse()),n!==null&&("end_line"in i||(i.end_line=n&&n.container_end_line||n.end_line,i.end_column=n&&n.container_end_column||n.end_column,i.end_pos=n&&n.container_end_pos||n.end_pos,i.empty=!1),i.container_end_line=n&&n.container_end_line||n.end_line,i.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 Ie=O(Tt);function Nt(s){if(Ye(s))return F({unknown_param_0:Ie,node_filter:s});if(s===!0)return Ie;if(s===!1)return null;throw new N(u("Invalid option for propagate_positions: %r",s))}class pe{constructor(t,r,n){this.node_builder=n,this.to_include=t,this.append_none=r}__call__(t){let r=[];for(const[n,i,_]of this.to_include)_&&r.push(...k([null],_)),i?r.push(...t[n].children):r.push(t[n]);return this.append_none&&r.push(...k([null],this.append_none)),this.node_builder(r)}}const Rt=O(pe);class vt extends pe{__call__(t){let r=[];for(const[n,i,_]of this.to_include)_&&r.push(...k([null],_)),i?r.length?r.push(...t[n].children):r=t[n].children:r.push(t[n]);return this.append_none&&r.push(...k([null],this.append_none)),this.node_builder(r)}}const Et=O(vt);class Ot extends pe{constructor(t,r){super(),this.node_builder=r,this.to_include=t}__call__(t){let r=[];for(const[n,i]of this.to_include)i?r.length?r.push(...t[n].children):r=t[n].children:r.push(t[n]);return this.node_builder(r)}}const At=O(Ot);function Pt(s){return!s.is_term&&s.name.startsWith("_")}function St(s,t,r,n){let i,_;n.length?(_=n.map(p=>(0+p).toString()).join(""),i=_.split("0").map(p=>p.length)):i=k([0],s.length+1);let a=[],l=0;for(const[p,o]of z(s))l+=i[p],(t||!(o.is_term&&o.filter_out))&&(a.push([p,Pt(o),l]),l=0);if(l+=i[s.length],n.length||a.length<s.length||et(a.map(([p,o,c])=>o)))return(n.length||r).length?F(r?Rt:Et,a,l):F(At,a.map(([p,o,c])=>[p,o]))}function Dt(s){function t(r){let n=new m(s.name,r);return s(n)}return t=wraps(s)(t),t}function It(s,t,r){if(r===_vargs_meta||r===_vargs_meta_inline)throw new NotImplementedError("Meta args not supported for internal transformer");function n(i){return r(s,t,i,null)}return n=wraps(s)(n),n}class zt{constructor(t,r,n=!1,i=!1,_=!1){this.tree_class=r,this.propagate_positions=n,this.ambiguous=i,this.maybe_placeholders=_,this.rule_builders=[...this._init_builders(t)]}*_init_builders(t){let r,n,i,_,a=Nt(this.propagate_positions);for(const l of t)i=l.options,n=i.keep_all_tokens,r=i.expand1,_=[...ve(null,[r&&!l.alias&&kt,St(l.expansion,n,this.ambiguous,this.maybe_placeholders?i.empty_indices:[]),a])],yield[l,_]}create_callback(t=null){let r,n,i,_=new Map;for(const[a,l]of this.rule_builders){n=a.alias||a.options.template_source||a.origin.name,t&&t[n]?(r=t&&t[n],i=r&&r.visit_wrapper||null,i!==null?r=It(r,n,i):t instanceof Ae&&(r=Dt(r))):r=F(this.tree_class,n);for(const p of l)r=p(r);if(_.has(a))throw new Q(u("Rule '%s' already exists",a));_.set(a,r)}return _}}class ze 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 i=t.callbacks;this._parse_table=n.parse_table,this.parser_conf=t,this.parser=new Le(n.parse_table,i,r)}static deserialize(t,r,n,i=!1){let _=K(this);return _._parse_table=jt.deserialize(t,r),_.parser=new Le(_._parse_table,n,i),_}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 i,_;try{return this.parser.parse({lexer:t,start:r})}catch(a){if(a instanceof R){if(n===null)throw a;for(;;){if(a instanceof A&&(_=a.interactive_parser.lexer_thread.state,i=_.line_ctr.char_pos),!n(a))throw a;a instanceof A&&i===_.line_ctr.char_pos&&_.line_ctr.feed(_.text.slice(i,i+1));try{return a.interactive_parser.resume_parse()}catch(l){if(l instanceof P){if(a instanceof P&&a.token.type===l.token.type&&l.token.type==="$END"&&a.interactive_parser.eq(l.interactive_parser))throw l;a=l}else if(l instanceof A)a=l;else throw l}}}else throw a}}}class Lt{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 me{constructor(t,r,n=null,i=null){this.parse_conf=t,this.lexer=r,this.state_stack=n||[this.parse_conf.start_state],this.value_stack=i||[]}get position(){return d(this.state_stack)}eq(t){return t instanceof me?this.state_stack.length===t.state_stack.length&&this.position===t.position:I}copy(){return b(this)}feed_token(t,r=!1){let n,i,_,a,l,p,o,c,g,E,x=this.state_stack,D=this.value_stack,j=this.parse_conf.states,Me=this.parse_conf.end_state,Z=this.parse_conf.callbacks;for(;;){if(g=d(x),t.type in j[g])[i,_]=j[g][t.type];else throw a=new Set(V(j[g]).filter(J=>Ee(J)).map(J=>J)),new P({token:t,expected:a,state:this,interactive_parser:null});if(i===ce){x.push(_),D.push(t.type in Z?Z[t.type](t):t);return}else if(p=_,c=p.expansion.length,c?(o=D.slice(-c),x.splice(-c),D.splice(-c)):o=[],E=Z.get(p)(o),[n,l]=j[d(x)][p.origin.name],x.push(l),D.push(E),r&&d(x)===Me)return d(D)}}}class Le{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:i=null,start_interactive:_=!1}={}){let a=new Lt(this.parse_table,this.callbacks,r),l=new me(a,t,i,n);return _?new v(this,l,l.lexer):this.parse_from_state(l)}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(i){if(i instanceof R){try{i.interactive_parser=new v(this,t,t.lexer)}catch(_){if(!(_ instanceof ReferenceError))throw _}throw i}else if(i instanceof Error){if(this.debug){console.log(""),console.log("STATE STACK DUMP"),console.log("----------------");for(const[_,a]of z(t.state_stack))console.log(u("%d)",_),a);console.log("")}throw i}else throw i}}}class v{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 b(this)}eq(t){return t instanceof v?this.parser_state===t.parser_state&&this.lexer_thread===t.lexer_thread:!1}as_immutable(){let t=b(this);return new qe(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(Ee(n)){t=b(this);let i=null;try{t.feed_token(new h(n,""))}catch(_){if(i=_,!(_ instanceof P))throw _}i||r.add(n)}return r}resume_parse(){return this.parser.parse_from_state(this.parser_state)}}class qe extends v{constructor(){super(...arguments),w(this,"result",null)}feed_token(t){let r=b(this);return r.result=v.feed_token(r,t),r}exhaust_lexer(){let t=this.as_mutable();return t.exhaust_lexer(),t.as_immutable()}as_mutable(){let t=b(this);return new v(t.parser,t.parser_state,t.lexer_thread)}}class je{constructor(t){this.name=t}repr(){return this.toString()}}var ce=new je("Shift"),Ce=new je("Reduce");class qt{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(([i,_])=>[i,Object.fromEntries(f(_).map(([a,[l,p]])=>[be(r,a),l===Ce?[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 i=t.tokens,_=Object.fromEntries(f(t.states).map(([a,l])=>[a,Object.fromEntries(f(l).map(([p,[o,c]])=>[i[p],o===1?[Ce,S.deserialize(c,r)]:[ce,c]]))]));return new n(_,t.start_states,t.end_states)}}class jt extends qt{static from_ParseTable(t){const r=this;let n=[...t.states],i=Object.fromEntries(z(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]===ce?[g[0],i[g[1]]]:g])),_[i[p]]=o;let a=Object.fromEntries(f(t.start_states).map(([p,o])=>[p,i[o]])),l=Object.fromEntries(f(t.end_states).map(([p,o])=>[p,i[o]]));return new r(_,a,l)}}function Ct(s){if(s&&s.__future_interface__)return s;{class t extends W{constructor(n){super(),this.lexer=s(n)}lex(n,i){return this.lexer.lex(n.text)}}return t}}function Bt(s,t,r,n,i){let _=De.deserialize(s.parser_conf,t),a=ze.deserialize(s.parser,t,n,i.debug);return _.callbacks=n,new Ft({lexer_conf:r,parser_conf:_,options:i,parser:a})}var Be={};class Ft extends y{static get __serialize_fields__(){return["lexer_conf","parser_conf","parser"]}constructor({lexer_conf:t,parser_conf:r,options:n,parser:i=null}={}){super();let _,a;this.parser_conf=r,this.lexer_conf=t,this.options=n,i?this.parser=i:(a=be(Be,r.parser_type),this.parser=a(t,r,n));let l=t.lexer_type;if(this.skip_lexer=!1,["dynamic","dynamic_complete"].includes(l)){this.skip_lexer=!0;return}const p={basic:Mt,contextual:Wt};l in p?(_=p[l],this.lexer=_(t,this.parser,t.postlex,n)):this.lexer=Ct(l)(t),t.postlex&&(this.lexer=new $t(this.lexer,t.postlex))}_verify_start(t=null){let r;if(t===null){if(r=this.parser_conf.start,r.length>1)throw new N("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 N(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:Pe.from_text(this.lexer,t)}parse(t,r=null,n=null){let i=this._verify_start(r),_=n===null?{}:{on_error:n},a=this._make_lexer_thread(t);return this.parser.parse({lexer:a,start:i,..._})}parse_interactive(t=null,r=null){let n=this._verify_start(r);if(this.parser_conf.parser_type!=="lalr")throw new N("parse_interactive() currently only works with parser='lalr' ");let i=this._make_lexer_thread(t);return this.parser.parse_interactive(i,n)}}function Qt(s,t){let r;te(s,["lalr","earley","cyk"]),typeof t!="object"&&(r={lalr:["basic","contextual"],earley:["basic","dynamic","dynamic_complete"],cyk:["basic"]}[s],te(t,r,u("Parser %r does not support lexer %%r, expected one of %%s",s)))}function Ut(s,t){let r,n={};for(const i of t)r=s&&s[i.name]||null,r!==null&&(n[i.name]=r);return n}class $t{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 Mt(s,t,r,n){return new G(s)}function Wt(s,t,r,n){let i=Object.fromEntries(f(t._parse_table.states).map(([a,l])=>[a,[...V(l)]])),_=r?r.always_accept:[];return new wt({conf:s,states:i,always_accept:_})}function Gt(s,t,r=null){let n=r?r.debug:!1;return new ze({parser_conf:t,debug:n})}Be.lalr=Gt;class Fe extends we{constructor(){super(...arguments),w(this,"always_accept",[])}process(t){return t}}class Zt extends y{constructor(t){super(),w(this,"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 '),w(this,"_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});let r,n=Ne(t),i=this;for(const[_,a]of f(this._defaults))_ in n?(r=Ve(n,_),typeof a=="boolean"&&!["cache","use_bytes","propagate_positions"].includes(_)&&(r=Re(r))):r=a,i[_]=r;if(typeof i.start=="string"&&(i.start=[i.start]),this.options=i,te(this.parser,["earley","lalr","cyk",null]),this.parser==="earley"&&this.transformer)throw new N("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 N(u("Unknown options: %s",V(n)))}serialize(t){return this.options}static deserialize(t,r){const n=this;return new n(t)}}class Qe extends y{static get __serialize_fields__(){return["parser","rules","options"]}_build_lexer(t=!1){let r=this.lexer_conf;return t&&(r=b(r),r.ignore=[]),new G(r)}_prepare_callbacks(){this._callbacks=new Map,this.options.ambiguity!=="forest"&&(this._parse_tree_builder=new zt(this.rules,this.options.tree_class||Ke(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)),ke(this._callbacks,Ut(this.options.transformer,this.terminals))}_deserialize_lexer_conf(t,r,n){let i=Se.deserialize(t.lexer_conf,r);return i.callbacks=n.lexer_callbacks||{},i.re_module=n.regex?regex:ye,i.use_bytes=n.use_bytes,i.g_regex_flags=n.g_regex_flags||"",i.skip_validation=!0,i.postlex=n.postlex,i}_load({f:t,...r}={}){let n;H(t)?n=t:n=pickle.load(t);let i=n.memo,_=n.data,a=_t.deserialize(i,{Rule:S,TerminalDef:M},{}),l=Ne(_.options);return ke(l,r),this.options=Zt.deserialize(l,a),this.rules=_.rules.map(p=>S.deserialize(p,a)),this.source_path="<deserialized>",Qt(this.options.parser,this.options.lexer),this.lexer_conf=this._deserialize_lexer_conf(_.parser,a,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=Bt(_.parser,a,this.lexer_conf,this._callbacks,this.options),this}static _load_from_dict({data:t,memo:r,...n}={}){return K(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 i=Pe.from_text(n,t).lex(null);return this.options.postlex?this.options.postlex.process(i):i}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 Ue extends T{}class $e extends Fe{constructor(){super(),this.paren_level=0,this.indent_level=[0]}*handle_NL(t){if(this.paren_level>0)return;yield t;let r=Y(t.value,`
|
|
21
|
+
`,1)[1],n=ee(r," ")+ee(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 Ue(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 Jt extends $e{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 Vt={Terminal:ie,NonTerminal:_e,RuleOptions:$,PatternStr:le,PatternRE:oe,TerminalDef:M};var Kt={LarkError:T,ConfigurationError:N,GrammarError:Q,ParseError:nt,LexError:L,UnexpectedInput:R,UnexpectedEOF:st,UnexpectedCharacters:A,UnexpectedToken:P,VisitError:re,Meta:Oe,Tree:m,Discard:C,Transformer:q,Transformer_InPlace:Ae,Transformer_NonRecursive:at,Transformer_InPlaceRecursive:lt,VisitorBase:ne,Visitor:ot,Visitor_Recursive:pt,Interpreter:ct,Symbol:se,Terminal:ie,NonTerminal:_e,RuleOptions:$,Rule:S,Pattern:ae,PatternStr:le,PatternRE:oe,TerminalDef:M,Token:h,Lexer:W,LexerConf:Se,ParserConf:De,InteractiveParser:v,ImmutableInteractiveParser:qe,PostLex:Fe,Lark:Qe,DedentError:Ue,Indenter:$e,PythonIndenter:Jt,get_parser:Ze},Ht={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"},Xt={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"}};export{h as Token,Kt as default};
|
|
23
|
+
//# sourceMappingURL=logic_parser.esm.js.map
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
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};export{a as $defs,e as $id,t as $schema,o as additionalProperties,p as default,s as properties,n as required,i as title,r as type};
|
|
2
|
+
//# sourceMappingURL=survey-template-schema.json.esm.js.map
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import{QuestionType as p}from"../graphql/schema-types.generated.esm.js";import{getQuestionTypeEnum as f,extractQuestionNodes as q}from"./convertTemplateToNode.esm.js";import{hasAnswer as w,evaluateTemplateNode as h,getRelevantQuestionResponses as y}from"./evaluation.esm.js";const R=(s,n)=>n?`${s}.${n}`:s,g=(s,n,i,e)=>{var a;if(!n.singleAnswer)return e==null||e.warn("Response validation failed: No SingleAnswer provided in single answer question.",{surveyResponseId:i.surveyResponseId,questionId:n.questionId}),!1;const r=new Set(i.getQuestionChoicesFlattened(s).map(o=>{var l;return(l=o.id)!=null?l:o.value})),u=(a=n.singleAnswer.choiceId)!=null?a:n.singleAnswer.choiceValue;return r.has(u)?!0:(e==null||e.warn("Response validation failed: Selected choice in single answer question not available",{surveyResponseId:i.surveyResponseId,questionId:s.id,choiceKey:u}),!1)},S=(s,n,i,e)=>{if(!n.multipleAnswers)return e==null||e.warn("Response validation failed: No MultipleAnswer provided in multi answer question",{surveyResponseId:i.surveyResponseId,questionId:n.questionId}),!1;const a=new Set(i.getQuestionChoicesFlattened(s).map(u=>{var o;return(o=u.id)!=null?o:u.value}));let r=!1;return n.multipleAnswers.forEach(u=>{var o;const l=(o=u.choiceId)!=null?o:u.choiceValue;a.has(l)||(e==null||e.warn("Response validation failed: Selected choice in multi answer question not available",{surveyResponseId:i.surveyResponseId,questionId:s.id,choiceKey:l}),r=!0)}),!r},M=(s,n,i)=>{var e;return(e=s.singleAnswer)!=null&&e.text?!0:(i==null||i.warn("Response validation failed: No text provided",{surveyResponseId:n.surveyResponseId,questionId:s.questionId}),!1)};function m(s,n,i,e){if(!w(n))return!0;switch(f(s.type)){case p.McSingle:case p.MatrixSingle:return g(s,n,i,e);case p.McMulti:case p.MatrixMulti:return S(s,n,i,e);case p.TextSingle:case p.TextMulti:return M(n,i,e);default:return e==null||e.warn("Response validation failed: Unsupported question type",{questionId:s.id,questionType:s.type,surveyResponseId:i.surveyResponseId}),!1}}function A(s,n,i,e){const a={templateId:s.id,surveyResponseId:i.surveyResponseId};e==null||e.debug("Validating response...",{questionResponses:n,...a});const r=h(s,i),u=q(r),o=y(r,n);if(new Set(o.map(t=>R(t.questionId,t.statementId))).size<o.length)return e==null||e.warn("Response validation failed: Duplicate question/statement ID(s) in the response.",{relevantQuestionResponses:o,...a}),!1;const l=Object.fromEntries(u.filter(t=>t.id).map(t=>[t.id,t])),I=new Map;for(const t of o){const v=l[t.questionId];if(!v)return e==null||e.warn("Response validation failed: Response provided to a question that's not in the template",{questionId:t.questionId,...a}),!1;let d=I.get(t.questionId);if(d===void 0&&(d=new Map(i.getQuestionStatementsFlattened(v).map(c=>[c.id,c])),I.set(t.questionId,d)),t.statementId){if(!d||!d.size)return e==null||e.warn("Response validation failed: Response provided to a statement even to the question has no statements",{questionId:t.questionId,statementId:t.statementId,...a}),!1;if(!d.get(t.statementId))return e==null||e.warn("Response validation failed: Response provided to an invalid question statement",{questionId:t.questionId,statementId:t.statementId,...a}),!1}else if(d&&d.size)return e==null||e.warn("Response validation failed; Response provided to a question with statements but not statement provided.",{questionId:t.questionId,statementId:t.statementId,...a}),!1;if(!m(v,t,i,e))return!1}return!0}export{R as responseRef,m as validateQuestionResponse,A as validateResponse};
|
|
2
|
+
//# sourceMappingURL=validateResponse.esm.js.map
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import M from"ajv";import z from"ajv-formats";import{interpolateTemplate as O}from"./interpolation.esm.js";import{parseLocator as x,LOCATOR_EXPRESSION as Q}from"./locators.esm.js";import{evaluateExpression as b,QUESTION_TEXT_LOCATOR_PATTERN as A}from"./logic.esm.js";import D from"./schema/survey-template-schema.json.esm.js";var L=Object.defineProperty,N=(e,i,n)=>i in e?L(e,i,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[i]=n,h=(e,i,n)=>(N(e,typeof i!="symbol"?i+"":i,n),n);const C=new M({allowUnionTypes:!0});z(C);const T=C.compile(D);class w extends Error{}class l extends Error{}class $ extends Error{}class f extends Error{}class U extends Error{}class X{constructor(){h(this,"seenQuestions",new Set),h(this,"seenMultiQuestions",new Set),h(this,"seenQuestionStatements",new Map),h(this,"seenQuestionChoices",new Map),h(this,"seenTextChoices",new Map),h(this,"evaluator",{}),h(this,"validateReference",i=>{var n,a,o;if(!this.seenQuestions.has(i.questionId))throw new w(`Invalid question: ${i.questionId}`);if(i.statementId!==void 0&&!((n=this.seenQuestionStatements.get(i.questionId))!=null&&n.has(i.statementId)))throw new w(`Invalid statement: ${i.questionId}.${i.statementId}`);if(i.choice!==void 0&&!((a=this.seenQuestionChoices.get(i.questionId))!=null&&a.has(i.choice)))throw new w(`Invalid choice: ${i.questionId}[${i.choice}]`);if(i.choice!==void 0&&i.expectText===!0&&!((o=this.seenTextChoices.get(i.questionId))!=null&&o.has(i.choice)))throw new w(`Invalid text reference: ${i.questionId}[${i.choice}]`);if(typeof i.expectMulti=="boolean"&&i.expectMulti&&!this.seenMultiQuestions.has(i.questionId))throw new l(`Invalid question reference: ${i.questionId}. Expected a multi-answer question.`);if(typeof i.expectMulti=="boolean"&&!i.expectMulti&&this.seenMultiQuestions.has(i.questionId))throw new l(`Invalid question reference: ${i.questionId}. Expected a non-multi-answer question.`)}),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}),"")}}const m=(e,i,n)=>{if(n)try{b(n,e.evaluator)}catch(a){throw a instanceof w||a instanceof l||a instanceof f?a:new Error(`Syntax error parsing display logic at ${i}: ${n}`)}},F=(e,i)=>{[...i.matchAll(A)].forEach(n=>{var a;const o=x(n.groups.locator);if(!e.seenQuestions.has(o.questionId))throw new l(`Invalid question referenced in locator expression: ${o.questionId}/${o.expression}`);if(o.identifier&&!((a=e.seenQuestionChoices.get(o.questionId))!=null&&a.has(o.identifier)))throw new l(`Invalid question choice referenced in locator expression: ${o.questionId}/${o.expression}(${o.identifier})`)})},p=(e,i,n)=>{if(n){const a=new Set(i);if(n.order){const o=n.order.split(" "),u=o.filter(c=>c==="$").length;if(u===0)throw new $(`Wildcard $ is missing in randomization order at ${e.id}`);if(u>1)throw new $(`Wildcard $ occurred multiples times in randomization order at ${e.id}`);if(o.forEach(c=>{if(c!=="$"&&!a.has(c))throw new $(`Unknown id ${c} in randomization ordering at ${e.id}`)}),n.total!==void 0&&n.total<o.length)throw new $(`Total value in randomization is too small at ${e.id}`)}}},R=(e,i)=>{const n=[Q.FOR_MATRIX_CHOICE,Q.UNSELECTED_FOR_MATRIX_CHOICE].includes(e.expression),a=(n?i.seenQuestionStatements:i.seenQuestionChoices).get(e.questionId);if(a===void 0)throw new l(`Invalid question referenced in locator expression: ${e.questionId}/${e.expression}`);if(n){const o=i.seenQuestionChoices.get(e.questionId);if(!e.identifier||!(o!=null&&o.has(e.identifier)))throw new l(`Invalid choice referenced in locator expression: ${e.questionId}/${e.expression}(${e.identifier})`)}return a},P=(e,i)=>{var n,a,o,u,c,q,g,E,y,_,S;if(F(i,e.text),e.id!==void 0){if(m(i,e.id,e.display_logic),(n=e.statements)==null||n.forEach(t=>{m(i,`${e.id}.${t.id}`,t.display_logic)}),(a=e.choices)==null||a.forEach(t=>{m(i,`${e.id}[${t.id||t.value}]`,t.display_logic)}),e.type==="matrix-multi"||e.type==="matrix-single"?e.statement_groups?p(e,e.statement_groups.map(t=>t.id),e.randomization):p(e,(u=(o=e.statements)==null?void 0:o.map(t=>t.id))!=null?u:[],e.randomization):e.choice_groups?p(e,e.choice_groups.map(t=>t.id),e.randomization):p(e,(q=(c=e.choices)==null?void 0:c.map(t=>`${t.id||t.value}`))!=null?q:[],e.randomization),(g=e.statement_groups)==null||g.forEach(t=>{t.statements.forEach(s=>{m(i,`${e.id}.${s.id}`,s.display_logic)}),p(e,t.statements.map(s=>s.id),t.randomization)}),(E=e.choice_groups)==null||E.forEach(t=>{t.choices.forEach(s=>{m(i,`${e.id}[${s.id||s.value}]`,s.display_logic)}),p(e,t.choices.map(s=>`${s.id||s.value}`),t.randomization)}),i.seenQuestions.has(e.id))throw new f(`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),(y=e.statements)==null||y.forEach(s=>{if(t.has(s.id))throw new f(`Duplicate statement id: ${e.id}.${s.id}`);t.add(s.id)}),e.dynamic_statements){const s=x(e.dynamic_statements);R(s,i).forEach(r=>{if(typeof r=="number")throw new l(`Dynamic statement in question ${e.id} refers to choices with values`);if(t.has(r))throw new f(`Duplicate statement ${r} via dynamic statements in question ${e.id}`);t.add(r)})}}const I=(_=e.choices)!=null?_:[];if(e.choice_groups){if(new Set(e.choice_groups.map(t=>t.id)).size!==e.choice_groups.length)throw new f(`Choice groups must have a unique id in question ${e.id}`);e.choice_groups.forEach(t=>I.push(...t.choices))}if(I||e.dynamic_choices){const t=new Set;i.seenQuestionChoices.set(e.id,t);const s=new Set;if(i.seenTextChoices.set(e.id,s),I.forEach(r=>{var d;const v=(d=r.id)!=null?d:r.value;if(t.has(v))throw new f(`Duplicate choice: ${e.id}[${v}]`);t.add(v),r.text_input&&r.text_input!=="no"&&s.add(v)}),e.dynamic_choices){const r=x(e.dynamic_choices);R(r,i).forEach(d=>{if(t.has(d))throw new f(`Duplicate choice ${d} via dynamic choices in ${e.id}`);t.add(d)}),(S=i.seenTextChoices.get(r.questionId))==null||S.forEach(d=>s.add(d))}if(new Set([...t].map(r=>typeof r)).size>=2)throw new U("All choices in a question must either all have id's or all have values")}}},j=e=>{if(!T(e))throw new Error(`Invalid template: ${e.template.id}. Reason: ${JSON.stringify(T.errors,null,4)}`);O(e);const i=new X;e.sections.forEach(n=>{m(i,n.id,n.display_logic),n.pages.forEach(a=>{var o;(o=a.questions)==null||o.forEach(u=>{P(u,i)})})})};export{j as validateTemplate};
|
|
2
|
+
//# sourceMappingURL=validateTemplate.esm.js.map
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import t from"lodash";const n=(o,s="camelCase")=>{const r=s==="camelCase"?t.camelCase:t.snakeCase;return t.transform(o,(c,a,e)=>{const m=typeof e=="string"?r(e):e;c[m]=t.isObject(a)&&!(a instanceof Date)?n(a,s):a})};export{n as transformCase};
|
|
2
|
+
//# sourceMappingURL=transformCase.esm.js.map
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@spotify/backstage-plugin-pulse-common",
|
|
3
|
-
"version": "0.11.
|
|
3
|
+
"version": "0.11.6",
|
|
4
4
|
"license": "SEE LICENSE IN LICENSE.md",
|
|
5
5
|
"homepage": "https://backstage.spotify.com",
|
|
6
6
|
"main": "dist/index.cjs.js",
|
|
@@ -28,15 +28,15 @@
|
|
|
28
28
|
"@backstage/plugin-permission-common": "^0.7.13",
|
|
29
29
|
"@ungap/structured-clone": "^1.2.0",
|
|
30
30
|
"ajv": "^8.11.2",
|
|
31
|
-
"ajv-formats": "^
|
|
31
|
+
"ajv-formats": "^3.0.0",
|
|
32
32
|
"graphql": "^16.0.0",
|
|
33
33
|
"lodash": "^4.17.21"
|
|
34
34
|
},
|
|
35
35
|
"devDependencies": {
|
|
36
|
-
"@backstage/cli": "^0.26.
|
|
36
|
+
"@backstage/cli": "^0.26.5",
|
|
37
37
|
"@types/ungap__structured-clone": "^1.0.0",
|
|
38
38
|
"js-yaml": "^4.1.0",
|
|
39
|
-
"json-schema-to-typescript": "^
|
|
39
|
+
"json-schema-to-typescript": "^14.0.0",
|
|
40
40
|
"process": "^0.11.10"
|
|
41
41
|
},
|
|
42
42
|
"files": [
|