@spotify/backstage-plugin-pulse-common 0.7.0 → 0.8.0
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 +11 -0
- package/dist/index.cjs.js +13 -13
- package/dist/index.d.ts +42 -4
- package/dist/index.esm.js +13 -13
- package/package.json +2 -2
- package/src/templates/schema/survey-template-schema.json +5 -5
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,16 @@
|
|
|
1
1
|
# @spotify/backstage-plugin-pulse-common
|
|
2
2
|
|
|
3
|
+
## 0.8.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- Added support for customizable survey flows.
|
|
8
|
+
- Added support for future experimental features.
|
|
9
|
+
|
|
10
|
+
### Patch Changes
|
|
11
|
+
|
|
12
|
+
- Upgraded Backstage to `v1.17.0`.
|
|
13
|
+
|
|
3
14
|
## 0.7.0
|
|
4
15
|
|
|
5
16
|
### Minor Changes
|
package/dist/index.cjs.js
CHANGED
|
@@ -1,23 +1,23 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var ct=require("@backstage/plugin-permission-common"),pt=require("ajv"),ut=require("ajv-formats");function ve(s){return s&&typeof s=="object"&&"default"in s?s:{default:s}}var ht=ve(pt),dt=ve(ut);const mt="survey-instance",Ne=ct.createPermission({name:"survey.instance.administer",attributes:{action:"create"}}),ft=[Ne];var yt="surveyTemplate",gt="http://json-schema.org/draft-07/schema",xt="Survey Template",wt="object",bt={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 ${p:<name>} construct (same as 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"}}},Tt=!1,vt=["template","parameters","sections"],Nt={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."},questions:{type:"array",description:"The questions in the section (all in one page)",items:{$ref:"#/$defs/question"}},pages:{type:"array",description:"The questions in the section, split into pages",items:{$ref:"#/$defs/page"}}},additionalProperties:!1,required:["id","name"],oneOf:[{required:["questions"]},{required:["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"},text_html:{type:"string",description:"The question description, in HTML"},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"},display_logic_in_page:{type:"string",description:"Similar to display_logic, but enables the question to appear on the same page as the depending question"},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|displayed|not_displayed|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. Need only be set if referenced to in constrained randomization."},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","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|displayed|not_displayed|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. Need only be set if referenced to in constrained randomization."},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","display"],additionalProperties:!1}},randomization:{$ref:"#/$defs/randomization"}},additionalProperties:!1,allOf:[{oneOf:[{required:["text"]},{required:["text_html"]}]},{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:{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}},ke={$id:yt,$schema:gt,title:xt,type:wt,properties:bt,additionalProperties:Tt,required:vt,$defs:Nt},kt=Object.defineProperty,Rt=(s,t,n)=>t in s?kt(s,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):s[t]=n,N=(s,t,n)=>(Rt(s,typeof t!="symbol"?t+"":t,n),n);class Re{}class Ee{}class te extends Error{}class R extends Error{}class E extends R{}function ne(s,t,n="Got %r, expected one of %s"){if(!t.includes(s))throw new E(h(n,s,t))}class Z extends R{}class Et extends R{}class L extends R{}class O extends R{constructor(){super(...arguments),N(this,"pos_in_stream",null),N(this,"_terminals_by_name",null)}get_context(t,n=40){let r,i;const a=this.pos_in_stream,o=max(a-n,0),_=a+n;return t instanceof bytes?(i=b(fe(t.slice(o,a),`
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var ut=require("@backstage/plugin-permission-common"),ht=require("ajv"),dt=require("ajv-formats");function Ne(s){return s&&typeof s=="object"&&"default"in s?s:{default:s}}var mt=Ne(ht),ft=Ne(dt);const yt="survey-instance",ke=ut.createPermission({name:"survey.instance.administer",attributes:{action:"create"}}),gt=[ke];var xt="surveyTemplate",wt="http://json-schema.org/draft-07/schema",bt="Survey Template",Tt="object",vt={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"}}},Nt=!1,kt=["template","parameters","sections"],Rt={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."},questions:{type:"array",description:"The questions in the section (all in one page)",items:{$ref:"#/$defs/question"}},pages:{type:"array",description:"The questions in the section, split into pages",items:{$ref:"#/$defs/page"}}},additionalProperties:!1,required:["id","name"],oneOf:[{required:["questions"]},{required:["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"},text_html:{type:"string",description:"The question description, in HTML"},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"},display_logic_in_page:{type:"string",description:"Similar to display_logic, but enables the question to appear on the same page as the depending question"},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|displayed|not_displayed|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|displayed|not_displayed|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"}},additionalProperties:!1,allOf:[{oneOf:[{required:["text"]},{required:["text_html"]}]},{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:{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}},Re={$id:xt,$schema:wt,title:bt,type:Tt,properties:vt,additionalProperties:Nt,required:kt,$defs:Rt},Et=Object.defineProperty,qt=(s,t,n)=>t in s?Et(s,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):s[t]=n,v=(s,t,n)=>(qt(s,typeof t!="symbol"?t+"":t,n),n);class Ee{}class qe{}class te extends Error{}class k extends Error{}class R extends k{}function ne(s,t,n="Got %r, expected one of %s"){if(!t.includes(s))throw new R(u(n,s,t))}class M extends k{}class Ot extends k{}class D extends k{}class q extends k{constructor(){super(...arguments),v(this,"pos_in_stream",null),v(this,"_terminals_by_name",null)}get_context(t,n=40){let r,i;const a=this.pos_in_stream,o=max(a-n,0),_=a+n;return t instanceof bytes?(i=w(fe(t.slice(o,a),`
|
|
2
2
|
`,1)),r=t.slice(a,_).split(`
|
|
3
3
|
`,1)[0],`${i+r}
|
|
4
4
|
${" "*i.expandtabs().length}^
|
|
5
|
-
`.decode("ascii","backslashreplace")):(i=
|
|
5
|
+
`.decode("ascii","backslashreplace")):(i=w(fe(t.slice(o,a),`
|
|
6
6
|
`,1)),r=t.slice(a,_).split(`
|
|
7
7
|
`,1)[0],`${i+r}
|
|
8
8
|
${" "*i.expandtabs().length}^
|
|
9
|
-
`)}match_examples(t,n,r=!1){me(n)&&(n=g(n));let i=[null,!1];for(const[a,[o,_]]of
|
|
9
|
+
`)}match_examples(t,n,r=!1){me(n)&&(n=g(n));let i=[null,!1];for(const[a,[o,_]]of C(n))for(const[c,l]of C(_))try{t(l)}catch(p){if(p instanceof q){if(p.state.eq(this.state)){if(p.token===this.token)return o;r&&p.token.type===this.token.type&&!w(i)&&(i=[o,!0]),i[0]===null&&(i=[o,!1])}}else throw p}return i[0]}_format_expected(t){let n;return this._terminals_by_name&&(n=this._terminals_by_name,t=t.map(r=>r in n?n[r].user_repr():r)),u(`Expected one of:
|
|
10
10
|
* %s
|
|
11
11
|
`,t.join(`
|
|
12
|
-
* `))}}class
|
|
12
|
+
* `))}}class At extends q{constructor(t,n=null,r=null){super(),this.expected=t,this.state=n,this.token=new f("<EOF>",""),this.pos_in_stream=-1,this.line=-1,this.column=-1,this._terminals_by_name=r}}class $ extends q{constructor({seq:t,lex_pos:n,line:r,column:i,allowed:a=null,considered_tokens:o=null,state:_=null,token_history:c=null,terminals_by_name:l=null,considered_rules:p=null}={}){super(),this.line=r,this.column=i,this.pos_in_stream=n,this.state=_,this._terminals_by_name=l,this.allowed=a,this.considered_tokens=o,this.considered_rules=p,this.token_history=c,this.char=t[n]}}class P extends q{constructor({token:t,expected:n,considered_rules:r=null,state:i=null,interactive_parser:a=null,terminals_by_name:o=null,token_history:_=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=n,this._accepts=Be,this.considered_rules=r,this.interactive_parser=a,this._terminals_by_name=o,this.token_history=_}get accepts(){return this._accepts===Be&&(this._accepts=this.interactive_parser&&this.interactive_parser.accepts()),this._accepts}}class re extends k{constructor(t,n,r){const i=u(`Error trying to process rule "%s":
|
|
13
13
|
|
|
14
|
-
%s`,t,r);super(i),this.rule=t,this.obj=n,this.orig_exc=r}}function
|
|
15
|
-
`];const r=[
|
|
16
|
-
`];for(const i of this.children)i instanceof y?r.push(...i._pretty(t+1,n)):r.push(
|
|
17
|
-
`);return r}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];const n=new Map;for(const r of t)n.set(r,r),t.push(...[...r.children].reverse().filter(i=>i instanceof y&&!n.has(i)).map(i=>i));return t=void 0,[...n.values()].reverse()}find_pred(t){return
|
|
18
|
-
`)||s.includes("\\n")||s.includes("\\s")||s.includes("[^")||s.includes("(?s")&&s.includes(".")}class
|
|
19
|
-
`),this.last_token=r}eq(t){return t instanceof be?this.text===t.text&&this.line_ctr===t.line_ctr&&this.last_token===t.last_token:C}}class Ae{constructor(t,n){this.lexer=t,this.state=n}static from_text(t,n){return new this(t,new be(n))}lex(t){return this.lexer.lex(this.state,t)}}class W extends Re{lex(t,n){return C}}function Zt(s,t){s.sort((n,r)=>{const i=t(n),a=t(r);for(let o=0;o<i.length;o++){if(i[o]>a[o])return 1;if(i[o]<a[o])return-1}return 0})}class J extends W{constructor(t){super();const n=[...t.terminals];if(this.re=t.re_module,!t.skip_validation){for(const r of n){try{this.re.compile(r.pattern.to_regexp(),t.g_regex_flags)}catch(i){throw i instanceof this.re.error?new L(h("Cannot compile token %s: %s",r.name,r.pattern)):i}if(r.pattern.min_width===0)throw new L(h("Lexer does not allow zero-width terminals. (%s: %s)",r.name,r.pattern))}if(!(new Set(t.ignore)<=new Set(n.map(r=>r.name))))throw new L(h("Ignore terminals are not defined: %s",Ye(new Set(t.ignore),new Set(n.map(r=>r.name)))))}this.newline_types=Y(n.filter(r=>Ut(r.pattern.to_regexp())).map(r=>r.name)),this.ignore_types=Y(t.ignore),Zt(n,r=>[-r.priority,-r.pattern.max_width,-r.pattern.value.length,r.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]=Ft(this.terminals,this.g_regex_flags,this.re,this.use_bytes);for(const[n,r]of g(this.user_callbacks))n in this.callback?this.callback[n]=new Qt(this.callback[n],r,i=>i.type===n):this.callback[n]=r;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,n){return this.scanner.match(t,n)}*lex(t,n){try{for(;;)yield this.next_token(t,n)}catch(r){if(!(r instanceof te))throw r}}next_token(t,n=null){let r,i,a,o;const _=t.line_ctr;for(;_.char_pos<t.text.length;){if(i=this.match(t.text,_.char_pos),!i)throw r=Ye(this.scanner.allowed_types,this.ignore_types),r||(r=new Set(["<END-OF-FILE>"])),new $({seq:t.text,lex_pos:_.char_pos,line:_.line,column:_.column,allowed:r,token_history:t.last_token&&[t.last_token],state:n,terminals_by_name:this.terminals_by_name});const[c,l]=i;if(!this.ignore_types.has(l)){if(a=new f(l,c,_.char_pos,_.line,_.column),_.feed(c,this.newline_types.has(l)),a.end_line=_.line,a.end_column=_.column,a.end_pos=_.char_pos,a.type in this.callback&&(a=this.callback[a.type](a),!(a instanceof f)))throw new L(h("Callbacks must return a token (returned %r)",a));return t.last_token=a,a}l in this.callback&&(o=new f(l,c,_.char_pos,_.line,_.column),this.callback[l](o)),_.feed(c,this.newline_types.has(l))}throw new te(this)}}class Mt extends W{constructor({conf:t,states:n,always_accept:r=[]}={}){super();let i,a,o;const _=[...t.terminals],c=t.terminals_by_name,l=k(t);l.terminals=_;const p=new Map;this.lexers={};for(let[u,m]of g(n))i=Y(m),p.has(i)?a=p.get(i):(m=Nn(new Set(m),[...new Set(t.ignore),...new Set(r)]),o=k(l),o.terminals=[...m].filter(d=>d in c).map(d=>c[d]),a=new J(o),p.set(i,a)),this.lexers[u]=a;this.root_lexer=new J(l)}*lex(t,n){let r,i,a;try{for(;;)i=this.lexers[n.position],yield i.next_token(t,n)}catch(o){if(!(o instanceof te))if(o instanceof $)try{throw r=t.last_token,a=this.root_lexer.next_token(t,n),new P({token:a,expected:o.allowed,state:n,token_history:[r],terminals_by_name:this.root_lexer.terminals_by_name})}catch(_){throw _}else throw o}}}class Ie extends w{static get __serialize_fields__(){return["terminals","ignore","g_regex_flags","use_bytes","lexer_type"]}static get __serialize_namespace__(){return[G]}constructor({terminals:t,re_module:n,ignore:r=[],postlex:i=null,callbacks:a=null,g_regex_flags:o="",skip_validation:_=!1,use_bytes:c=!1}={}){super(),this.terminals=t,this.terminals_by_name=Object.fromEntries(this.terminals.map(l=>[l.name,l])),this.ignore=r,this.postlex=i,this.callbacks=Object.keys(a).length||{},this.g_regex_flags=o,this.re_module=n,this.skip_validation=_,this.use_bytes=c,this.lexer_type=null}_deserialize(){this.terminals_by_name=Object.fromEntries(this.terminals.map(t=>[t.name,t]))}}class $e extends w{static get __serialize_fields__(){return["rules","start","parser_type"]}constructor(t,n,r){super(),this.rules=t,this.callbacks=n,this.start=r,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 Gt=I(Bt);class Wt{constructor(t,n=null){this.node_builder=t,this.node_filter=n}__call__(t){let n,r,i;const a=this.node_builder(t);return a instanceof y&&(i=a.meta,n=this._pp_get_meta(t),n!==null&&("line"in i||(i.line=n&&n.container_line||n.line,i.column=n&&n.container_column||n.column,i.start_pos=n&&n.container_start_pos||n.start_pos,i.empty=!1),i.container_line=n&&n.container_line||n.line,i.container_column=n&&n.container_column||n.column),r=this._pp_get_meta([...t].reverse()),r!==null&&("end_line"in i||(i.end_line=r&&r.container_end_line||r.end_line,i.end_column=r&&r.container_end_column||r.end_column,i.end_pos=r&&r.container_end_pos||r.end_pos,i.empty=!1),i.container_end_line=r&&r.container_end_line||r.end_line,i.container_end_column=r&&r.container_end_column||r.end_column)),a}_pp_get_meta(t){for(const n of t)if(!(this.node_filter!==null&&!this.node_filter(n))){if(n instanceof y){if(!n.meta.empty)return n.meta}else if(n instanceof f)return n}}}const Pe=I(Wt);function Jt(s){if(Rn(s))return K({unknown_param_0:Pe,node_filter:s});if(s===!0)return Pe;if(s===!1)return null;throw new E(h("Invalid option for propagate_positions: %r",s))}class pe{constructor(t,n,r){this.node_builder=r,this.to_include=t,this.append_none=n}__call__(t){const n=[];for(const[r,i,a]of this.to_include)a&&n.push(...q([null],a)),i?n.push(...t[r].children):n.push(t[r]);return this.append_none&&n.push(...q([null],this.append_none)),this.node_builder(n)}}const Vt=I(pe);class Yt extends pe{__call__(t){let n=[];for(const[r,i,a]of this.to_include)a&&n.push(...q([null],a)),i?n.length?n.push(...t[r].children):n=t[r].children:n.push(t[r]);return this.append_none&&n.push(...q([null],this.append_none)),this.node_builder(n)}}const Kt=I(Yt);class Ht extends pe{constructor(t,n){super(),this.node_builder=n,this.to_include=t}__call__(t){let n=[];for(const[r,i]of this.to_include)i?n.length?n.push(...t[r].children):n=t[r].children:n.push(t[r]);return this.node_builder(n)}}const Xt=I(Ht);function en(s){return!s.is_term&&s.name.startsWith("_")}function tn(s,t,n,r){let i,a;r.length?(a=r.map(c=>(0+c).toString()).join(""),i=a.split("0").map(c=>c.length)):i=q([0],s.length+1);const o=[];let _=0;for(const[c,l]of Q(s))_+=i[c],(t||!(l.is_term&&l.filter_out))&&(o.push([c,en(l),_]),_=0);if(_+=i[s.length],r.length||o.length<s.length||En(o.map(([c,l,p])=>l)))return(r.length||n).length?K(n?Vt:Kt,o,_):K(Xt,o.map(([c,l,p])=>[c,l]))}function nn(s){function t(n){const r=new y(s.name,n);return s(r)}return t=wraps(s)(t),t}function rn(s,t,n){if(n===_vargs_meta||n===_vargs_meta_inline)throw new NotImplementedError("Meta args not supported for internal transformer");function r(i){return n(s,t,i,null)}return r=wraps(s)(r),r}class sn{constructor(t,n,r=!1,i=!1,a=!1){this.tree_class=n,this.propagate_positions=r,this.ambiguous=i,this.maybe_placeholders=a,this.rule_builders=[...this._init_builders(t)]}*_init_builders(t){let n,r,i,a;const o=Jt(this.propagate_positions);for(const _ of t)i=_.options,r=i.keep_all_tokens,n=i.expand1,a=[...Xe(null,[n&&!_.alias&&Gt,tn(_.expansion,r,this.ambiguous,this.maybe_placeholders?i.empty_indices:[]),o])],yield[_,a]}create_callback(t=null){let n,r,i;const a=new Map;for(const[o,_]of this.rule_builders){r=o.alias||o.options.template_source||o.origin.name,t&&t[r]?(n=t&&t[r],i=n&&n.visit_wrapper||null,i!==null?n=rn(n,r,i):t instanceof Oe&&(n=nn(n))):n=K(this.tree_class,r);for(const c of _)n=c(n);if(a.has(o))throw new Z(h("Rule '%s' already exists",o));a.set(o,n)}return a}}class Se extends w{constructor({parser_conf:t,debug:n=!1}={}){super();const r=new LALR_Analyzer({unknown_param_0:t,debug:n});r.compute_lalr();const i=t.callbacks;this._parse_table=r.parse_table,this.parser_conf=t,this.parser=new ze(r.parse_table,i,n)}static deserialize(t,n,r,i=!1){const a=de(this);return a._parse_table=_n.deserialize(t,n),a.parser=new ze(a._parse_table,r,i),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:r=null}={}){let i,a;try{return this.parser.parse({lexer:t,start:n})}catch(o){if(o instanceof O){if(r===null)throw o;for(;;){if(o instanceof $&&(a=o.interactive_parser.lexer_thread.state,i=a.line_ctr.char_pos),!r(o))throw o;o instanceof $&&i===a.line_ctr.char_pos&&a.line_ctr.feed(a.text.slice(i,i+1));try{return o.interactive_parser.resume_parse()}catch(_){if(_ instanceof P){if(o instanceof P&&o.token.type===_.token.type&&_.token.type==="$END"&&o.interactive_parser.eq(_.interactive_parser))throw _;o=_}else if(_ instanceof $)o=_;else throw _}}}else throw o}}}class an{constructor(t,n,r){this.parse_table=t,this.start_state=this.parse_table.start_states[r],this.end_state=this.parse_table.end_states[r],this.states=this.parse_table.states,this.callbacks=n,this.start=r}}class Te{constructor(t,n,r=null,i=null){this.parse_conf=t,this.lexer=n,this.state_stack=r||[this.parse_conf.start_state],this.value_stack=i||[]}get position(){return b(this.state_stack)}eq(t){return t instanceof Te?this.state_stack.length===t.state_stack.length&&this.position===t.position:C}copy(){return k(this)}feed_token(t,n=!1){let r,i,a,o,_,c,l,p,u,m;const d=this.state_stack,x=this.value_stack,v=this.parse_conf.states,lt=this.parse_conf.end_state,X=this.parse_conf.callbacks;for(;;){if(u=b(d),t.type in v[u])[i,a]=v[u][t.type];else throw o=new Set(he(v[u]).filter(ee=>et(ee)).map(ee=>ee)),new P({token:t,expected:o,state:this,interactive_parser:null});if(i===ue){d.push(a),x.push(t.type in X?X[t.type](t):t);return}if(c=a,p=c.expansion.length,p?(l=x.slice(-p),d.splice(-p),x.splice(-p)):l=[],m=X.get(c)(l),[r,_]=v[b(d)][c.origin.name],d.push(_),x.push(m),n&&b(d)===lt)return b(x)}}}class ze{constructor(t,n,r=!1){this.parse_table=t,this.callbacks=n,this.debug=r}parse({lexer:t,start:n,value_stack:r=null,state_stack:i=null,start_interactive:a=!1}={}){const o=new an(this.parse_table,this.callbacks,n),_=new Te(o,t,i,r);return a?new A(this,_,_.lexer):this.parse_from_state(_)}parse_from_state(t){let n,r;try{r=null;for(r of t.lexer.lex(t))t.feed_token(r);return n=r?f.new_borrow_pos("$END","",r):new f("$END","",0,1,1),t.feed_token(n,!0)}catch(i){if(i instanceof O){try{i.interactive_parser=new A(this,t,t.lexer)}catch(a){if(!(a instanceof ReferenceError))throw a}throw i}else if(i instanceof Error){if(this.debug){console.log(""),console.log("STATE STACK DUMP"),console.log("----------------");for(const[a,o]of Q(t.state_stack))console.log(h("%d)",a),o);console.log("")}throw i}else throw i}}}class A{constructor(t,n,r){this.parser=t,this.parser_state=n,this.lexer_thread=r,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){const n=t!==null?f.new_borrow_pos("$END","",t):new f("$END","",0,1,1);return this.feed_token(n)}copy(){return k(this)}eq(t){return t instanceof A?this.parser_state===t.parser_state&&this.lexer_thread===t.lexer_thread:!1}as_immutable(){const t=k(this);return new De(t.parser,t.parser_state,t.lexer_thread)}pretty(){const t=["Parser choices:"];for(const[n,r]of g(this.choices()))t.push(h(" - %s -> %r",n,r));return t.push(h("stack size: %s",this.parser_state.state_stack.length)),t.join(`
|
|
20
|
-
`)}choices(){return this.parser_state.parse_conf.parse_table.states[this.parser_state.position]}accepts(){let t;const n=new Set;for(const r of this.choices())if(et(r)){t=k(this);let i=null;try{t.feed_token(new f(r,""))}catch(a){if(i=a,!(a instanceof P))throw a}i||n.add(r)}return n}resume_parse(){return this.parser.parse_from_state(this.parser_state)}}class De extends A{constructor(){super(...arguments),N(this,"result",null)}feed_token(t){const n=k(this);return n.result=A.feed_token(n,t),n}exhaust_lexer(){const t=this.as_mutable();return t.exhaust_lexer(),t.as_immutable()}as_mutable(){const t=k(this);return new A(t.parser,t.parser_state,t.lexer_thread)}}class Le{constructor(t){this.name=t}repr(){return this.toString()}}var ue=new Le("Shift");const je=new Le("Reduce");class on{constructor(t,n,r){this.states=t,this.start_states=n,this.end_states=r}serialize(t){const n=new Enumerator,r=Object.fromEntries(g(this.states).map(([i,a])=>[i,Object.fromEntries(g(a).map(([o,[_,c]])=>[Je(n,o),_===je?[1,c.serialize(t)]:[0,c]]))]));return{tokens:n.reversed(),states:r,start_states:this.start_states,end_states:this.end_states}}static deserialize(t,n){const r=this,i=t.tokens,a=Object.fromEntries(g(t.states).map(([o,_])=>[o,Object.fromEntries(g(_).map(([c,[l,p]])=>[i[c],l===1?[je,D.deserialize(p,n)]:[ue,p]]))]));return new r(a,t.start_states,t.end_states)}}class _n extends on{static from_ParseTable(t){const n=this,r=[...t.states],i=Object.fromEntries(Q(r).map(([c,l])=>[l,c])),a={};for(let[c,l]of g(t.states))l=Object.fromEntries(g(l).map(([p,u])=>[p,u[0]===ue?[u[0],i[u[1]]]:u])),a[i[c]]=l;const o=Object.fromEntries(g(t.start_states).map(([c,l])=>[c,i[l]])),_=Object.fromEntries(g(t.end_states).map(([c,l])=>[c,i[l]]));return new n(a,o,_)}}function ln(s){if(s&&s.__future_interface__)return s;class t extends W{constructor(r){super(),this.lexer=s(r)}lex(r,i){return this.lexer.lex(r.text)}}return t}function cn(s,t,n,r,i){const a=$e.deserialize(s.parser_conf,t),o=Se.deserialize(s.parser,t,r,i.debug);return a.callbacks=r,new pn({lexer_conf:n,parser_conf:a,options:i,parser:o})}const Ce={};class pn extends w{static get __serialize_fields__(){return["lexer_conf","parser_conf","parser"]}constructor({lexer_conf:t,parser_conf:n,options:r,parser:i=null}={}){super();let a,o;this.parser_conf=n,this.lexer_conf=t,this.options=r,i?this.parser=i:(o=Je(Ce,n.parser_type),this.parser=o(t,n,r));const _=t.lexer_type;if(this.skip_lexer=!1,["dynamic","dynamic_complete"].includes(_)){this.skip_lexer=!0;return}const c={basic:mn,contextual:fn};_ in c?(a=c[_],this.lexer=a(t,this.parser,t.postlex,r)):this.lexer=ln(_)(t),t.postlex&&(this.lexer=new dn(this.lexer,t.postlex))}_verify_start(t=null){let n;if(t===null){if(n=this.parser_conf.start,n.length>1)throw new E("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 E(h("Unknown start rule %s. Must be one of %r",t,this.parser_conf.start));return t}_make_lexer_thread(t){return this.skip_lexer?t:Ae.from_text(this.lexer,t)}parse(t,n=null,r=null){const i=this._verify_start(n),a=r===null?{}:{on_error:r},o=this._make_lexer_thread(t);return this.parser.parse({lexer:o,start:i,...a})}parse_interactive(t=null,n=null){const r=this._verify_start(n);if(this.parser_conf.parser_type!=="lalr")throw new E("parse_interactive() currently only works with parser='lalr' ");const i=this._make_lexer_thread(t);return this.parser.parse_interactive(i,r)}}function un(s,t){let n;ne(s,["lalr","earley","cyk"]),typeof t!="object"&&(n={lalr:["basic","contextual"],earley:["basic","dynamic","dynamic_complete"],cyk:["basic"]}[s],ne(t,n,h("Parser %r does not support lexer %%r, expected one of %%s",s)))}function hn(s,t){let n;const r={};for(const i of t)n=s&&s[i.name]||null,n!==null&&(r[i.name]=n);return r}class dn{constructor(t,n){this.lexer=t,this.postlexer=n}lex(t,n){const r=this.lexer.lex(t,n);return this.postlexer.process(r)}}function mn(s,t,n,r){return new J(s)}function fn(s,t,n,r){const i=Object.fromEntries(g(t._parse_table.states).map(([o,_])=>[o,[...he(_)]])),a=n?n.always_accept:[];return new Mt({conf:s,states:i,always_accept:a})}function yn(s,t,n=null){const r=n?n.debug:!1;return new Se({parser_conf:t,debug:r})}Ce.lalr=yn;class Qe extends Re{constructor(){super(...arguments),N(this,"always_accept",[])}process(t){return t}}class gn extends w{constructor(t){super(),N(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 '),N(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;const r=Ke(t),i=this;for(const[a,o]of g(this._defaults))a in r?(n=Tn(r,a),typeof o=="boolean"&&!["cache","use_bytes","propagate_positions"].includes(a)&&(n=He(n))):n=o,i[a]=n;if(typeof i.start=="string"&&(i.start=[i.start]),this.options=i,ne(this.parser,["earley","lalr","cyk",null]),this.parser==="earley"&&this.transformer)throw new E("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(r).length)throw new E(h("Unknown options: %s",he(r)))}serialize(t){return this.options}static deserialize(t,n){const r=this;return new r(t)}}class Fe extends w{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 J(n)}_prepare_callbacks(){this._callbacks=new Map,this.options.ambiguity!=="forest"&&(this._parse_tree_builder=new sn(this.rules,this.options.tree_class||vn(y),this.options.propagate_positions,this.options.parser!=="lalr"&&this.options.ambiguity==="explicit",this.options.maybe_placeholders),this._callbacks=this._parse_tree_builder.create_callback(this.options.transformer)),Ve(this._callbacks,hn(this.options.transformer,this.terminals))}_deserialize_lexer_conf(t,n,r){const i=Ie.deserialize(t.lexer_conf,n);return i.callbacks=r.lexer_callbacks||{},i.re_module=r.regex?regex:Be,i.use_bytes=r.use_bytes,i.g_regex_flags=r.g_regex_flags||"",i.skip_validation=!0,i.postlex=r.postlex,i}_load({f:t,...n}={}){let r;me(t)?r=t:r=pickle.load(t);const i=r.memo,a=r.data,o=At.deserialize(i,{Rule:D,TerminalDef:G},{}),_=Ke(a.options);return Ve(_,n),this.options=gn.deserialize(_,o),this.rules=a.rules.map(c=>D.deserialize(c,o)),this.source_path="<deserialized>",un(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(c=>[c.name,c])),this.parser=cn(a.parser,o,this.lexer_conf,this._callbacks,this.options),this}static _load_from_dict({data:t,memo:n,...r}={}){return de(this)._load({f:{data:t,memo:n},...r})}repr(){return h("Lark(open(%r), parser=%r, lexer=%r, ...)",this.source_path,this.options.parser,this.options.lexer)}lex(t,n=!1){let r;!("lexer"in this)||n?r=this._build_lexer(n):r=this.lexer;const i=Ae.from_text(r,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,n=null){return this.parser.parse_interactive({unknown_param_0:t,start:n})}parse(t,n=null,r=null){return this.parser.parse(t,n,r)}}class Ue extends R{}class Ze extends Qe{constructor(){super(),this.paren_level=0,this.indent_level=[0]}*handle_NL(t){if(this.paren_level>0)return;yield t;const n=fe(t.value,`
|
|
21
|
-
`,1)[1],r=ye(n," ")+ye(n," ")*this.tab_len;if(r>b(this.indent_level))this.indent_level.push(r),yield f.new_borrow_pos(this.INDENT_type,n,t);else{for(;r<b(this.indent_level);)this.indent_level.pop(),yield f.new_borrow_pos(this.DEDENT_type,n,t);if(r!==b(this.indent_level))throw new Ue(h("Unexpected dedent to column %s. Expected dedent to %s",r,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 f(this.DEDENT_type,"")}process(t){return this.paren_level=0,this.indent_level=[0],this._process(t)}get always_accept(){return[this.NL_type]}get NL_type(){throw new NotImplementedError}get OPEN_PAREN_types(){throw new NotImplementedError}get CLOSE_PAREN_types(){throw new NotImplementedError}get INDENT_type(){throw new NotImplementedError}get DEDENT_type(){throw new NotImplementedError}get tab_len(){throw new NotImplementedError}}class xn extends Ze{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}}function wn(s={}){return s.transformer&&s.transformer.constructor.name==="object"&&(s.transformer=j.fromObj(s.transformer)),Fe._load_from_dict({data:$n,memo:Pn,...s})}const Me={},V={},Be={escape(s){return s.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")},compile(s,t){return new RegExp(s,t)},error:SyntaxError};function bn(s,t,n,r){const i=s.compile(t,r).exec(n);if(i!=null)return i[0]}class Ge{constructor(t,n,r,i,a=!1){this.terminals=t,this.g_regex_flags=n,this.re_=r,this.use_bytes=i,this.match_whole=a,this.allowed_types=new Set(this.terminals.map(o=>o.name)),this._regexps=this._build_mres(t)}_build_mres(t){const n=this.match_whole?"$":"",r=On(t,a=>a.pattern.flags.join("")),i=[];for(const[a,o]of r){const _=o.map(c=>`(?<${c.name}>${c.pattern.to_regexp()+n})`).join("|");i.push(new RegExp(_,`${this.g_regex_flags+a}y`))}return i}match(t,n){for(const r of this._regexps){r.lastIndex=n;const i=r.exec(t);if(i){let a=null;for(const[o,_]of Object.entries(i.groups))if(_){a=o;break}return[i[0],a]}}}}const We=typeof require!="undefined"&&require("util"),C={};function g(s){return Object.entries(s)}function he(s){return Object.keys(s)}function Tn(s,t){t===void 0&&(t=Object.keys(s)[0]);const n=s[t];return delete s[t],n}function Je(s,t,n=null){return s[t]||n}function Ve(s,t){if(s.constructor.name==="Map")for(const[n,r]of g(t))s.set(n,r);else for(const[n,r]of g(t))s[n]=r}function vn(s){return function(){return new s(...arguments)}}function h(s){let t=0;const n=[...arguments].slice(1);return s.replace(/%([sr])/g,function(){const r=arguments[1],i=n[t++];return r==="r"?We?We.inspect(i,!1,null,!0):JSON.stringify(i,null,0):i})}function Nn(s,t){const n=new Set(s);for(const r of t)n.add(r);return n}function Ye(s,t){return[...s].filter(n=>!t.has(n))}function Ke(s){return{...s}}function He(s){return!!s}function de(s){return Object.create(s.prototype)}function k(s){if(typeof s=="object"){const t=Object.create(Object.getPrototypeOf(s));return Object.assign(t,s)}return s}function Y(s){return new Set(s)}function me(s){return s&&s.constructor.name==="Object"}function kn(s){return s&&s.constructor.name==="Array"}function Rn(s){return typeof s=="function"}function*Q(s,t=0){let n=t;for(const r of s)yield[n++,r]}function En(s){for(const t of s)if(t)return!0;return!1}function Xe(s,t){return t.filter(s||He)}function K(s){const t=[...arguments].slice(1);return function(){return s(...t,...arguments)}}function b(s){return s[s.length-1]}function I(s){return function(){const t=new s(...arguments);return t.__call__.bind(t)}}function q(s,t){return Array.from({length:t},()=>s).flat()}function et(s){return/^[A-Z_$]*$/.test(s)}function fe(s,t,n){const r=s.split(t);return n?r.splice(-n-1):r}function ye(s,t){const n=new RegExp(t,"g");return(s.match(n)||[]).length}function qn(s,t){for(const n of s)if(!t.has(n))return!1;return!0}function*On(s,t){let n=[],r=null;for(const i of s){const a=t(i);r&&a!=r&&(yield[r,n],n=[]),n.push(i),r=a}yield[r,n]}const An={Terminal:ae,NonTerminal:oe,RuleOptions:B,PatternStr:le,PatternRE:ce,TerminalDef:G};var In={LarkError:R,ConfigurationError:E,GrammarError:Z,ParseError:Et,LexError:L,UnexpectedInput:O,UnexpectedEOF:qt,UnexpectedCharacters:$,UnexpectedToken:P,VisitError:re,Meta:qe,Tree:y,Discard:V,Transformer:j,Transformer_InPlace:Oe,Transformer_NonRecursive:It,Transformer_InPlaceRecursive:$t,VisitorBase:se,Visitor:Pt,Visitor_Recursive:St,Interpreter:zt,Symbol:ie,Terminal:ae,NonTerminal:oe,RuleOptions:B,Rule:D,Pattern:_e,PatternStr:le,PatternRE:ce,TerminalDef:G,Token:f,Lexer:W,LexerConf:Ie,ParserConf:$e,InteractiveParser:A,ImmutableInteractiveParser:De,PostLex:Qe,Lark:Fe,DedentError:Ue,Indenter:Ze,PythonIndenter:xn,get_parser:wn},$n={parser:{lexer_conf:{terminals:[{"@":0},{"@":1},{"@":2},{"@":3},{"@":4},{"@":5},{"@":6},{"@":7},{"@":8},{"@":9},{"@":10},{"@":11},{"@":12},{"@":13},{"@":14},{"@":15},{"@":16},{"@":17},{"@":18},{"@":19},{"@":20}],ignore:["WS"],g_regex_flags:0,use_bytes:!1,lexer_type:"contextual",__type__:"LexerConf"},parser_conf:{rules:[{"@":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},{"@":49},{"@":50},{"@":51},{"@":52},{"@":53},{"@":54},{"@":55},{"@":56}],start:["start"],parser_type:"lalr",__type__:"ParserConf"},parser:{tokens:{0:"CONJUNCTION",1:"RPAR",2:"$END",3:"STRING",4:"IDENTIFIER",5:"INT",6:"OPERATOR",7:"RSQB",8:"__ANON_0",9:"__ANON_1",10:"mc_choice_selector",11:"question_selector",12:"LSQB",13:"__ANON_6",14:"bool_expr",15:"__ANON_3",16:"qc_mc_text_ignore_case",17:"NEGATION",18:"qc_matrix_displayed",19:"bool_const",20:"qc_mc_count",21:"qc_mc_displayed",22:"condition",23:"TRUE",24:"qc_matrix_selected",25:"qc_mc_text",26:"__ANON_4",27:"qc_matrix_count",28:"FALSE",29:"qc_mc_selected",30:"__ANON_2",31:"__ANON_5",32:"matrix_statement_selector",33:"matrix_choice_selector",34:"LPAR",35:"top_level_expr",36:"DOT",37:"start"},states:{0:{0:[0,59],1:[1,{"@":25}],2:[1,{"@":25}]},1:{1:[0,69]},2:{3:[0,65]},3:{1:[1,{"@":34}],0:[1,{"@":34}],2:[1,{"@":34}]},4:{4:[0,73],5:[0,8]},5:{0:[0,46],2:[1,{"@":23}]},6:{6:[0,7]},7:{3:[0,47]},8:{7:[0,17]},9:{8:[0,83],9:[0,56]},10:{1:[1,{"@":33}],0:[1,{"@":33}],2:[1,{"@":33}]},11:{1:[1,{"@":46}],0:[1,{"@":46}],2:[1,{"@":46}]},12:{1:[1,{"@":36}],0:[1,{"@":36}],2:[1,{"@":36}]},13:{10:[0,16],4:[0,72],11:[0,35]},14:{12:[0,31]},15:{1:[1,{"@":39}],0:[1,{"@":39}],2:[1,{"@":39}]},16:{1:[0,6]},17:{1:[1,{"@":50}]},18:{13:[0,54]},19:{1:[1,{"@":27}],0:[1,{"@":27}],2:[1,{"@":27}]},20:{4:[0,72],11:[0,61]},21:{1:[1,{"@":53}]},22:{4:[0,28]},23:{1:[1,{"@":44}],0:[1,{"@":44}],2:[1,{"@":44}]},24:{2:[1,{"@":22}]},25:{1:[1,{"@":37}],0:[1,{"@":37}],2:[1,{"@":37}]},26:{1:[1,{"@":28}],0:[1,{"@":28}],2:[1,{"@":28}]},27:{6:[0,71]},28:{12:[1,{"@":52}],1:[1,{"@":52}]},29:{5:[0,45]},30:{14:[0,78],15:[0,62],16:[0,55],17:[0,9],8:[0,38],18:[0,3],19:[0,19],20:[0,50],21:[0,51],22:[0,0],23:[0,48],24:[0,10],25:[0,82],9:[0,70],26:[0,32],27:[0,68],28:[0,52],29:[0,26],30:[0,13],31:[0,20]},31:{5:[0,34],4:[0,33]},32:{11:[0,74],4:[0,72]},33:{7:[0,81]},34:{7:[0,21]},35:{12:[0,4]},36:{5:[0,18],4:[0,66]},37:{6:[0,29]},38:{4:[0,72],32:[0,14],10:[0,49],33:[0,60],11:[0,84]},39:{1:[1,{"@":47}],0:[1,{"@":47}],2:[1,{"@":47}]},40:{1:[0,75]},41:{1:[1,{"@":26}],2:[1,{"@":26}]},42:{1:[0,43]},43:{1:[1,{"@":45}],0:[1,{"@":45}],2:[1,{"@":45}]},44:{2:[1,{"@":24}]},45:{1:[1,{"@":48}],0:[1,{"@":48}],2:[1,{"@":48}]},46:{34:[0,30],35:[0,44]},47:{1:[1,{"@":40}],0:[1,{"@":40}],2:[1,{"@":40}]},48:{1:[1,{"@":55}],0:[1,{"@":55}],2:[1,{"@":55}]},49:{1:[0,25]},50:{1:[1,{"@":32}],0:[1,{"@":32}],2:[1,{"@":32}]},51:{1:[1,{"@":29}],0:[1,{"@":29}],2:[1,{"@":29}]},52:{1:[1,{"@":56}],0:[1,{"@":56}],2:[1,{"@":56}]},53:{1:[0,79]},54:{6:[0,58]},55:{1:[1,{"@":31}],0:[1,{"@":31}],2:[1,{"@":31}]},56:{11:[0,84],4:[0,72],32:[0,42],10:[0,40]},57:{},58:{5:[0,39]},59:{14:[0,41],15:[0,62],16:[0,55],17:[0,9],8:[0,38],18:[0,3],19:[0,19],20:[0,50],21:[0,51],22:[0,0],23:[0,48],24:[0,10],25:[0,82],9:[0,70],26:[0,32],27:[0,68],28:[0,52],29:[0,26],30:[0,13],31:[0,20]},60:{1:[0,23]},61:{12:[0,36]},62:{4:[0,72],10:[0,53],11:[0,35]},63:{1:[0,12]},64:{2:[1,{"@":21}]},65:{1:[1,{"@":41}],0:[1,{"@":41}],2:[1,{"@":41}]},66:{13:[0,37]},67:{1:[1,{"@":42}],0:[1,{"@":42}],2:[1,{"@":42}]},68:{1:[1,{"@":35}],0:[1,{"@":35}],2:[1,{"@":35}]},69:{1:[1,{"@":43}],0:[1,{"@":43}],2:[1,{"@":43}]},70:{11:[0,84],4:[0,72],32:[0,77],10:[0,76]},71:{5:[0,67]},72:{12:[1,{"@":49}],1:[1,{"@":49}],36:[1,{"@":49}]},73:{7:[0,85]},74:{1:[0,27]},75:{1:[1,{"@":38}],0:[1,{"@":38}],2:[1,{"@":38}]},76:{1:[0,15]},77:{1:[0,11]},78:{1:[0,5]},79:{6:[0,2]},80:{15:[0,62],34:[0,30],17:[0,9],16:[0,55],8:[0,38],18:[0,3],19:[0,19],35:[0,64],20:[0,50],21:[0,51],22:[0,0],37:[0,57],23:[0,48],24:[0,10],25:[0,82],9:[0,70],26:[0,32],14:[0,24],27:[0,68],28:[0,52],29:[0,26],30:[0,13],31:[0,20]},81:{1:[1,{"@":54}]},82:{1:[1,{"@":30}],0:[1,{"@":30}],2:[1,{"@":30}]},83:{4:[0,72],32:[0,14],10:[0,63],11:[0,84],33:[0,1]},84:{12:[0,4],36:[0,22]},85:{1:[1,{"@":51}]}},start_states:{start:80},end_states:{start:57}},__type__:"ParsingFrontend"},rules:[{"@":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},{"@":49},{"@":50},{"@":51},{"@":52},{"@":53},{"@":54},{"@":55},{"@":56}],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"},Pn={0:{name:"WS",pattern:{value:`(?:[ \f\r
|
|
22
|
-
])+`,flags:[],_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:[],_width:[2,4294967295],__type__:"PatternRE"},priority:0,__type__:"TerminalDef"},2:{name:"INT",pattern:{value:"-?[0-9]+",flags:[],_width:[1,4294967295],__type__:"PatternRE"},priority:0,__type__:"TerminalDef"},3:{name:"STRING",pattern:{value:`(?:'[^\\']*'|"[^"]*")`,flags:[],_width:[2,4294967295],__type__:"PatternRE"},priority:0,__type__:"TerminalDef"},4:{name:"OPERATOR",pattern:{value:"(?:regex_matches|not_contains|contains|==|!=|<=|>=|<|>)",flags:[],_width:[1,13],__type__:"PatternRE"},priority:0,__type__:"TerminalDef"},5:{name:"CONJUNCTION",pattern:{value:"(?:and|or)",flags:[],_width:[2,3],__type__:"PatternRE"},priority:0,__type__:"TerminalDef"},6:{name:"NEGATION",pattern:{value:"!",flags:[],__type__:"PatternStr"},priority:0,__type__:"TerminalDef"},7:{name:"TRUE",pattern:{value:"true",flags:[],__type__:"PatternStr"},priority:0,__type__:"TerminalDef"},8:{name:"FALSE",pattern:{value:"false",flags:[],__type__:"PatternStr"},priority:0,__type__:"TerminalDef"},9:{name:"LPAR",pattern:{value:"(",flags:[],__type__:"PatternStr"},priority:0,__type__:"TerminalDef"},10:{name:"RPAR",pattern:{value:")",flags:[],__type__:"PatternStr"},priority:0,__type__:"TerminalDef"},11:{name:"__ANON_0",pattern:{value:"selected(",flags:[],__type__:"PatternStr"},priority:0,__type__:"TerminalDef"},12:{name:"__ANON_1",pattern:{value:"displayed(",flags:[],__type__:"PatternStr"},priority:0,__type__:"TerminalDef"},13:{name:"__ANON_2",pattern:{value:"text(",flags:[],__type__:"PatternStr"},priority:0,__type__:"TerminalDef"},14:{name:"__ANON_3",pattern:{value:"text_ignore_case(",flags:[],__type__:"PatternStr"},priority:0,__type__:"TerminalDef"},15:{name:"__ANON_4",pattern:{value:"count_selected(",flags:[],__type__:"PatternStr"},priority:0,__type__:"TerminalDef"},16:{name:"__ANON_5",pattern:{value:"count_choice_selections(",flags:[],__type__:"PatternStr"},priority:0,__type__:"TerminalDef"},17:{name:"LSQB",pattern:{value:"[",flags:[],__type__:"PatternStr"},priority:0,__type__:"TerminalDef"},18:{name:"__ANON_6",pattern:{value:"])",flags:[],__type__:"PatternStr"},priority:0,__type__:"TerminalDef"},19:{name:"RSQB",pattern:{value:"]",flags:[],__type__:"PatternStr"},priority:0,__type__:"TerminalDef"},20:{name:"DOT",pattern:{value:".",flags:[],__type__:"PatternStr"},priority:0,__type__:"TerminalDef"},21:{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"},22:{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"},23:{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"},24:{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"},25:{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"},26:{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"},27:{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"},28:{origin:{name:"condition",__type__:"NonTerminal"},expansion:[{name:"qc_mc_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"},29:{origin:{name:"condition",__type__:"NonTerminal"},expansion:[{name:"qc_mc_displayed",__type__:"NonTerminal"}],order:2,alias:null,options:{keep_all_tokens:!1,expand1:!1,priority:null,template_source:null,empty_indices:[],__type__:"RuleOptions"},__type__:"Rule"},30:{origin:{name:"condition",__type__:"NonTerminal"},expansion:[{name:"qc_mc_text",__type__:"NonTerminal"}],order:3,alias:null,options:{keep_all_tokens:!1,expand1:!1,priority:null,template_source:null,empty_indices:[],__type__:"RuleOptions"},__type__:"Rule"},31:{origin:{name:"condition",__type__:"NonTerminal"},expansion:[{name:"qc_mc_text_ignore_case",__type__:"NonTerminal"}],order:4,alias:null,options:{keep_all_tokens:!1,expand1:!1,priority:null,template_source:null,empty_indices:[],__type__:"RuleOptions"},__type__:"Rule"},32:{origin:{name:"condition",__type__:"NonTerminal"},expansion:[{name:"qc_mc_count",__type__:"NonTerminal"}],order:5,alias:null,options:{keep_all_tokens:!1,expand1:!1,priority:null,template_source:null,empty_indices:[],__type__:"RuleOptions"},__type__:"Rule"},33:{origin:{name:"condition",__type__:"NonTerminal"},expansion:[{name:"qc_matrix_selected",__type__:"NonTerminal"}],order:6,alias:null,options:{keep_all_tokens:!1,expand1:!1,priority:null,template_source:null,empty_indices:[],__type__:"RuleOptions"},__type__:"Rule"},34:{origin:{name:"condition",__type__:"NonTerminal"},expansion:[{name:"qc_matrix_displayed",__type__:"NonTerminal"}],order:7,alias:null,options:{keep_all_tokens:!1,expand1:!1,priority:null,template_source:null,empty_indices:[],__type__:"RuleOptions"},__type__:"Rule"},35:{origin:{name:"condition",__type__:"NonTerminal"},expansion:[{name:"qc_matrix_count",__type__:"NonTerminal"}],order:8,alias:null,options:{keep_all_tokens:!1,expand1:!1,priority:null,template_source:null,empty_indices:[],__type__:"RuleOptions"},__type__:"Rule"},36:{origin:{name:"qc_mc_selected",__type__:"NonTerminal"},expansion:[{name:"NEGATION",filter_out:!1,__type__:"Terminal"},{name:"__ANON_0",filter_out:!0,__type__:"Terminal"},{name:"mc_choice_selector",__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"},37:{origin:{name:"qc_mc_selected",__type__:"NonTerminal"},expansion:[{name:"__ANON_0",filter_out:!0,__type__:"Terminal"},{name:"mc_choice_selector",__type__:"NonTerminal"},{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"},38:{origin:{name:"qc_mc_displayed",__type__:"NonTerminal"},expansion:[{name:"NEGATION",filter_out:!1,__type__:"Terminal"},{name:"__ANON_1",filter_out:!0,__type__:"Terminal"},{name:"mc_choice_selector",__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"},39:{origin:{name:"qc_mc_displayed",__type__:"NonTerminal"},expansion:[{name:"__ANON_1",filter_out:!0,__type__:"Terminal"},{name:"mc_choice_selector",__type__:"NonTerminal"},{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"},40:{origin:{name:"qc_mc_text",__type__:"NonTerminal"},expansion:[{name:"__ANON_2",filter_out:!0,__type__:"Terminal"},{name:"mc_choice_selector",__type__:"NonTerminal"},{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"},41:{origin:{name:"qc_mc_text_ignore_case",__type__:"NonTerminal"},expansion:[{name:"__ANON_3",filter_out:!0,__type__:"Terminal"},{name:"mc_choice_selector",__type__:"NonTerminal"},{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"},42:{origin:{name:"qc_mc_count",__type__:"NonTerminal"},expansion:[{name:"__ANON_4",filter_out:!0,__type__:"Terminal"},{name:"question_selector",__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"},43:{origin:{name:"qc_matrix_selected",__type__:"NonTerminal"},expansion:[{name:"NEGATION",filter_out:!1,__type__:"Terminal"},{name:"__ANON_0",filter_out:!0,__type__:"Terminal"},{name:"matrix_choice_selector",__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"},44:{origin:{name:"qc_matrix_selected",__type__:"NonTerminal"},expansion:[{name:"__ANON_0",filter_out:!0,__type__:"Terminal"},{name:"matrix_choice_selector",__type__:"NonTerminal"},{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"},45:{origin:{name:"qc_matrix_displayed",__type__:"NonTerminal"},expansion:[{name:"NEGATION",filter_out:!1,__type__:"Terminal"},{name:"__ANON_1",filter_out:!0,__type__:"Terminal"},{name:"matrix_statement_selector",__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:"qc_matrix_displayed",__type__:"NonTerminal"},expansion:[{name:"__ANON_1",filter_out:!0,__type__:"Terminal"},{name:"matrix_statement_selector",__type__:"NonTerminal"},{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"},47:{origin:{name:"qc_matrix_count",__type__:"NonTerminal"},expansion:[{name:"__ANON_5",filter_out:!0,__type__:"Terminal"},{name:"question_selector",__type__:"NonTerminal"},{name:"LSQB",filter_out:!0,__type__:"Terminal"},{name:"INT",filter_out:!1,__type__:"Terminal"},{name:"__ANON_6",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"},48:{origin:{name:"qc_matrix_count",__type__:"NonTerminal"},expansion:[{name:"__ANON_5",filter_out:!0,__type__:"Terminal"},{name:"question_selector",__type__:"NonTerminal"},{name:"LSQB",filter_out:!0,__type__:"Terminal"},{name:"IDENTIFIER",filter_out:!1,__type__:"Terminal"},{name:"__ANON_6",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"},49:{origin:{name:"question_selector",__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"},50:{origin:{name:"mc_choice_selector",__type__:"NonTerminal"},expansion:[{name:"question_selector",__type__:"NonTerminal"},{name:"LSQB",filter_out:!0,__type__:"Terminal"},{name:"INT",filter_out:!1,__type__:"Terminal"},{name:"RSQB",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"},51:{origin:{name:"mc_choice_selector",__type__:"NonTerminal"},expansion:[{name:"question_selector",__type__:"NonTerminal"},{name:"LSQB",filter_out:!0,__type__:"Terminal"},{name:"IDENTIFIER",filter_out:!1,__type__:"Terminal"},{name:"RSQB",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"},52:{origin:{name:"matrix_statement_selector",__type__:"NonTerminal"},expansion:[{name:"question_selector",__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"},53:{origin:{name:"matrix_choice_selector",__type__:"NonTerminal"},expansion:[{name:"matrix_statement_selector",__type__:"NonTerminal"},{name:"LSQB",filter_out:!0,__type__:"Terminal"},{name:"INT",filter_out:!1,__type__:"Terminal"},{name:"RSQB",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"},54:{origin:{name:"matrix_choice_selector",__type__:"NonTerminal"},expansion:[{name:"matrix_statement_selector",__type__:"NonTerminal"},{name:"LSQB",filter_out:!0,__type__:"Terminal"},{name:"IDENTIFIER",filter_out:!1,__type__:"Terminal"},{name:"RSQB",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"},55:{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"},56:{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"}};const tt=require("assert");function nt(s){if(s.length===1)return s[0];const t=s[1].value;return t==="or"?s[0]||s[2]:t==="and"?s[0]&&s[2]:!1}function ge(s,t,n){switch(t){case"==":return s===n;case"!=":return s!==n;case"<=":return s<=n;case">=":return s>=n;case"<":return s<n;case">":return s>n;default:return!1}}function rt(s,t,n,r){const i=r?s.toLowerCase():s,a=r?n.toLowerCase():n;switch(t){case"contains":return i.includes(a);case"not_contains":return!i.includes(a);case"regex_matches":try{return new RegExp(n).test(i)}catch{return!1}default:return ge(i,t,a)}}function H(s,t){return s.length===1?t(s[0]):(tt(s[0].type==="NEGATION"),!t(s[1]))}function xe(s){if(!["INT","IDENTIFIER"].includes(s.type))throw new SyntaxError(`Invalid token type: ${s.type}; expected IDENTIFIER or INT`);return T(s)}function T(s){var t,n;switch(s.type){case"IDENTIFIER":return s.value;case"INT":return parseInt(s.value,10);case"STRING":{const r=s.value.match(/(?:'(?<single>[^\']*)')|(?:"(?<double>[^\"]*)")/),i=((t=r==null?void 0:r.groups)==null?void 0:t.double)||((n=r==null?void 0:r.groups)==null?void 0:n.single);return tt(i),i}case"OPERATOR":return s.value;case"TRUE":return!0;case"FALSE":return!1;default:throw new SyntaxError(`Invalid token type: ${s.type}`)}}function Sn(s,t){const n={start:r=>r[0],top_level_expr:nt,bool_expr:nt,condition:r=>r[0],qc_mc_selected:r=>H(r,t.isSelected),qc_mc_displayed:r=>H(r,t.isDisplayed),qc_mc_text:r=>rt(t.textEntry(r[0]),T(r[1]),T(r[2]),!1),qc_mc_text_ignore_case:r=>rt(t.textEntry(r[0]),T(r[1]),T(r[2]),!0),qc_mc_count:r=>ge(t.countSelected(r[0]),T(r[1]),T(r[2])),qc_matrix_selected:r=>H(r,t.isSelected),qc_matrix_displayed:r=>H(r,t.isDisplayed),qc_matrix_count:r=>ge(t.countChoiceSelections(r[0],xe(r[1])),T(r[2]),T(r[3])),question_selector:r=>r[0].value,mc_choice_selector:r=>({questionId:r[0],choice:xe(r[1])}),matrix_statement_selector:r=>({questionId:r[0],statementId:T(r[1])}),matrix_choice_selector:r=>({...r[0],choice:xe(r[1])}),bool_const:r=>r[0].value==="true"};return In.get_parser({transformer:n}).parse(s)}const zn=/\$\{m:([^\}]+)\}/g,Dn=100,st=(s,t)=>{if(typeof t=="string"){let n=t,r=0;for(;r<Dn;){const i=n.replace(zn,(a,o)=>{if(s[o]===void 0)throw new Error(`Undefined macro: ${o}`);return s[o]});if(i===n)return i;n=i,r+=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]=st(s,t[n])}),t},Ln=s=>{s.sections=st(s.macros||{},s.sections)};var jn=Object.defineProperty,Cn=(s,t,n)=>t in s?jn(s,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):s[t]=n,S=(s,t,n)=>(Cn(s,typeof t!="symbol"?t+"":t,n),n);const it=new ht.default({allowUnionTypes:!0});dt.default(it);const at=it.compile(ke);class F extends Error{}class ot extends Error{}class z extends Error{}class Qn extends Error{}class Fn{constructor(){S(this,"seenQuestions",new Set),S(this,"seenQuestionStatements",new Map),S(this,"seenQuestionChoices",new Map),S(this,"seenTextChoices",new Map),S(this,"validateReference",t=>{var n,r,i;if(!this.seenQuestions.has(t.questionId))throw new F(`Invalid question: ${t.questionId}`);if(t.statementId!==void 0&&!((n=this.seenQuestionStatements.get(t.questionId))!=null&&n.has(t.statementId)))throw new F(`Invalid statement: ${t.questionId}.${t.statementId}`);if(t.choice!==void 0&&!((r=this.seenQuestionChoices.get(t.questionId))!=null&&r.has(t.choice)))throw new F(`Invalid choice: ${t.questionId}[${t.choice}]`);if(t.choice!==void 0&&t.expectText===!0&&!((i=this.seenTextChoices.get(t.questionId))!=null&&i.has(t.choice)))throw new F(`Invalid text reference: ${t.questionId}[${t.choice}]`)}),S(this,"evaluator",{isSelected:t=>(this.validateReference(t),!1),isDisplayed:t=>(this.validateReference(t),!1),countSelected:t=>(this.validateReference({questionId:t}),0),countChoiceSelections:(t,n)=>(this.validateReference({questionId:t,choice:n}),0),textEntry:t=>(this.validateReference({...t,expectText:!0}),"")})}}const U=(s,t,n)=>{if(n)try{Sn(n,s.evaluator)}catch(r){throw r instanceof F||r instanceof z?r:new Error(`Syntax error parsing display logic at ${t}: ${n}`)}},_t=(s,t)=>{var n,r,i,a,o,_;U(t,s.id,s.display_logic),U(t,s.id,s.display_logic_in_page),(n=s.statements)==null||n.forEach(p=>{U(t,`${s.id}.${p.id}`,p.display_logic)}),(r=s.choices)==null||r.forEach(p=>{U(t,`${s.id}[${p.id||p.value}]`,p.display_logic)});const c=p=>{const[u,m]=p.split("/",2);return{questionId:u,expression:m}},l=p=>{const u=(p.expression.startsWith("for_matrix_choice")||p.expression.startsWith("unselected_for_matrix_choice")?t.seenQuestionStatements:t.seenQuestionChoices).get(p.questionId);if(u===void 0)throw new ot(`Invalid question referenced in locator expression: ${p.questionId}/${p.expression}`);return u};if(s.id!==void 0){if(t.seenQuestions.has(s.id))throw new z(`Duplicate question id: ${s.id}`);if(t.seenQuestions.add(s.id),s.statements||s.dynamic_statements){const u=new Set;if(t.seenQuestionStatements.set(s.id,u),(i=s.statements)==null||i.forEach(m=>{if(u.has(m.id))throw new z(`Duplicate statement id: ${s.id}.${m.id}`);u.add(m.id)}),s.dynamic_statements){const m=c(s.dynamic_statements);l(m).forEach(d=>{if(typeof d=="number")throw new ot(`Dynamic statement in question ${s.id} refers to choices with values`);if(u.has(d))throw new z(`Duplicate statement ${d} via dynamic statements in question ${s.id}`);u.add(d)})}}const p=(a=s.choices)!=null?a:[];if((o=s.choice_groups)==null||o.forEach(u=>p.push(...u.choices)),p||s.dynamic_choices){const u=new Set;t.seenQuestionChoices.set(s.id,u);const m=new Set;if(t.seenTextChoices.set(s.id,m),p.forEach(d=>{var x;const v=(x=d.id)!=null?x:d.value;if(u.has(v))throw new z(`Duplicate choice: ${s.id}[${v}]`);u.add(v),d.text&&d.text!=="no"&&m.add(v)}),s.dynamic_choices){const d=c(s.dynamic_choices);l(d).forEach(x=>{if(u.has(x))throw new z(`Duplicate choice ${x} via dynamic choices in ${s.id}`);u.add(x)}),(_=t.seenTextChoices.get(d.questionId))==null||_.forEach(x=>m.add(x))}if(new Set([...u].map(d=>typeof d)).size>=2)throw new Qn("All choices in a question must either all have id's or all have values")}}},Un=s=>{if(!at(s))throw new Error(`Invalid template: ${s.template.id}. Reason: ${JSON.stringify(at.errors,null,4)}`);Ln(s);const t=new Fn;s.sections.forEach(n=>{var r,i;U(t,n.id,n.display_logic),(r=n.questions)==null||r.forEach(a=>{_t(a,t)}),(i=n.pages)==null||i.forEach(a=>{var o;(o=a.questions)==null||o.forEach(_=>{_t(_,t)})})})},Zn=ke,Mn="pulse_default_alpha",Bn={allPermissions:ft,SURVEY_RESOURCE_TYPE:mt,surveyAdministerPermission:Ne};exports.DEFAULT_TEMPLATE_ID=Mn,exports.permissions=Bn,exports.templateSchema=Zn,exports.validateTemplate=Un;
|
|
14
|
+
%s`,t,r);super(i),this.rule=t,this.obj=n,this.orig_exc=r}}function It(s,t=null,n=null){let r,i;const a=new Map;for(const o of s)r=t!==null?t(o):o,i=n!==null?n(o):o,a.has(r)?a.get(r).push(i):a.set(r,[i]);return a}function Z(s,t,n){let r;return me(s)?"__type__"in s?(r=t[s.__type__],r.deserialize(s,n)):"@"in s?n[s["@"]]:Object.fromEntries(g(s).map(([i,a])=>[i,Z(a,t,n)])):En(s)?s.map(i=>Z(i,t,n)):s}class x{static deserialize(t,n){const r=this,i=r&&r.__serialize_fields__;if("@"in t)return n[t["@"]];const a=de(r);for(const o of i)if(t&&o in t)a[o]=Z(t[o],$n,n);else throw new KeyError("Cannot find key for class",r,e);return"_deserialize"in a&&a._deserialize(),a}}class $t extends x{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,r){return Z(t,n,r)}}class Oe{constructor(){this.empty=!0}}class y{constructor(t,n,r=null){this.data=t,this.children=n,this._meta=r}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,n){if(this.children.length===1&&!(this.children[0]instanceof y))return[E(n,t).join(""),this._pretty_label()," ",u("%s",this.children[0].value),`
|
|
15
|
+
`];const r=[E(n,t).join(""),this._pretty_label(),`
|
|
16
|
+
`];for(const i of this.children)i instanceof y?r.push(...i._pretty(t+1,n)):r.push(E(n,t+1).join(""),u("%s",i.value),`
|
|
17
|
+
`);return r}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];const n=new Map;for(const r of t)n.set(r,r),t.push(...[...r.children].reverse().filter(i=>i instanceof y&&!n.has(i)).map(i=>i));return t=void 0,[...n.values()].reverse()}find_pred(t){return et(t,this.iter_subtrees())}find_data(t){return this.find_pred(n=>n.data===t)}*scan_values(t){for(const n of this.children)if(n instanceof y)for(const r of n.scan_values(t))yield r;else t(n)&&(yield n)}*iter_subtrees_topdown(){let t;const n=[this];for(;n.length;)if(t=n.pop(),t instanceof y){yield t;for(const r of[...t.children].reverse())n.push(r)}}copy(){return type(this)(this.data,this.children)}set(t,n){this.data=t,this.children=n}}class L extends qe{static get __visit_tokens__(){return!0}constructor(t=!0){super(),this.__visit_tokens__=t}static fromObj(t,...n){class r extends this{}for(const[i,a]of Object.entries(t))r.prototype[i]=a;return new r(...n)}_call_userfunc(t,n=null){let r,i;const a=n!==null?n:t.children;if(t&&t.data&&this&&this[t.data]){r=this&&this[t.data];try{return i=r&&r.visit_wrapper||null,i!==null?r.visit_wrapper(r,t.data,a,t.meta):r(a)}catch(o){throw o instanceof M?o:o instanceof Error?new re(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(r){throw r instanceof M?r:r instanceof Error?new re(t.type,t,r):r}}else return this.__default_token__(t)}*_transform_children(t){let n;for(const r of t)r instanceof y?n=this._transform_tree(r):this.__visit_tokens__&&r instanceof f?n=this._call_userfunc_token(r):n=r,n!==V&&(yield n)}_transform_tree(t){const n=[...this._transform_children(t.children)];return this._call_userfunc(t,n)}transform(t){return this._transform_tree(t)}__default__(t,n,r){return new y(t,n,r)}__default_token__(t){return t}}class Ae extends L{_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 Pt extends L{transform(t){let n,r,i;const a=[],o=[t];for(;o.length;){const l=o.pop();a.push(l),l instanceof y&&o.push(...l.children)}const _=[];for(const l of[...a].reverse())l instanceof y?(i=l.children.length,i?(n=_.slice(-i),_.splice(-i)):n=[],r=this._call_userfunc(l,n),r!==V&&_.push(r)):this.__visit_tokens__&&l instanceof f?(r=this._call_userfunc_token(l),r!==V&&_.push(r)):_.push(l);const[c]=_;return c}}class St extends L{_transform_tree(t){return t.children=[...this._transform_children(t.children)],this._call_userfunc(t)}}class se{_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 zt extends se{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 Dt extends se{visit(t){for(const n of t.children)n instanceof y&&this.visit(n);return this._call_userfunc(t),t}visit_topdown(t){this._call_userfunc(t);for(const n of t.children)n instanceof y&&this.visit_topdown(n);return t}}class Lt extends qe{visit(t){return t.data in this?this[t.data](t):this.__default__(t)}visit_children(t){return t.children.map(n=>n instanceof y?this.visit(n):n)}__default__(t){return this.visit_children(t)}}const jt=0;class ie extends x{constructor(t){super(),v(this,"is_term",j),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 ae extends ie{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 u("%s(%r, %r)",type(this).name,this.name,this.filter_out)}renamed(t){return type(this)(t(this.name),this.filter_out)}}class oe extends ie{static get __serialize_fields__(){return["name"]}get is_term(){return!1}}class B extends x{static get __serialize_fields__(){return["keep_all_tokens","expand1","priority","template_source","empty_indices"]}constructor(t=!1,n=!1,r=null,i=null,a=[]){super(),this.keep_all_tokens=t,this.expand1=n,this.priority=r,this.template_source=i,this.empty_indices=a}repr(){return u("RuleOptions(%r, %r, %r, %r)",this.keep_all_tokens,this.expand1,this.priority,this.template_source)}}class z extends x{static get __serialize_fields__(){return["origin","expansion","order","alias","options"]}static get __serialize_namespace__(){return[ae,oe,B]}constructor(t,n,r=0,i=null,a=null){super(),this.origin=t,this.expansion=n,this.alias=i,this.order=r,this.options=a||new B,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 z?this.origin===t.origin&&this.expansion===t.expansion:!1}}class _e extends x{constructor(t,n=[],r=null){super(),this.value=t,this.flags=Y(n),this.raw=r}repr(){return repr(this.to_regexp())}eq(t){return type(this)===type(t)&&this.value===t.value&&this.flags===t.flags}to_regexp(){throw new NotImplementedError}get min_width(){throw new NotImplementedError}get max_width(){throw new NotImplementedError}_get_flags(t){return t}}class le extends _e{static get __serialize_fields__(){return["value","flags"]}static get type(){return"str"}to_regexp(){return this._get_flags(Ge.escape(this.value))}get min_width(){return this.value.length}get max_width(){return this.value.length}}class ce extends _e{static get __serialize_fields__(){return["value","flags","_width"]}static get type(){return"re"}to_regexp(){return this._get_flags(this.value)}_get_width(){return this._width===null&&(this._width=get_regexp_width(this.to_regexp())),this._width}get min_width(){return this._get_width()[0]}get max_width(){return this._get_width()[1]}}class G extends x{static get __serialize_fields__(){return["name","pattern","priority"]}static get __serialize_namespace__(){return[le,ce]}constructor(t,n,r=jt){super(),this.name=t,this.pattern=n,this.priority=r}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 f{constructor(t,n,r=null,i=null,a=null,o=null,_=null,c=null){v(this,"value"),v(this,"type"),this.type=t,this.start_pos=r,this.value=n,this.line=i,this.column=a,this.end_line=o,this.end_column=_,this.end_pos=c}update(t=null,n=null){return f.new_borrow_pos(t!==null?t:this.type,n!==null?n:this.value,this)}static new_borrow_pos(t,n,r){const i=this;return new i(t,n,r.start_pos,r.line,r.column,r.end_line,r.end_column,r.end_pos)}repr(){return u("Token(%r, %r)",this.type,this.value)}eq(t){return t instanceof f&&this.type!==t.type?!1:str.__eq__(this,t)}static get __hash__(){return str.__hash__}}class be{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 be?this.char_pos===t.char_pos&&this.newline_char===t.newline_char:j}feed(t,n=!0){let r;n&&(r=ye(t,this.newline_char),r&&(this.line+=r,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 Ct{constructor(t){this.scanner=t}__call__(t){let n;const r=this.scanner.match(t.value,0);return r&&([n,t.type]=r),t}}const Ft=A(Ct);class Qt{constructor(t,n,r){this.callback1=t,this.callback2=n,this.cond=r}__call__(t){const n=this.callback1(t);return this.cond(n)?this.callback2(t):n}}const Ut=A(Qt);function Mt(s,t,n,r){let i,a;const o=It(s,l=>l.pattern.constructor.type),_=new Set,c={};for(const l of o.get("re")||[]){a=[];for(const p of o.get("str")||[])p.priority===l.priority&&(i=p.pattern.value,i===vn(n,l.pattern.to_regexp(),i,t)&&(a.push(p),An(new Set(p.pattern.flags),new Set(l.pattern.flags))&&_.add(p)));a.length&&(c[l.name]=new Ft(new We(a,t,n,r,!0)))}return[s.filter(l=>!_.has(l)).map(l=>l),c]}function Zt(s){return s.includes(`
|
|
18
|
+
`)||s.includes("\\n")||s.includes("\\s")||s.includes("[^")||s.includes("(?s")&&s.includes(".")}class Te{constructor(t,n=null,r=null){this.text=t,this.line_ctr=n||new be(`
|
|
19
|
+
`),this.last_token=r}eq(t){return t instanceof Te?this.text===t.text&&this.line_ctr===t.line_ctr&&this.last_token===t.last_token:j}}class Ie{constructor(t,n){this.lexer=t,this.state=n}static from_text(t,n){return new this(t,new Te(n))}lex(t){return this.lexer.lex(this.state,t)}}class W extends Ee{lex(t,n){return j}}function Bt(s,t){s.sort((n,r)=>{const i=t(n),a=t(r);for(let o=0;o<i.length;o++){if(i[o]>a[o])return 1;if(i[o]<a[o])return-1}return 0})}class J extends W{constructor(t){super();const n=[...t.terminals];if(this.re=t.re_module,!t.skip_validation){for(const r of n){try{this.re.compile(r.pattern.to_regexp(),t.g_regex_flags)}catch(i){throw i instanceof this.re.error?new D(u("Cannot compile token %s: %s",r.name,r.pattern)):i}if(r.pattern.min_width===0)throw new D(u("Lexer does not allow zero-width terminals. (%s: %s)",r.name,r.pattern))}if(!(new Set(t.ignore)<=new Set(n.map(r=>r.name))))throw new D(u("Ignore terminals are not defined: %s",Ke(new Set(t.ignore),new Set(n.map(r=>r.name)))))}this.newline_types=Y(n.filter(r=>Zt(r.pattern.to_regexp())).map(r=>r.name)),this.ignore_types=Y(t.ignore),Bt(n,r=>[-r.priority,-r.pattern.max_width,-r.pattern.value.length,r.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]=Mt(this.terminals,this.g_regex_flags,this.re,this.use_bytes);for(const[n,r]of g(this.user_callbacks))n in this.callback?this.callback[n]=new Ut(this.callback[n],r,i=>i.type===n):this.callback[n]=r;this._scanner=new We(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(r){if(!(r instanceof te))throw r}}next_token(t,n=null){let r,i,a,o;const _=t.line_ctr;for(;_.char_pos<t.text.length;){if(i=this.match(t.text,_.char_pos),!i)throw r=Ke(this.scanner.allowed_types,this.ignore_types),r||(r=new Set(["<END-OF-FILE>"])),new $({seq:t.text,lex_pos:_.char_pos,line:_.line,column:_.column,allowed:r,token_history:t.last_token&&[t.last_token],state:n,terminals_by_name:this.terminals_by_name});const[c,l]=i;if(!this.ignore_types.has(l)){if(a=new f(l,c,_.char_pos,_.line,_.column),_.feed(c,this.newline_types.has(l)),a.end_line=_.line,a.end_column=_.column,a.end_pos=_.char_pos,a.type in this.callback&&(a=this.callback[a.type](a),!(a instanceof f)))throw new D(u("Callbacks must return a token (returned %r)",a));return t.last_token=a,a}l in this.callback&&(o=new f(l,c,_.char_pos,_.line,_.column),this.callback[l](o)),_.feed(c,this.newline_types.has(l))}throw new te(this)}}class Gt extends W{constructor({conf:t,states:n,always_accept:r=[]}={}){super();let i,a,o;const _=[...t.terminals],c=t.terminals_by_name,l=N(t);l.terminals=_;const p=new Map;this.lexers={};for(let[h,d]of g(n))i=Y(d),p.has(i)?a=p.get(i):(d=Rn(new Set(d),[...new Set(t.ignore),...new Set(r)]),o=N(l),o.terminals=[...d].filter(m=>m in c).map(m=>c[m]),a=new J(o),p.set(i,a)),this.lexers[h]=a;this.root_lexer=new J(l)}*lex(t,n){let r,i,a;try{for(;;)i=this.lexers[n.position],yield i.next_token(t,n)}catch(o){if(!(o instanceof te))if(o instanceof $)try{throw r=t.last_token,a=this.root_lexer.next_token(t,n),new P({token:a,expected:o.allowed,state:n,token_history:[r],terminals_by_name:this.root_lexer.terminals_by_name})}catch(_){throw _}else throw o}}}class $e extends x{static get __serialize_fields__(){return["terminals","ignore","g_regex_flags","use_bytes","lexer_type"]}static get __serialize_namespace__(){return[G]}constructor({terminals:t,re_module:n,ignore:r=[],postlex:i=null,callbacks:a=null,g_regex_flags:o="",skip_validation:_=!1,use_bytes:c=!1}={}){super(),this.terminals=t,this.terminals_by_name=Object.fromEntries(this.terminals.map(l=>[l.name,l])),this.ignore=r,this.postlex=i,this.callbacks=Object.keys(a).length||{},this.g_regex_flags=o,this.re_module=n,this.skip_validation=_,this.use_bytes=c,this.lexer_type=null}_deserialize(){this.terminals_by_name=Object.fromEntries(this.terminals.map(t=>[t.name,t]))}}class Pe extends x{static get __serialize_fields__(){return["rules","start","parser_type"]}constructor(t,n,r){super(),this.rules=t,this.callbacks=n,this.start=r,this.parser_type=null}}class Wt{constructor(t){this.node_builder=t}__call__(t){return t.length===1?t[0]:this.node_builder(t)}}const Jt=A(Wt);class Vt{constructor(t,n=null){this.node_builder=t,this.node_filter=n}__call__(t){let n,r,i;const a=this.node_builder(t);return a instanceof y&&(i=a.meta,n=this._pp_get_meta(t),n!==null&&("line"in i||(i.line=n&&n.container_line||n.line,i.column=n&&n.container_column||n.column,i.start_pos=n&&n.container_start_pos||n.start_pos,i.empty=!1),i.container_line=n&&n.container_line||n.line,i.container_column=n&&n.container_column||n.column),r=this._pp_get_meta([...t].reverse()),r!==null&&("end_line"in i||(i.end_line=r&&r.container_end_line||r.end_line,i.end_column=r&&r.container_end_column||r.end_column,i.end_pos=r&&r.container_end_pos||r.end_pos,i.empty=!1),i.container_end_line=r&&r.container_end_line||r.end_line,i.container_end_column=r&&r.container_end_column||r.end_column)),a}_pp_get_meta(t){for(const n of t)if(!(this.node_filter!==null&&!this.node_filter(n))){if(n instanceof y){if(!n.meta.empty)return n.meta}else if(n instanceof f)return n}}}const Se=A(Vt);function Yt(s){if(qn(s))return K({unknown_param_0:Se,node_filter:s});if(s===!0)return Se;if(s===!1)return null;throw new R(u("Invalid option for propagate_positions: %r",s))}class pe{constructor(t,n,r){this.node_builder=r,this.to_include=t,this.append_none=n}__call__(t){const n=[];for(const[r,i,a]of this.to_include)a&&n.push(...E([null],a)),i?n.push(...t[r].children):n.push(t[r]);return this.append_none&&n.push(...E([null],this.append_none)),this.node_builder(n)}}const Kt=A(pe);class Ht extends pe{__call__(t){let n=[];for(const[r,i,a]of this.to_include)a&&n.push(...E([null],a)),i?n.length?n.push(...t[r].children):n=t[r].children:n.push(t[r]);return this.append_none&&n.push(...E([null],this.append_none)),this.node_builder(n)}}const Xt=A(Ht);class en extends pe{constructor(t,n){super(),this.node_builder=n,this.to_include=t}__call__(t){let n=[];for(const[r,i]of this.to_include)i?n.length?n.push(...t[r].children):n=t[r].children:n.push(t[r]);return this.node_builder(n)}}const tn=A(en);function nn(s){return!s.is_term&&s.name.startsWith("_")}function rn(s,t,n,r){let i,a;r.length?(a=r.map(c=>(0+c).toString()).join(""),i=a.split("0").map(c=>c.length)):i=E([0],s.length+1);const o=[];let _=0;for(const[c,l]of C(s))_+=i[c],(t||!(l.is_term&&l.filter_out))&&(o.push([c,nn(l),_]),_=0);if(_+=i[s.length],r.length||o.length<s.length||On(o.map(([c,l,p])=>l)))return(r.length||n).length?K(n?Kt:Xt,o,_):K(tn,o.map(([c,l,p])=>[c,l]))}function sn(s){function t(n){const r=new y(s.name,n);return s(r)}return t=wraps(s)(t),t}function an(s,t,n){if(n===_vargs_meta||n===_vargs_meta_inline)throw new NotImplementedError("Meta args not supported for internal transformer");function r(i){return n(s,t,i,null)}return r=wraps(s)(r),r}class on{constructor(t,n,r=!1,i=!1,a=!1){this.tree_class=n,this.propagate_positions=r,this.ambiguous=i,this.maybe_placeholders=a,this.rule_builders=[...this._init_builders(t)]}*_init_builders(t){let n,r,i,a;const o=Yt(this.propagate_positions);for(const _ of t)i=_.options,r=i.keep_all_tokens,n=i.expand1,a=[...et(null,[n&&!_.alias&&Jt,rn(_.expansion,r,this.ambiguous,this.maybe_placeholders?i.empty_indices:[]),o])],yield[_,a]}create_callback(t=null){let n,r,i;const a=new Map;for(const[o,_]of this.rule_builders){r=o.alias||o.options.template_source||o.origin.name,t&&t[r]?(n=t&&t[r],i=n&&n.visit_wrapper||null,i!==null?n=an(n,r,i):t instanceof Ae&&(n=sn(n))):n=K(this.tree_class,r);for(const c of _)n=c(n);if(a.has(o))throw new M(u("Rule '%s' already exists",o));a.set(o,n)}return a}}class ze extends x{constructor({parser_conf:t,debug:n=!1}={}){super();const r=new LALR_Analyzer({unknown_param_0:t,debug:n});r.compute_lalr();const i=t.callbacks;this._parse_table=r.parse_table,this.parser_conf=t,this.parser=new De(r.parse_table,i,n)}static deserialize(t,n,r,i=!1){const a=de(this);return a._parse_table=cn.deserialize(t,n),a.parser=new De(a._parse_table,r,i),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:r=null}={}){let i,a;try{return this.parser.parse({lexer:t,start:n})}catch(o){if(o instanceof q){if(r===null)throw o;for(;;){if(o instanceof $&&(a=o.interactive_parser.lexer_thread.state,i=a.line_ctr.char_pos),!r(o))throw o;o instanceof $&&i===a.line_ctr.char_pos&&a.line_ctr.feed(a.text.slice(i,i+1));try{return o.interactive_parser.resume_parse()}catch(_){if(_ instanceof P){if(o instanceof P&&o.token.type===_.token.type&&_.token.type==="$END"&&o.interactive_parser.eq(_.interactive_parser))throw _;o=_}else if(_ instanceof $)o=_;else throw _}}}else throw o}}}class _n{constructor(t,n,r){this.parse_table=t,this.start_state=this.parse_table.start_states[r],this.end_state=this.parse_table.end_states[r],this.states=this.parse_table.states,this.callbacks=n,this.start=r}}class ve{constructor(t,n,r=null,i=null){this.parse_conf=t,this.lexer=n,this.state_stack=r||[this.parse_conf.start_state],this.value_stack=i||[]}get position(){return w(this.state_stack)}eq(t){return t instanceof ve?this.state_stack.length===t.state_stack.length&&this.position===t.position:j}copy(){return N(this)}feed_token(t,n=!1){let r,i,a,o,_,c,l,p,h,d;const m=this.state_stack,b=this.value_stack,U=this.parse_conf.states,pt=this.parse_conf.end_state,X=this.parse_conf.callbacks;for(;;){if(h=w(m),t.type in U[h])[i,a]=U[h][t.type];else throw o=new Set(he(U[h]).filter(ee=>tt(ee)).map(ee=>ee)),new P({token:t,expected:o,state:this,interactive_parser:null});if(i===ue){m.push(a),b.push(t.type in X?X[t.type](t):t);return}if(c=a,p=c.expansion.length,p?(l=b.slice(-p),m.splice(-p),b.splice(-p)):l=[],d=X.get(c)(l),[r,_]=U[w(m)][c.origin.name],m.push(_),b.push(d),n&&w(m)===pt)return w(b)}}}class De{constructor(t,n,r=!1){this.parse_table=t,this.callbacks=n,this.debug=r}parse({lexer:t,start:n,value_stack:r=null,state_stack:i=null,start_interactive:a=!1}={}){const o=new _n(this.parse_table,this.callbacks,n),_=new ve(o,t,i,r);return a?new O(this,_,_.lexer):this.parse_from_state(_)}parse_from_state(t){let n,r;try{r=null;for(r of t.lexer.lex(t))t.feed_token(r);return n=r?f.new_borrow_pos("$END","",r):new f("$END","",0,1,1),t.feed_token(n,!0)}catch(i){if(i instanceof q){try{i.interactive_parser=new O(this,t,t.lexer)}catch(a){if(!(a instanceof ReferenceError))throw a}throw i}else if(i instanceof Error){if(this.debug){console.log(""),console.log("STATE STACK DUMP"),console.log("----------------");for(const[a,o]of C(t.state_stack))console.log(u("%d)",a),o);console.log("")}throw i}else throw i}}}class O{constructor(t,n,r){this.parser=t,this.parser_state=n,this.lexer_thread=r,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){const n=t!==null?f.new_borrow_pos("$END","",t):new f("$END","",0,1,1);return this.feed_token(n)}copy(){return N(this)}eq(t){return t instanceof O?this.parser_state===t.parser_state&&this.lexer_thread===t.lexer_thread:!1}as_immutable(){const t=N(this);return new Le(t.parser,t.parser_state,t.lexer_thread)}pretty(){const t=["Parser choices:"];for(const[n,r]of g(this.choices()))t.push(u(" - %s -> %r",n,r));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;const n=new Set;for(const r of this.choices())if(tt(r)){t=N(this);let i=null;try{t.feed_token(new f(r,""))}catch(a){if(i=a,!(a instanceof P))throw a}i||n.add(r)}return n}resume_parse(){return this.parser.parse_from_state(this.parser_state)}}class Le extends O{constructor(){super(...arguments),v(this,"result",null)}feed_token(t){const n=N(this);return n.result=O.feed_token(n,t),n}exhaust_lexer(){const t=this.as_mutable();return t.exhaust_lexer(),t.as_immutable()}as_mutable(){const t=N(this);return new O(t.parser,t.parser_state,t.lexer_thread)}}class je{constructor(t){this.name=t}repr(){return this.toString()}}var ue=new je("Shift");const Ce=new je("Reduce");class ln{constructor(t,n,r){this.states=t,this.start_states=n,this.end_states=r}serialize(t){const n=new Enumerator,r=Object.fromEntries(g(this.states).map(([i,a])=>[i,Object.fromEntries(g(a).map(([o,[_,c]])=>[Ve(n,o),_===Ce?[1,c.serialize(t)]:[0,c]]))]));return{tokens:n.reversed(),states:r,start_states:this.start_states,end_states:this.end_states}}static deserialize(t,n){const r=this,i=t.tokens,a=Object.fromEntries(g(t.states).map(([o,_])=>[o,Object.fromEntries(g(_).map(([c,[l,p]])=>[i[c],l===1?[Ce,z.deserialize(p,n)]:[ue,p]]))]));return new r(a,t.start_states,t.end_states)}}class cn extends ln{static from_ParseTable(t){const n=this,r=[...t.states],i=Object.fromEntries(C(r).map(([c,l])=>[l,c])),a={};for(let[c,l]of g(t.states))l=Object.fromEntries(g(l).map(([p,h])=>[p,h[0]===ue?[h[0],i[h[1]]]:h])),a[i[c]]=l;const o=Object.fromEntries(g(t.start_states).map(([c,l])=>[c,i[l]])),_=Object.fromEntries(g(t.end_states).map(([c,l])=>[c,i[l]]));return new n(a,o,_)}}function pn(s){if(s&&s.__future_interface__)return s;class t extends W{constructor(r){super(),this.lexer=s(r)}lex(r,i){return this.lexer.lex(r.text)}}return t}function un(s,t,n,r,i){const a=Pe.deserialize(s.parser_conf,t),o=ze.deserialize(s.parser,t,r,i.debug);return a.callbacks=r,new hn({lexer_conf:n,parser_conf:a,options:i,parser:o})}const Fe={};class hn extends x{static get __serialize_fields__(){return["lexer_conf","parser_conf","parser"]}constructor({lexer_conf:t,parser_conf:n,options:r,parser:i=null}={}){super();let a,o;this.parser_conf=n,this.lexer_conf=t,this.options=r,i?this.parser=i:(o=Ve(Fe,n.parser_type),this.parser=o(t,n,r));const _=t.lexer_type;if(this.skip_lexer=!1,["dynamic","dynamic_complete"].includes(_)){this.skip_lexer=!0;return}const c={basic:yn,contextual:gn};_ in c?(a=c[_],this.lexer=a(t,this.parser,t.postlex,r)):this.lexer=pn(_)(t),t.postlex&&(this.lexer=new fn(this.lexer,t.postlex))}_verify_start(t=null){let n;if(t===null){if(n=this.parser_conf.start,n.length>1)throw new R("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 R(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:Ie.from_text(this.lexer,t)}parse(t,n=null,r=null){const i=this._verify_start(n),a=r===null?{}:{on_error:r},o=this._make_lexer_thread(t);return this.parser.parse({lexer:o,start:i,...a})}parse_interactive(t=null,n=null){const r=this._verify_start(n);if(this.parser_conf.parser_type!=="lalr")throw new R("parse_interactive() currently only works with parser='lalr' ");const i=this._make_lexer_thread(t);return this.parser.parse_interactive(i,r)}}function dn(s,t){let n;ne(s,["lalr","earley","cyk"]),typeof t!="object"&&(n={lalr:["basic","contextual"],earley:["basic","dynamic","dynamic_complete"],cyk:["basic"]}[s],ne(t,n,u("Parser %r does not support lexer %%r, expected one of %%s",s)))}function mn(s,t){let n;const r={};for(const i of t)n=s&&s[i.name]||null,n!==null&&(r[i.name]=n);return r}class fn{constructor(t,n){this.lexer=t,this.postlexer=n}lex(t,n){const r=this.lexer.lex(t,n);return this.postlexer.process(r)}}function yn(s,t,n,r){return new J(s)}function gn(s,t,n,r){const i=Object.fromEntries(g(t._parse_table.states).map(([o,_])=>[o,[...he(_)]])),a=n?n.always_accept:[];return new Gt({conf:s,states:i,always_accept:a})}function xn(s,t,n=null){const r=n?n.debug:!1;return new ze({parser_conf:t,debug:r})}Fe.lalr=xn;class Qe extends Ee{constructor(){super(...arguments),v(this,"always_accept",[])}process(t){return t}}class wn extends x{constructor(t){super(),v(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 '),v(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;const r=He(t),i=this;for(const[a,o]of g(this._defaults))a in r?(n=Nn(r,a),typeof o=="boolean"&&!["cache","use_bytes","propagate_positions"].includes(a)&&(n=Xe(n))):n=o,i[a]=n;if(typeof i.start=="string"&&(i.start=[i.start]),this.options=i,ne(this.parser,["earley","lalr","cyk",null]),this.parser==="earley"&&this.transformer)throw new R("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(r).length)throw new R(u("Unknown options: %s",he(r)))}serialize(t){return this.options}static deserialize(t,n){const r=this;return new r(t)}}class Ue extends x{static get __serialize_fields__(){return["parser","rules","options"]}_build_lexer(t=!1){let n=this.lexer_conf;return t&&(n=N(n),n.ignore=[]),new J(n)}_prepare_callbacks(){this._callbacks=new Map,this.options.ambiguity!=="forest"&&(this._parse_tree_builder=new on(this.rules,this.options.tree_class||kn(y),this.options.propagate_positions,this.options.parser!=="lalr"&&this.options.ambiguity==="explicit",this.options.maybe_placeholders),this._callbacks=this._parse_tree_builder.create_callback(this.options.transformer)),Ye(this._callbacks,mn(this.options.transformer,this.terminals))}_deserialize_lexer_conf(t,n,r){const i=$e.deserialize(t.lexer_conf,n);return i.callbacks=r.lexer_callbacks||{},i.re_module=r.regex?regex:Ge,i.use_bytes=r.use_bytes,i.g_regex_flags=r.g_regex_flags||"",i.skip_validation=!0,i.postlex=r.postlex,i}_load({f:t,...n}={}){let r;me(t)?r=t:r=pickle.load(t);const i=r.memo,a=r.data,o=$t.deserialize(i,{Rule:z,TerminalDef:G},{}),_=He(a.options);return Ye(_,n),this.options=wn.deserialize(_,o),this.rules=a.rules.map(c=>z.deserialize(c,o)),this.source_path="<deserialized>",dn(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(c=>[c.name,c])),this.parser=un(a.parser,o,this.lexer_conf,this._callbacks,this.options),this}static _load_from_dict({data:t,memo:n,...r}={}){return de(this)._load({f:{data:t,memo:n},...r})}repr(){return u("Lark(open(%r), parser=%r, lexer=%r, ...)",this.source_path,this.options.parser,this.options.lexer)}lex(t,n=!1){let r;!("lexer"in this)||n?r=this._build_lexer(n):r=this.lexer;const i=Ie.from_text(r,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,n=null){return this.parser.parse_interactive({unknown_param_0:t,start:n})}parse(t,n=null,r=null){return this.parser.parse(t,n,r)}}class Me extends k{}class Ze extends Qe{constructor(){super(),this.paren_level=0,this.indent_level=[0]}*handle_NL(t){if(this.paren_level>0)return;yield t;const n=fe(t.value,`
|
|
21
|
+
`,1)[1],r=ye(n," ")+ye(n," ")*this.tab_len;if(r>w(this.indent_level))this.indent_level.push(r),yield f.new_borrow_pos(this.INDENT_type,n,t);else{for(;r<w(this.indent_level);)this.indent_level.pop(),yield f.new_borrow_pos(this.DEDENT_type,n,t);if(r!==w(this.indent_level))throw new Me(u("Unexpected dedent to column %s. Expected dedent to %s",r,w(this.indent_level)))}}*_process(t){for(const n of t)n.type===this.NL_type?yield*this.handle_NL(n):yield n,this.OPEN_PAREN_types.includes(n.type)?this.paren_level+=1:this.CLOSE_PAREN_types.includes(n.type)&&(this.paren_level-=1);for(;this.indent_level.length>1;)this.indent_level.pop(),yield new f(this.DEDENT_type,"")}process(t){return this.paren_level=0,this.indent_level=[0],this._process(t)}get always_accept(){return[this.NL_type]}get NL_type(){throw new NotImplementedError}get OPEN_PAREN_types(){throw new NotImplementedError}get CLOSE_PAREN_types(){throw new NotImplementedError}get INDENT_type(){throw new NotImplementedError}get DEDENT_type(){throw new NotImplementedError}get tab_len(){throw new NotImplementedError}}class bn extends Ze{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}}function Tn(s={}){return s.transformer&&s.transformer.constructor.name==="object"&&(s.transformer=L.fromObj(s.transformer)),Ue._load_from_dict({data:Sn,memo:zn,...s})}const Be={},V={},Ge={escape(s){return s.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")},compile(s,t){return new RegExp(s,t)},error:SyntaxError};function vn(s,t,n,r){const i=s.compile(t,r).exec(n);if(i!=null)return i[0]}class We{constructor(t,n,r,i,a=!1){this.terminals=t,this.g_regex_flags=n,this.re_=r,this.use_bytes=i,this.match_whole=a,this.allowed_types=new Set(this.terminals.map(o=>o.name)),this._regexps=this._build_mres(t)}_build_mres(t){const n=this.match_whole?"$":"",r=In(t,a=>a.pattern.flags.join("")),i=[];for(const[a,o]of r){const _=o.map(c=>`(?<${c.name}>${c.pattern.to_regexp()+n})`).join("|");i.push(new RegExp(_,`${this.g_regex_flags+a}y`))}return i}match(t,n){for(const r of this._regexps){r.lastIndex=n;const i=r.exec(t);if(i){let a=null;for(const[o,_]of Object.entries(i.groups))if(_){a=o;break}return[i[0],a]}}}}const Je=typeof require!="undefined"&&require("util"),j={};function g(s){return Object.entries(s)}function he(s){return Object.keys(s)}function Nn(s,t){t===void 0&&(t=Object.keys(s)[0]);const n=s[t];return delete s[t],n}function Ve(s,t,n=null){return s[t]||n}function Ye(s,t){if(s.constructor.name==="Map")for(const[n,r]of g(t))s.set(n,r);else for(const[n,r]of g(t))s[n]=r}function kn(s){return function(){return new s(...arguments)}}function u(s){let t=0;const n=[...arguments].slice(1);return s.replace(/%([sr])/g,function(){const r=arguments[1],i=n[t++];return r==="r"?Je?Je.inspect(i,!1,null,!0):JSON.stringify(i,null,0):i})}function Rn(s,t){const n=new Set(s);for(const r of t)n.add(r);return n}function Ke(s,t){return[...s].filter(n=>!t.has(n))}function He(s){return{...s}}function Xe(s){return!!s}function de(s){return Object.create(s.prototype)}function N(s){if(typeof s=="object"){const t=Object.create(Object.getPrototypeOf(s));return Object.assign(t,s)}return s}function Y(s){return new Set(s)}function me(s){return s&&s.constructor.name==="Object"}function En(s){return s&&s.constructor.name==="Array"}function qn(s){return typeof s=="function"}function*C(s,t=0){let n=t;for(const r of s)yield[n++,r]}function On(s){for(const t of s)if(t)return!0;return!1}function et(s,t){return t.filter(s||Xe)}function K(s){const t=[...arguments].slice(1);return function(){return s(...t,...arguments)}}function w(s){return s[s.length-1]}function A(s){return function(){const t=new s(...arguments);return t.__call__.bind(t)}}function E(s,t){return Array.from({length:t},()=>s).flat()}function tt(s){return/^[A-Z_$]*$/.test(s)}function fe(s,t,n){const r=s.split(t);return n?r.splice(-n-1):r}function ye(s,t){const n=new RegExp(t,"g");return(s.match(n)||[]).length}function An(s,t){for(const n of s)if(!t.has(n))return!1;return!0}function*In(s,t){let n=[],r=null;for(const i of s){const a=t(i);r&&a!=r&&(yield[r,n],n=[]),n.push(i),r=a}yield[r,n]}const $n={Terminal:ae,NonTerminal:oe,RuleOptions:B,PatternStr:le,PatternRE:ce,TerminalDef:G};var Pn={LarkError:k,ConfigurationError:R,GrammarError:M,ParseError:Ot,LexError:D,UnexpectedInput:q,UnexpectedEOF:At,UnexpectedCharacters:$,UnexpectedToken:P,VisitError:re,Meta:Oe,Tree:y,Discard:V,Transformer:L,Transformer_InPlace:Ae,Transformer_NonRecursive:Pt,Transformer_InPlaceRecursive:St,VisitorBase:se,Visitor:zt,Visitor_Recursive:Dt,Interpreter:Lt,Symbol:ie,Terminal:ae,NonTerminal:oe,RuleOptions:B,Rule:z,Pattern:_e,PatternStr:le,PatternRE:ce,TerminalDef:G,Token:f,Lexer:W,LexerConf:$e,ParserConf:Pe,InteractiveParser:O,ImmutableInteractiveParser:Le,PostLex:Qe,Lark:Ue,DedentError:Me,Indenter:Ze,PythonIndenter:bn,get_parser:Tn},Sn={parser:{lexer_conf:{terminals:[{"@":0},{"@":1},{"@":2},{"@":3},{"@":4},{"@":5},{"@":6},{"@":7},{"@":8},{"@":9},{"@":10},{"@":11},{"@":12},{"@":13},{"@":14},{"@":15},{"@":16},{"@":17},{"@":18},{"@":19},{"@":20}],ignore:["WS"],g_regex_flags:0,use_bytes:!1,lexer_type:"contextual",__type__:"LexerConf"},parser_conf:{rules:[{"@":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},{"@":49},{"@":50},{"@":51},{"@":52},{"@":53},{"@":54},{"@":55},{"@":56}],start:["start"],parser_type:"lalr",__type__:"ParserConf"},parser:{tokens:{0:"CONJUNCTION",1:"RPAR",2:"$END",3:"STRING",4:"IDENTIFIER",5:"INT",6:"OPERATOR",7:"RSQB",8:"__ANON_0",9:"__ANON_1",10:"mc_choice_selector",11:"question_selector",12:"LSQB",13:"__ANON_6",14:"bool_expr",15:"__ANON_3",16:"qc_mc_text_ignore_case",17:"NEGATION",18:"qc_matrix_displayed",19:"bool_const",20:"qc_mc_count",21:"qc_mc_displayed",22:"condition",23:"TRUE",24:"qc_matrix_selected",25:"qc_mc_text",26:"__ANON_4",27:"qc_matrix_count",28:"FALSE",29:"qc_mc_selected",30:"__ANON_2",31:"__ANON_5",32:"matrix_statement_selector",33:"matrix_choice_selector",34:"LPAR",35:"top_level_expr",36:"DOT",37:"start"},states:{0:{0:[0,59],1:[1,{"@":25}],2:[1,{"@":25}]},1:{1:[0,69]},2:{3:[0,65]},3:{1:[1,{"@":34}],0:[1,{"@":34}],2:[1,{"@":34}]},4:{4:[0,73],5:[0,8]},5:{0:[0,46],2:[1,{"@":23}]},6:{6:[0,7]},7:{3:[0,47]},8:{7:[0,17]},9:{8:[0,83],9:[0,56]},10:{1:[1,{"@":33}],0:[1,{"@":33}],2:[1,{"@":33}]},11:{1:[1,{"@":46}],0:[1,{"@":46}],2:[1,{"@":46}]},12:{1:[1,{"@":36}],0:[1,{"@":36}],2:[1,{"@":36}]},13:{10:[0,16],4:[0,72],11:[0,35]},14:{12:[0,31]},15:{1:[1,{"@":39}],0:[1,{"@":39}],2:[1,{"@":39}]},16:{1:[0,6]},17:{1:[1,{"@":50}]},18:{13:[0,54]},19:{1:[1,{"@":27}],0:[1,{"@":27}],2:[1,{"@":27}]},20:{4:[0,72],11:[0,61]},21:{1:[1,{"@":53}]},22:{4:[0,28]},23:{1:[1,{"@":44}],0:[1,{"@":44}],2:[1,{"@":44}]},24:{2:[1,{"@":22}]},25:{1:[1,{"@":37}],0:[1,{"@":37}],2:[1,{"@":37}]},26:{1:[1,{"@":28}],0:[1,{"@":28}],2:[1,{"@":28}]},27:{6:[0,71]},28:{12:[1,{"@":52}],1:[1,{"@":52}]},29:{5:[0,45]},30:{14:[0,78],15:[0,62],16:[0,55],17:[0,9],8:[0,38],18:[0,3],19:[0,19],20:[0,50],21:[0,51],22:[0,0],23:[0,48],24:[0,10],25:[0,82],9:[0,70],26:[0,32],27:[0,68],28:[0,52],29:[0,26],30:[0,13],31:[0,20]},31:{5:[0,34],4:[0,33]},32:{11:[0,74],4:[0,72]},33:{7:[0,81]},34:{7:[0,21]},35:{12:[0,4]},36:{5:[0,18],4:[0,66]},37:{6:[0,29]},38:{4:[0,72],32:[0,14],10:[0,49],33:[0,60],11:[0,84]},39:{1:[1,{"@":47}],0:[1,{"@":47}],2:[1,{"@":47}]},40:{1:[0,75]},41:{1:[1,{"@":26}],2:[1,{"@":26}]},42:{1:[0,43]},43:{1:[1,{"@":45}],0:[1,{"@":45}],2:[1,{"@":45}]},44:{2:[1,{"@":24}]},45:{1:[1,{"@":48}],0:[1,{"@":48}],2:[1,{"@":48}]},46:{34:[0,30],35:[0,44]},47:{1:[1,{"@":40}],0:[1,{"@":40}],2:[1,{"@":40}]},48:{1:[1,{"@":55}],0:[1,{"@":55}],2:[1,{"@":55}]},49:{1:[0,25]},50:{1:[1,{"@":32}],0:[1,{"@":32}],2:[1,{"@":32}]},51:{1:[1,{"@":29}],0:[1,{"@":29}],2:[1,{"@":29}]},52:{1:[1,{"@":56}],0:[1,{"@":56}],2:[1,{"@":56}]},53:{1:[0,79]},54:{6:[0,58]},55:{1:[1,{"@":31}],0:[1,{"@":31}],2:[1,{"@":31}]},56:{11:[0,84],4:[0,72],32:[0,42],10:[0,40]},57:{},58:{5:[0,39]},59:{14:[0,41],15:[0,62],16:[0,55],17:[0,9],8:[0,38],18:[0,3],19:[0,19],20:[0,50],21:[0,51],22:[0,0],23:[0,48],24:[0,10],25:[0,82],9:[0,70],26:[0,32],27:[0,68],28:[0,52],29:[0,26],30:[0,13],31:[0,20]},60:{1:[0,23]},61:{12:[0,36]},62:{4:[0,72],10:[0,53],11:[0,35]},63:{1:[0,12]},64:{2:[1,{"@":21}]},65:{1:[1,{"@":41}],0:[1,{"@":41}],2:[1,{"@":41}]},66:{13:[0,37]},67:{1:[1,{"@":42}],0:[1,{"@":42}],2:[1,{"@":42}]},68:{1:[1,{"@":35}],0:[1,{"@":35}],2:[1,{"@":35}]},69:{1:[1,{"@":43}],0:[1,{"@":43}],2:[1,{"@":43}]},70:{11:[0,84],4:[0,72],32:[0,77],10:[0,76]},71:{5:[0,67]},72:{12:[1,{"@":49}],1:[1,{"@":49}],36:[1,{"@":49}]},73:{7:[0,85]},74:{1:[0,27]},75:{1:[1,{"@":38}],0:[1,{"@":38}],2:[1,{"@":38}]},76:{1:[0,15]},77:{1:[0,11]},78:{1:[0,5]},79:{6:[0,2]},80:{15:[0,62],34:[0,30],17:[0,9],16:[0,55],8:[0,38],18:[0,3],19:[0,19],35:[0,64],20:[0,50],21:[0,51],22:[0,0],37:[0,57],23:[0,48],24:[0,10],25:[0,82],9:[0,70],26:[0,32],14:[0,24],27:[0,68],28:[0,52],29:[0,26],30:[0,13],31:[0,20]},81:{1:[1,{"@":54}]},82:{1:[1,{"@":30}],0:[1,{"@":30}],2:[1,{"@":30}]},83:{4:[0,72],32:[0,14],10:[0,63],11:[0,84],33:[0,1]},84:{12:[0,4],36:[0,22]},85:{1:[1,{"@":51}]}},start_states:{start:80},end_states:{start:57}},__type__:"ParsingFrontend"},rules:[{"@":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},{"@":49},{"@":50},{"@":51},{"@":52},{"@":53},{"@":54},{"@":55},{"@":56}],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"},zn={0:{name:"WS",pattern:{value:`(?:[ \f\r
|
|
22
|
+
])+`,flags:[],_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:[],_width:[2,4294967295],__type__:"PatternRE"},priority:0,__type__:"TerminalDef"},2:{name:"INT",pattern:{value:"-?[0-9]+",flags:[],_width:[1,4294967295],__type__:"PatternRE"},priority:0,__type__:"TerminalDef"},3:{name:"STRING",pattern:{value:`(?:'[^\\']*'|"[^"]*")`,flags:[],_width:[2,4294967295],__type__:"PatternRE"},priority:0,__type__:"TerminalDef"},4:{name:"OPERATOR",pattern:{value:"(?:regex_matches|not_contains|contains|==|!=|<=|>=|<|>)",flags:[],_width:[1,13],__type__:"PatternRE"},priority:0,__type__:"TerminalDef"},5:{name:"CONJUNCTION",pattern:{value:"(?:and|or)",flags:[],_width:[2,3],__type__:"PatternRE"},priority:0,__type__:"TerminalDef"},6:{name:"NEGATION",pattern:{value:"!",flags:[],__type__:"PatternStr"},priority:0,__type__:"TerminalDef"},7:{name:"TRUE",pattern:{value:"true",flags:[],__type__:"PatternStr"},priority:0,__type__:"TerminalDef"},8:{name:"FALSE",pattern:{value:"false",flags:[],__type__:"PatternStr"},priority:0,__type__:"TerminalDef"},9:{name:"LPAR",pattern:{value:"(",flags:[],__type__:"PatternStr"},priority:0,__type__:"TerminalDef"},10:{name:"RPAR",pattern:{value:")",flags:[],__type__:"PatternStr"},priority:0,__type__:"TerminalDef"},11:{name:"__ANON_0",pattern:{value:"selected(",flags:[],__type__:"PatternStr"},priority:0,__type__:"TerminalDef"},12:{name:"__ANON_1",pattern:{value:"displayed(",flags:[],__type__:"PatternStr"},priority:0,__type__:"TerminalDef"},13:{name:"__ANON_2",pattern:{value:"text(",flags:[],__type__:"PatternStr"},priority:0,__type__:"TerminalDef"},14:{name:"__ANON_3",pattern:{value:"text_ignore_case(",flags:[],__type__:"PatternStr"},priority:0,__type__:"TerminalDef"},15:{name:"__ANON_4",pattern:{value:"count_selected(",flags:[],__type__:"PatternStr"},priority:0,__type__:"TerminalDef"},16:{name:"__ANON_5",pattern:{value:"count_choice_selections(",flags:[],__type__:"PatternStr"},priority:0,__type__:"TerminalDef"},17:{name:"LSQB",pattern:{value:"[",flags:[],__type__:"PatternStr"},priority:0,__type__:"TerminalDef"},18:{name:"__ANON_6",pattern:{value:"])",flags:[],__type__:"PatternStr"},priority:0,__type__:"TerminalDef"},19:{name:"RSQB",pattern:{value:"]",flags:[],__type__:"PatternStr"},priority:0,__type__:"TerminalDef"},20:{name:"DOT",pattern:{value:".",flags:[],__type__:"PatternStr"},priority:0,__type__:"TerminalDef"},21:{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"},22:{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"},23:{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"},24:{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"},25:{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"},26:{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"},27:{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"},28:{origin:{name:"condition",__type__:"NonTerminal"},expansion:[{name:"qc_mc_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"},29:{origin:{name:"condition",__type__:"NonTerminal"},expansion:[{name:"qc_mc_displayed",__type__:"NonTerminal"}],order:2,alias:null,options:{keep_all_tokens:!1,expand1:!1,priority:null,template_source:null,empty_indices:[],__type__:"RuleOptions"},__type__:"Rule"},30:{origin:{name:"condition",__type__:"NonTerminal"},expansion:[{name:"qc_mc_text",__type__:"NonTerminal"}],order:3,alias:null,options:{keep_all_tokens:!1,expand1:!1,priority:null,template_source:null,empty_indices:[],__type__:"RuleOptions"},__type__:"Rule"},31:{origin:{name:"condition",__type__:"NonTerminal"},expansion:[{name:"qc_mc_text_ignore_case",__type__:"NonTerminal"}],order:4,alias:null,options:{keep_all_tokens:!1,expand1:!1,priority:null,template_source:null,empty_indices:[],__type__:"RuleOptions"},__type__:"Rule"},32:{origin:{name:"condition",__type__:"NonTerminal"},expansion:[{name:"qc_mc_count",__type__:"NonTerminal"}],order:5,alias:null,options:{keep_all_tokens:!1,expand1:!1,priority:null,template_source:null,empty_indices:[],__type__:"RuleOptions"},__type__:"Rule"},33:{origin:{name:"condition",__type__:"NonTerminal"},expansion:[{name:"qc_matrix_selected",__type__:"NonTerminal"}],order:6,alias:null,options:{keep_all_tokens:!1,expand1:!1,priority:null,template_source:null,empty_indices:[],__type__:"RuleOptions"},__type__:"Rule"},34:{origin:{name:"condition",__type__:"NonTerminal"},expansion:[{name:"qc_matrix_displayed",__type__:"NonTerminal"}],order:7,alias:null,options:{keep_all_tokens:!1,expand1:!1,priority:null,template_source:null,empty_indices:[],__type__:"RuleOptions"},__type__:"Rule"},35:{origin:{name:"condition",__type__:"NonTerminal"},expansion:[{name:"qc_matrix_count",__type__:"NonTerminal"}],order:8,alias:null,options:{keep_all_tokens:!1,expand1:!1,priority:null,template_source:null,empty_indices:[],__type__:"RuleOptions"},__type__:"Rule"},36:{origin:{name:"qc_mc_selected",__type__:"NonTerminal"},expansion:[{name:"NEGATION",filter_out:!1,__type__:"Terminal"},{name:"__ANON_0",filter_out:!0,__type__:"Terminal"},{name:"mc_choice_selector",__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"},37:{origin:{name:"qc_mc_selected",__type__:"NonTerminal"},expansion:[{name:"__ANON_0",filter_out:!0,__type__:"Terminal"},{name:"mc_choice_selector",__type__:"NonTerminal"},{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"},38:{origin:{name:"qc_mc_displayed",__type__:"NonTerminal"},expansion:[{name:"NEGATION",filter_out:!1,__type__:"Terminal"},{name:"__ANON_1",filter_out:!0,__type__:"Terminal"},{name:"mc_choice_selector",__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"},39:{origin:{name:"qc_mc_displayed",__type__:"NonTerminal"},expansion:[{name:"__ANON_1",filter_out:!0,__type__:"Terminal"},{name:"mc_choice_selector",__type__:"NonTerminal"},{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"},40:{origin:{name:"qc_mc_text",__type__:"NonTerminal"},expansion:[{name:"__ANON_2",filter_out:!0,__type__:"Terminal"},{name:"mc_choice_selector",__type__:"NonTerminal"},{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"},41:{origin:{name:"qc_mc_text_ignore_case",__type__:"NonTerminal"},expansion:[{name:"__ANON_3",filter_out:!0,__type__:"Terminal"},{name:"mc_choice_selector",__type__:"NonTerminal"},{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"},42:{origin:{name:"qc_mc_count",__type__:"NonTerminal"},expansion:[{name:"__ANON_4",filter_out:!0,__type__:"Terminal"},{name:"question_selector",__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"},43:{origin:{name:"qc_matrix_selected",__type__:"NonTerminal"},expansion:[{name:"NEGATION",filter_out:!1,__type__:"Terminal"},{name:"__ANON_0",filter_out:!0,__type__:"Terminal"},{name:"matrix_choice_selector",__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"},44:{origin:{name:"qc_matrix_selected",__type__:"NonTerminal"},expansion:[{name:"__ANON_0",filter_out:!0,__type__:"Terminal"},{name:"matrix_choice_selector",__type__:"NonTerminal"},{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"},45:{origin:{name:"qc_matrix_displayed",__type__:"NonTerminal"},expansion:[{name:"NEGATION",filter_out:!1,__type__:"Terminal"},{name:"__ANON_1",filter_out:!0,__type__:"Terminal"},{name:"matrix_statement_selector",__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:"qc_matrix_displayed",__type__:"NonTerminal"},expansion:[{name:"__ANON_1",filter_out:!0,__type__:"Terminal"},{name:"matrix_statement_selector",__type__:"NonTerminal"},{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"},47:{origin:{name:"qc_matrix_count",__type__:"NonTerminal"},expansion:[{name:"__ANON_5",filter_out:!0,__type__:"Terminal"},{name:"question_selector",__type__:"NonTerminal"},{name:"LSQB",filter_out:!0,__type__:"Terminal"},{name:"INT",filter_out:!1,__type__:"Terminal"},{name:"__ANON_6",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"},48:{origin:{name:"qc_matrix_count",__type__:"NonTerminal"},expansion:[{name:"__ANON_5",filter_out:!0,__type__:"Terminal"},{name:"question_selector",__type__:"NonTerminal"},{name:"LSQB",filter_out:!0,__type__:"Terminal"},{name:"IDENTIFIER",filter_out:!1,__type__:"Terminal"},{name:"__ANON_6",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"},49:{origin:{name:"question_selector",__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"},50:{origin:{name:"mc_choice_selector",__type__:"NonTerminal"},expansion:[{name:"question_selector",__type__:"NonTerminal"},{name:"LSQB",filter_out:!0,__type__:"Terminal"},{name:"INT",filter_out:!1,__type__:"Terminal"},{name:"RSQB",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"},51:{origin:{name:"mc_choice_selector",__type__:"NonTerminal"},expansion:[{name:"question_selector",__type__:"NonTerminal"},{name:"LSQB",filter_out:!0,__type__:"Terminal"},{name:"IDENTIFIER",filter_out:!1,__type__:"Terminal"},{name:"RSQB",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"},52:{origin:{name:"matrix_statement_selector",__type__:"NonTerminal"},expansion:[{name:"question_selector",__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"},53:{origin:{name:"matrix_choice_selector",__type__:"NonTerminal"},expansion:[{name:"matrix_statement_selector",__type__:"NonTerminal"},{name:"LSQB",filter_out:!0,__type__:"Terminal"},{name:"INT",filter_out:!1,__type__:"Terminal"},{name:"RSQB",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"},54:{origin:{name:"matrix_choice_selector",__type__:"NonTerminal"},expansion:[{name:"matrix_statement_selector",__type__:"NonTerminal"},{name:"LSQB",filter_out:!0,__type__:"Terminal"},{name:"IDENTIFIER",filter_out:!1,__type__:"Terminal"},{name:"RSQB",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"},55:{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"},56:{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"}};const nt=require("assert");function rt(s){if(s.length===1)return s[0];const t=s[1].value;return t==="or"?s[0]||s[2]:t==="and"?s[0]&&s[2]:!1}function ge(s,t,n){switch(t){case"==":return s===n;case"!=":return s!==n;case"<=":return s<=n;case">=":return s>=n;case"<":return s<n;case">":return s>n;default:return!1}}function st(s,t,n,r){const i=r?s.toLowerCase():s,a=r?n.toLowerCase():n;switch(t){case"contains":return i.includes(a);case"not_contains":return!i.includes(a);case"regex_matches":try{return new RegExp(n).test(i)}catch{return!1}default:return ge(i,t,a)}}function H(s,t){return s.length===1?t(s[0]):(nt(s[0].type==="NEGATION"),!t(s[1]))}function xe(s){if(!["INT","IDENTIFIER"].includes(s.type))throw new SyntaxError(`Invalid token type: ${s.type}; expected IDENTIFIER or INT`);return T(s)}function T(s){var t,n;switch(s.type){case"IDENTIFIER":return s.value;case"INT":return parseInt(s.value,10);case"STRING":{const r=s.value.match(/(?:'(?<single>[^\']*)')|(?:"(?<double>[^\"]*)")/),i=((t=r==null?void 0:r.groups)==null?void 0:t.double)||((n=r==null?void 0:r.groups)==null?void 0:n.single);return nt(i),i}case"OPERATOR":return s.value;case"TRUE":return!0;case"FALSE":return!1;default:throw new SyntaxError(`Invalid token type: ${s.type}`)}}function it(s,t){const n={start:r=>r[0],top_level_expr:rt,bool_expr:rt,condition:r=>r[0],qc_mc_selected:r=>H(r,t.isSelected),qc_mc_displayed:r=>H(r,t.isDisplayed),qc_mc_text:r=>st(t.textEntry(r[0]),T(r[1]),T(r[2]),!1),qc_mc_text_ignore_case:r=>st(t.textEntry(r[0]),T(r[1]),T(r[2]),!0),qc_mc_count:r=>ge(t.countSelected(r[0]),T(r[1]),T(r[2])),qc_matrix_selected:r=>H(r,t.isSelected),qc_matrix_displayed:r=>H(r,t.isDisplayed),qc_matrix_count:r=>ge(t.countChoiceSelections(r[0],xe(r[1])),T(r[2]),T(r[3])),question_selector:r=>r[0].value,mc_choice_selector:r=>({questionId:r[0],choice:xe(r[1])}),matrix_statement_selector:r=>({questionId:r[0],statementId:T(r[1])}),matrix_choice_selector:r=>({...r[0],choice:xe(r[1])}),bool_const:r=>r[0].value==="true"};return Pn.get_parser({transformer:n}).parse(s)}const Dn=/\$\{m:([^\}]+)\}/g,Ln=100,we=(s,t)=>{if(typeof t=="string"){let n=t,r=0;for(;r<Ln;){const i=n.replace(Dn,(a,o)=>{if(s[o]===void 0)throw new Error(`Undefined macro: ${o}`);return s[o]});if(i===n)return i;n=i,r+=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]=we(s,t[n])}),t},at=s=>(s.sections=we(s.macros||{},s.sections),s);var jn=Object.defineProperty,Cn=(s,t,n)=>t in s?jn(s,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):s[t]=n,S=(s,t,n)=>(Cn(s,typeof t!="symbol"?t+"":t,n),n);const ot=new mt.default({allowUnionTypes:!0});ft.default(ot);const _t=ot.compile(Re);class F extends Error{}class lt extends Error{}class I extends Error{}class Fn extends Error{}class Qn{constructor(){S(this,"seenQuestions",new Set),S(this,"seenQuestionStatements",new Map),S(this,"seenQuestionChoices",new Map),S(this,"seenTextChoices",new Map),S(this,"validateReference",t=>{var n,r,i;if(!this.seenQuestions.has(t.questionId))throw new F(`Invalid question: ${t.questionId}`);if(t.statementId!==void 0&&!((n=this.seenQuestionStatements.get(t.questionId))!=null&&n.has(t.statementId)))throw new F(`Invalid statement: ${t.questionId}.${t.statementId}`);if(t.choice!==void 0&&!((r=this.seenQuestionChoices.get(t.questionId))!=null&&r.has(t.choice)))throw new F(`Invalid choice: ${t.questionId}[${t.choice}]`);if(t.choice!==void 0&&t.expectText===!0&&!((i=this.seenTextChoices.get(t.questionId))!=null&&i.has(t.choice)))throw new F(`Invalid text reference: ${t.questionId}[${t.choice}]`)}),S(this,"evaluator",{isSelected:t=>(this.validateReference(t),!1),isDisplayed:t=>(this.validateReference(t),!1),countSelected:t=>(this.validateReference({questionId:t}),0),countChoiceSelections:(t,n)=>(this.validateReference({questionId:t,choice:n}),0),textEntry:t=>(this.validateReference({...t,expectText:!0}),"")})}}const Q=(s,t,n)=>{if(n)try{it(n,s.evaluator)}catch(r){throw r instanceof F||r instanceof I?r:new Error(`Syntax error parsing display logic at ${t}: ${n}`)}},ct=(s,t)=>{var n,r,i,a,o;Q(t,s.id,s.display_logic),Q(t,s.id,s.display_logic_in_page),(n=s.statements)==null||n.forEach(l=>{Q(t,`${s.id}.${l.id}`,l.display_logic)}),(r=s.choices)==null||r.forEach(l=>{Q(t,`${s.id}[${l.id||l.value}]`,l.display_logic)});const _=l=>{const[p,h]=l.split("/",2);return{questionId:p,expression:h}},c=l=>{const p=(l.expression.startsWith("for_matrix_choice")||l.expression.startsWith("unselected_for_matrix_choice")?t.seenQuestionStatements:t.seenQuestionChoices).get(l.questionId);if(p===void 0)throw new lt(`Invalid question referenced in locator expression: ${l.questionId}/${l.expression}`);return p};if(s.id!==void 0){if(t.seenQuestions.has(s.id))throw new I(`Duplicate question id: ${s.id}`);if(t.seenQuestions.add(s.id),s.statements||s.dynamic_statements){const p=new Set;if(t.seenQuestionStatements.set(s.id,p),(i=s.statements)==null||i.forEach(h=>{if(p.has(h.id))throw new I(`Duplicate statement id: ${s.id}.${h.id}`);p.add(h.id)}),s.dynamic_statements){const h=_(s.dynamic_statements);c(h).forEach(d=>{if(typeof d=="number")throw new lt(`Dynamic statement in question ${s.id} refers to choices with values`);if(p.has(d))throw new I(`Duplicate statement ${d} via dynamic statements in question ${s.id}`);p.add(d)})}}const l=(a=s.choices)!=null?a:[];if(s.choice_groups){if(new Set(s.choice_groups.map(p=>p.id)).size!==s.choice_groups.length)throw new I(`Choice groups must have a unique id in question ${s.id}`);s.choice_groups.forEach(p=>l.push(...p.choices))}if(l||s.dynamic_choices){const p=new Set;t.seenQuestionChoices.set(s.id,p);const h=new Set;if(t.seenTextChoices.set(s.id,h),l.forEach(d=>{var m;const b=(m=d.id)!=null?m:d.value;if(p.has(b))throw new I(`Duplicate choice: ${s.id}[${b}]`);p.add(b),d.text&&d.text!=="no"&&h.add(b)}),s.dynamic_choices){const d=_(s.dynamic_choices);c(d).forEach(m=>{if(p.has(m))throw new I(`Duplicate choice ${m} via dynamic choices in ${s.id}`);p.add(m)}),(o=t.seenTextChoices.get(d.questionId))==null||o.forEach(m=>h.add(m))}if(new Set([...p].map(d=>typeof d)).size>=2)throw new Fn("All choices in a question must either all have id's or all have values")}}},Un=s=>{if(!_t(s))throw new Error(`Invalid template: ${s.template.id}. Reason: ${JSON.stringify(_t.errors,null,4)}`);at(s);const t=new Qn;s.sections.forEach(n=>{var r,i;Q(t,n.id,n.display_logic),(r=n.questions)==null||r.forEach(a=>{ct(a,t)}),(i=n.pages)==null||i.forEach(a=>{var o;(o=a.questions)==null||o.forEach(_=>{ct(_,t)})})})},Mn=Re,Zn="pulse_default_alpha",Bn={allPermissions:gt,SURVEY_RESOURCE_TYPE:yt,surveyAdministerPermission:ke};exports.DEFAULT_TEMPLATE_ID=Zn,exports.evaluateExpression=it,exports.interpolateMacros=we,exports.interpolateTemplate=at,exports.permissions=Bn,exports.templateSchema=Mn,exports.validateTemplate=Un;
|
|
23
23
|
//# sourceMappingURL=index.cjs.js.map
|
package/dist/index.d.ts
CHANGED
|
@@ -54,7 +54,7 @@ interface SurveyTemplate {
|
|
|
54
54
|
default?: string | number | boolean;
|
|
55
55
|
}[];
|
|
56
56
|
/**
|
|
57
|
-
* Expression shortcuts. Macros are referred to elsewhere in the survey using the $\{
|
|
57
|
+
* 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.
|
|
58
58
|
*/
|
|
59
59
|
macros?: {
|
|
60
60
|
[k: string]: string;
|
|
@@ -144,7 +144,7 @@ interface Question {
|
|
|
144
144
|
statement_groups?: {
|
|
145
145
|
statements: Statement[];
|
|
146
146
|
/**
|
|
147
|
-
* The id of the group.
|
|
147
|
+
* The id of the group.
|
|
148
148
|
*/
|
|
149
149
|
id?: string;
|
|
150
150
|
/**
|
|
@@ -165,7 +165,7 @@ interface Question {
|
|
|
165
165
|
choice_groups?: {
|
|
166
166
|
choices: Choice[];
|
|
167
167
|
/**
|
|
168
|
-
* The id of the group.
|
|
168
|
+
* The id of the group.
|
|
169
169
|
*/
|
|
170
170
|
id?: string;
|
|
171
171
|
/**
|
|
@@ -250,6 +250,43 @@ interface Page {
|
|
|
250
250
|
/** @public */
|
|
251
251
|
declare const validateTemplate: (template: SurveyTemplate) => void;
|
|
252
252
|
|
|
253
|
+
/**
|
|
254
|
+
* Mutates the template by replacing all references to $\{m:<macro>\} with
|
|
255
|
+
* the evaluation of the macro. This can and must be done once after
|
|
256
|
+
* loading the template and before evaluating any expression etc.
|
|
257
|
+
*
|
|
258
|
+
* The interpolation is idempotent.
|
|
259
|
+
*
|
|
260
|
+
* @public */
|
|
261
|
+
declare const interpolateTemplate: (template: SurveyTemplate) => SurveyTemplate;
|
|
262
|
+
|
|
263
|
+
/** Refers to a specific choice in a specific question/statement
|
|
264
|
+
* If statementId is defined, questionId.statementId is the full path
|
|
265
|
+
* to this choice
|
|
266
|
+
* @public */
|
|
267
|
+
type ChoiceRef = {
|
|
268
|
+
questionId: string;
|
|
269
|
+
statementId?: string;
|
|
270
|
+
choice: string | number;
|
|
271
|
+
};
|
|
272
|
+
/** Refers to a specific statement in a matrix
|
|
273
|
+
* @public */
|
|
274
|
+
type MatrixStatementRef = {
|
|
275
|
+
questionId: string;
|
|
276
|
+
statementId: string;
|
|
277
|
+
};
|
|
278
|
+
/** @public */
|
|
279
|
+
type LogicContextEvaluator = {
|
|
280
|
+
surveyResponseId?: string;
|
|
281
|
+
isSelected: (choice: ChoiceRef) => boolean;
|
|
282
|
+
isDisplayed: (choice: ChoiceRef) => boolean;
|
|
283
|
+
countSelected: (questionId: string) => number;
|
|
284
|
+
countChoiceSelections: (questionId: string, choice: number | string) => number;
|
|
285
|
+
textEntry: (choiceRef: ChoiceRef) => string;
|
|
286
|
+
};
|
|
287
|
+
/** @public */
|
|
288
|
+
declare function evaluateExpression(expression: string, contextEvaluator: LogicContextEvaluator): any;
|
|
289
|
+
|
|
253
290
|
/** @public */
|
|
254
291
|
declare const templateSchema: {
|
|
255
292
|
$id: string;
|
|
@@ -260,6 +297,7 @@ declare const templateSchema: {
|
|
|
260
297
|
template: {
|
|
261
298
|
type: string;
|
|
262
299
|
description: string;
|
|
300
|
+
/** @public */
|
|
263
301
|
properties: {
|
|
264
302
|
id: {
|
|
265
303
|
type: string;
|
|
@@ -781,4 +819,4 @@ declare const permissions: {
|
|
|
781
819
|
surveyAdministerPermission: _backstage_plugin_permission_common.BasicPermission;
|
|
782
820
|
};
|
|
783
821
|
|
|
784
|
-
export { Choice, DEFAULT_TEMPLATE_ID, Page, Question, Randomization, Section, Statement, SurveyTemplate, permissions, templateSchema, validateTemplate };
|
|
822
|
+
export { Choice, ChoiceRef, DEFAULT_TEMPLATE_ID, LogicContextEvaluator, MatrixStatementRef, Page, Question, Randomization, Section, Statement, SurveyTemplate, evaluateExpression, interpolateTemplate, permissions, templateSchema, validateTemplate };
|
package/dist/index.esm.js
CHANGED
|
@@ -1,23 +1,23 @@
|
|
|
1
|
-
import{createPermission as lt}from"@backstage/plugin-permission-common";import ct from"ajv";import pt from"ajv-formats";const ut="survey-instance",ve=lt({name:"survey.instance.administer",attributes:{action:"create"}}),ht=[ve];var dt="surveyTemplate",mt="http://json-schema.org/draft-07/schema",ft="Survey Template",yt="object",gt={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 ${p:<name>} construct (same as 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"}}},xt=!1,wt=["template","parameters","sections"],bt={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."},questions:{type:"array",description:"The questions in the section (all in one page)",items:{$ref:"#/$defs/question"}},pages:{type:"array",description:"The questions in the section, split into pages",items:{$ref:"#/$defs/page"}}},additionalProperties:!1,required:["id","name"],oneOf:[{required:["questions"]},{required:["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"},text_html:{type:"string",description:"The question description, in HTML"},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"},display_logic_in_page:{type:"string",description:"Similar to display_logic, but enables the question to appear on the same page as the depending question"},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|displayed|not_displayed|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. Need only be set if referenced to in constrained randomization."},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","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|displayed|not_displayed|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. Need only be set if referenced to in constrained randomization."},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","display"],additionalProperties:!1}},randomization:{$ref:"#/$defs/randomization"}},additionalProperties:!1,allOf:[{oneOf:[{required:["text"]},{required:["text_html"]}]},{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:{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}},Ne={$id:dt,$schema:mt,title:ft,type:yt,properties:gt,additionalProperties:xt,required:wt,$defs:bt},Tt=Object.defineProperty,vt=(s,t,n)=>t in s?Tt(s,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):s[t]=n,N=(s,t,n)=>(vt(s,typeof t!="symbol"?t+"":t,n),n);class ke{}class Re{}class te extends Error{}class R extends Error{}class E extends R{}function ne(s,t,n="Got %r, expected one of %s"){if(!t.includes(s))throw new E(h(n,s,t))}class Z extends R{}class Nt extends R{}class L extends R{}class O extends R{constructor(){super(...arguments),N(this,"pos_in_stream",null),N(this,"_terminals_by_name",null)}get_context(t,n=40){let r,i;const a=this.pos_in_stream,o=max(a-n,0),_=a+n;return t instanceof bytes?(i=b(fe(t.slice(o,a),`
|
|
1
|
+
import{createPermission as pt}from"@backstage/plugin-permission-common";import ut from"ajv";import ht from"ajv-formats";const dt="survey-instance",Ne=pt({name:"survey.instance.administer",attributes:{action:"create"}}),mt=[Ne];var ft="surveyTemplate",yt="http://json-schema.org/draft-07/schema",gt="Survey Template",xt="object",wt={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"}}},bt=!1,Tt=["template","parameters","sections"],vt={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."},questions:{type:"array",description:"The questions in the section (all in one page)",items:{$ref:"#/$defs/question"}},pages:{type:"array",description:"The questions in the section, split into pages",items:{$ref:"#/$defs/page"}}},additionalProperties:!1,required:["id","name"],oneOf:[{required:["questions"]},{required:["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"},text_html:{type:"string",description:"The question description, in HTML"},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"},display_logic_in_page:{type:"string",description:"Similar to display_logic, but enables the question to appear on the same page as the depending question"},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|displayed|not_displayed|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|displayed|not_displayed|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"}},additionalProperties:!1,allOf:[{oneOf:[{required:["text"]},{required:["text_html"]}]},{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:{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}},ke={$id:ft,$schema:yt,title:gt,type:xt,properties:wt,additionalProperties:bt,required:Tt,$defs:vt},Nt=Object.defineProperty,kt=(s,t,n)=>t in s?Nt(s,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):s[t]=n,v=(s,t,n)=>(kt(s,typeof t!="symbol"?t+"":t,n),n);class Re{}class Ee{}class te extends Error{}class k extends Error{}class R extends k{}function ne(s,t,n="Got %r, expected one of %s"){if(!t.includes(s))throw new R(u(n,s,t))}class Z extends k{}class Rt extends k{}class D extends k{}class q extends k{constructor(){super(...arguments),v(this,"pos_in_stream",null),v(this,"_terminals_by_name",null)}get_context(t,n=40){let r,i;const a=this.pos_in_stream,o=max(a-n,0),_=a+n;return t instanceof bytes?(i=w(fe(t.slice(o,a),`
|
|
2
2
|
`,1)),r=t.slice(a,_).split(`
|
|
3
3
|
`,1)[0],`${i+r}
|
|
4
4
|
${" "*i.expandtabs().length}^
|
|
5
|
-
`.decode("ascii","backslashreplace")):(i=
|
|
5
|
+
`.decode("ascii","backslashreplace")):(i=w(fe(t.slice(o,a),`
|
|
6
6
|
`,1)),r=t.slice(a,_).split(`
|
|
7
7
|
`,1)[0],`${i+r}
|
|
8
8
|
${" "*i.expandtabs().length}^
|
|
9
|
-
`)}match_examples(t,n,r=!1){me(n)&&(n=g(n));let i=[null,!1];for(const[a,[o,_]]of
|
|
9
|
+
`)}match_examples(t,n,r=!1){me(n)&&(n=g(n));let i=[null,!1];for(const[a,[o,_]]of C(n))for(const[c,l]of C(_))try{t(l)}catch(p){if(p instanceof q){if(p.state.eq(this.state)){if(p.token===this.token)return o;r&&p.token.type===this.token.type&&!w(i)&&(i=[o,!0]),i[0]===null&&(i=[o,!1])}}else throw p}return i[0]}_format_expected(t){let n;return this._terminals_by_name&&(n=this._terminals_by_name,t=t.map(r=>r in n?n[r].user_repr():r)),u(`Expected one of:
|
|
10
10
|
* %s
|
|
11
11
|
`,t.join(`
|
|
12
|
-
* `))}}class
|
|
12
|
+
* `))}}class Et extends q{constructor(t,n=null,r=null){super(),this.expected=t,this.state=n,this.token=new f("<EOF>",""),this.pos_in_stream=-1,this.line=-1,this.column=-1,this._terminals_by_name=r}}class $ extends q{constructor({seq:t,lex_pos:n,line:r,column:i,allowed:a=null,considered_tokens:o=null,state:_=null,token_history:c=null,terminals_by_name:l=null,considered_rules:p=null}={}){super(),this.line=r,this.column=i,this.pos_in_stream=n,this.state=_,this._terminals_by_name=l,this.allowed=a,this.considered_tokens=o,this.considered_rules=p,this.token_history=c,this.char=t[n]}}class P extends q{constructor({token:t,expected:n,considered_rules:r=null,state:i=null,interactive_parser:a=null,terminals_by_name:o=null,token_history:_=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=n,this._accepts=Me,this.considered_rules=r,this.interactive_parser=a,this._terminals_by_name=o,this.token_history=_}get accepts(){return this._accepts===Me&&(this._accepts=this.interactive_parser&&this.interactive_parser.accepts()),this._accepts}}class re extends k{constructor(t,n,r){const i=u(`Error trying to process rule "%s":
|
|
13
13
|
|
|
14
|
-
%s`,t,r);super(i),this.rule=t,this.obj=n,this.orig_exc=r}}function
|
|
15
|
-
`];const r=[
|
|
16
|
-
`];for(const i of this.children)i instanceof y?r.push(...i._pretty(t+1,n)):r.push(
|
|
17
|
-
`);return r}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];const n=new Map;for(const r of t)n.set(r,r),t.push(...[...r.children].reverse().filter(i=>i instanceof y&&!n.has(i)).map(i=>i));return t=void 0,[...n.values()].reverse()}find_pred(t){return
|
|
18
|
-
`)||s.includes("\\n")||s.includes("\\s")||s.includes("[^")||s.includes("(?s")&&s.includes(".")}class
|
|
19
|
-
`),this.last_token=r}eq(t){return t instanceof be?this.text===t.text&&this.line_ctr===t.line_ctr&&this.last_token===t.last_token:C}}class Oe{constructor(t,n){this.lexer=t,this.state=n}static from_text(t,n){return new this(t,new be(n))}lex(t){return this.lexer.lex(this.state,t)}}class W extends ke{lex(t,n){return C}}function Qt(s,t){s.sort((n,r)=>{const i=t(n),a=t(r);for(let o=0;o<i.length;o++){if(i[o]>a[o])return 1;if(i[o]<a[o])return-1}return 0})}class J extends W{constructor(t){super();const n=[...t.terminals];if(this.re=t.re_module,!t.skip_validation){for(const r of n){try{this.re.compile(r.pattern.to_regexp(),t.g_regex_flags)}catch(i){throw i instanceof this.re.error?new L(h("Cannot compile token %s: %s",r.name,r.pattern)):i}if(r.pattern.min_width===0)throw new L(h("Lexer does not allow zero-width terminals. (%s: %s)",r.name,r.pattern))}if(!(new Set(t.ignore)<=new Set(n.map(r=>r.name))))throw new L(h("Ignore terminals are not defined: %s",Ve(new Set(t.ignore),new Set(n.map(r=>r.name)))))}this.newline_types=Y(n.filter(r=>Ct(r.pattern.to_regexp())).map(r=>r.name)),this.ignore_types=Y(t.ignore),Qt(n,r=>[-r.priority,-r.pattern.max_width,-r.pattern.value.length,r.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]=jt(this.terminals,this.g_regex_flags,this.re,this.use_bytes);for(const[n,r]of g(this.user_callbacks))n in this.callback?this.callback[n]=new Lt(this.callback[n],r,i=>i.type===n):this.callback[n]=r;this._scanner=new Be(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(r){if(!(r instanceof te))throw r}}next_token(t,n=null){let r,i,a,o;const _=t.line_ctr;for(;_.char_pos<t.text.length;){if(i=this.match(t.text,_.char_pos),!i)throw r=Ve(this.scanner.allowed_types,this.ignore_types),r||(r=new Set(["<END-OF-FILE>"])),new $({seq:t.text,lex_pos:_.char_pos,line:_.line,column:_.column,allowed:r,token_history:t.last_token&&[t.last_token],state:n,terminals_by_name:this.terminals_by_name});const[c,l]=i;if(!this.ignore_types.has(l)){if(a=new f(l,c,_.char_pos,_.line,_.column),_.feed(c,this.newline_types.has(l)),a.end_line=_.line,a.end_column=_.column,a.end_pos=_.char_pos,a.type in this.callback&&(a=this.callback[a.type](a),!(a instanceof f)))throw new L(h("Callbacks must return a token (returned %r)",a));return t.last_token=a,a}l in this.callback&&(o=new f(l,c,_.char_pos,_.line,_.column),this.callback[l](o)),_.feed(c,this.newline_types.has(l))}throw new te(this)}}class Ft extends W{constructor({conf:t,states:n,always_accept:r=[]}={}){super();let i,a,o;const _=[...t.terminals],c=t.terminals_by_name,l=k(t);l.terminals=_;const p=new Map;this.lexers={};for(let[u,m]of g(n))i=Y(m),p.has(i)?a=p.get(i):(m=bn(new Set(m),[...new Set(t.ignore),...new Set(r)]),o=k(l),o.terminals=[...m].filter(d=>d in c).map(d=>c[d]),a=new J(o),p.set(i,a)),this.lexers[u]=a;this.root_lexer=new J(l)}*lex(t,n){let r,i,a;try{for(;;)i=this.lexers[n.position],yield i.next_token(t,n)}catch(o){if(!(o instanceof te))if(o instanceof $)try{throw r=t.last_token,a=this.root_lexer.next_token(t,n),new P({token:a,expected:o.allowed,state:n,token_history:[r],terminals_by_name:this.root_lexer.terminals_by_name})}catch(_){throw _}else throw o}}}class Ae extends w{static get __serialize_fields__(){return["terminals","ignore","g_regex_flags","use_bytes","lexer_type"]}static get __serialize_namespace__(){return[G]}constructor({terminals:t,re_module:n,ignore:r=[],postlex:i=null,callbacks:a=null,g_regex_flags:o="",skip_validation:_=!1,use_bytes:c=!1}={}){super(),this.terminals=t,this.terminals_by_name=Object.fromEntries(this.terminals.map(l=>[l.name,l])),this.ignore=r,this.postlex=i,this.callbacks=Object.keys(a).length||{},this.g_regex_flags=o,this.re_module=n,this.skip_validation=_,this.use_bytes=c,this.lexer_type=null}_deserialize(){this.terminals_by_name=Object.fromEntries(this.terminals.map(t=>[t.name,t]))}}class Ie extends w{static get __serialize_fields__(){return["rules","start","parser_type"]}constructor(t,n,r){super(),this.rules=t,this.callbacks=n,this.start=r,this.parser_type=null}}class Ut{constructor(t){this.node_builder=t}__call__(t){return t.length===1?t[0]:this.node_builder(t)}}const Zt=I(Ut);class Mt{constructor(t,n=null){this.node_builder=t,this.node_filter=n}__call__(t){let n,r,i;const a=this.node_builder(t);return a instanceof y&&(i=a.meta,n=this._pp_get_meta(t),n!==null&&("line"in i||(i.line=n&&n.container_line||n.line,i.column=n&&n.container_column||n.column,i.start_pos=n&&n.container_start_pos||n.start_pos,i.empty=!1),i.container_line=n&&n.container_line||n.line,i.container_column=n&&n.container_column||n.column),r=this._pp_get_meta([...t].reverse()),r!==null&&("end_line"in i||(i.end_line=r&&r.container_end_line||r.end_line,i.end_column=r&&r.container_end_column||r.end_column,i.end_pos=r&&r.container_end_pos||r.end_pos,i.empty=!1),i.container_end_line=r&&r.container_end_line||r.end_line,i.container_end_column=r&&r.container_end_column||r.end_column)),a}_pp_get_meta(t){for(const n of t)if(!(this.node_filter!==null&&!this.node_filter(n))){if(n instanceof y){if(!n.meta.empty)return n.meta}else if(n instanceof f)return n}}}const $e=I(Mt);function Bt(s){if(vn(s))return K({unknown_param_0:$e,node_filter:s});if(s===!0)return $e;if(s===!1)return null;throw new E(h("Invalid option for propagate_positions: %r",s))}class pe{constructor(t,n,r){this.node_builder=r,this.to_include=t,this.append_none=n}__call__(t){const n=[];for(const[r,i,a]of this.to_include)a&&n.push(...q([null],a)),i?n.push(...t[r].children):n.push(t[r]);return this.append_none&&n.push(...q([null],this.append_none)),this.node_builder(n)}}const Gt=I(pe);class Wt extends pe{__call__(t){let n=[];for(const[r,i,a]of this.to_include)a&&n.push(...q([null],a)),i?n.length?n.push(...t[r].children):n=t[r].children:n.push(t[r]);return this.append_none&&n.push(...q([null],this.append_none)),this.node_builder(n)}}const Jt=I(Wt);class Vt extends pe{constructor(t,n){super(),this.node_builder=n,this.to_include=t}__call__(t){let n=[];for(const[r,i]of this.to_include)i?n.length?n.push(...t[r].children):n=t[r].children:n.push(t[r]);return this.node_builder(n)}}const Yt=I(Vt);function Kt(s){return!s.is_term&&s.name.startsWith("_")}function Ht(s,t,n,r){let i,a;r.length?(a=r.map(c=>(0+c).toString()).join(""),i=a.split("0").map(c=>c.length)):i=q([0],s.length+1);const o=[];let _=0;for(const[c,l]of Q(s))_+=i[c],(t||!(l.is_term&&l.filter_out))&&(o.push([c,Kt(l),_]),_=0);if(_+=i[s.length],r.length||o.length<s.length||Nn(o.map(([c,l,p])=>l)))return(r.length||n).length?K(n?Gt:Jt,o,_):K(Yt,o.map(([c,l,p])=>[c,l]))}function Xt(s){function t(n){const r=new y(s.name,n);return s(r)}return t=wraps(s)(t),t}function en(s,t,n){if(n===_vargs_meta||n===_vargs_meta_inline)throw new NotImplementedError("Meta args not supported for internal transformer");function r(i){return n(s,t,i,null)}return r=wraps(s)(r),r}class tn{constructor(t,n,r=!1,i=!1,a=!1){this.tree_class=n,this.propagate_positions=r,this.ambiguous=i,this.maybe_placeholders=a,this.rule_builders=[...this._init_builders(t)]}*_init_builders(t){let n,r,i,a;const o=Bt(this.propagate_positions);for(const _ of t)i=_.options,r=i.keep_all_tokens,n=i.expand1,a=[...He(null,[n&&!_.alias&&Zt,Ht(_.expansion,r,this.ambiguous,this.maybe_placeholders?i.empty_indices:[]),o])],yield[_,a]}create_callback(t=null){let n,r,i;const a=new Map;for(const[o,_]of this.rule_builders){r=o.alias||o.options.template_source||o.origin.name,t&&t[r]?(n=t&&t[r],i=n&&n.visit_wrapper||null,i!==null?n=en(n,r,i):t instanceof qe&&(n=Xt(n))):n=K(this.tree_class,r);for(const c of _)n=c(n);if(a.has(o))throw new Z(h("Rule '%s' already exists",o));a.set(o,n)}return a}}class Pe extends w{constructor({parser_conf:t,debug:n=!1}={}){super();const r=new LALR_Analyzer({unknown_param_0:t,debug:n});r.compute_lalr();const i=t.callbacks;this._parse_table=r.parse_table,this.parser_conf=t,this.parser=new Se(r.parse_table,i,n)}static deserialize(t,n,r,i=!1){const a=de(this);return a._parse_table=sn.deserialize(t,n),a.parser=new Se(a._parse_table,r,i),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:r=null}={}){let i,a;try{return this.parser.parse({lexer:t,start:n})}catch(o){if(o instanceof O){if(r===null)throw o;for(;;){if(o instanceof $&&(a=o.interactive_parser.lexer_thread.state,i=a.line_ctr.char_pos),!r(o))throw o;o instanceof $&&i===a.line_ctr.char_pos&&a.line_ctr.feed(a.text.slice(i,i+1));try{return o.interactive_parser.resume_parse()}catch(_){if(_ instanceof P){if(o instanceof P&&o.token.type===_.token.type&&_.token.type==="$END"&&o.interactive_parser.eq(_.interactive_parser))throw _;o=_}else if(_ instanceof $)o=_;else throw _}}}else throw o}}}class nn{constructor(t,n,r){this.parse_table=t,this.start_state=this.parse_table.start_states[r],this.end_state=this.parse_table.end_states[r],this.states=this.parse_table.states,this.callbacks=n,this.start=r}}class Te{constructor(t,n,r=null,i=null){this.parse_conf=t,this.lexer=n,this.state_stack=r||[this.parse_conf.start_state],this.value_stack=i||[]}get position(){return b(this.state_stack)}eq(t){return t instanceof Te?this.state_stack.length===t.state_stack.length&&this.position===t.position:C}copy(){return k(this)}feed_token(t,n=!1){let r,i,a,o,_,c,l,p,u,m;const d=this.state_stack,x=this.value_stack,v=this.parse_conf.states,_t=this.parse_conf.end_state,X=this.parse_conf.callbacks;for(;;){if(u=b(d),t.type in v[u])[i,a]=v[u][t.type];else throw o=new Set(he(v[u]).filter(ee=>Xe(ee)).map(ee=>ee)),new P({token:t,expected:o,state:this,interactive_parser:null});if(i===ue){d.push(a),x.push(t.type in X?X[t.type](t):t);return}if(c=a,p=c.expansion.length,p?(l=x.slice(-p),d.splice(-p),x.splice(-p)):l=[],m=X.get(c)(l),[r,_]=v[b(d)][c.origin.name],d.push(_),x.push(m),n&&b(d)===_t)return b(x)}}}class Se{constructor(t,n,r=!1){this.parse_table=t,this.callbacks=n,this.debug=r}parse({lexer:t,start:n,value_stack:r=null,state_stack:i=null,start_interactive:a=!1}={}){const o=new nn(this.parse_table,this.callbacks,n),_=new Te(o,t,i,r);return a?new A(this,_,_.lexer):this.parse_from_state(_)}parse_from_state(t){let n,r;try{r=null;for(r of t.lexer.lex(t))t.feed_token(r);return n=r?f.new_borrow_pos("$END","",r):new f("$END","",0,1,1),t.feed_token(n,!0)}catch(i){if(i instanceof O){try{i.interactive_parser=new A(this,t,t.lexer)}catch(a){if(!(a instanceof ReferenceError))throw a}throw i}else if(i instanceof Error){if(this.debug){console.log(""),console.log("STATE STACK DUMP"),console.log("----------------");for(const[a,o]of Q(t.state_stack))console.log(h("%d)",a),o);console.log("")}throw i}else throw i}}}class A{constructor(t,n,r){this.parser=t,this.parser_state=n,this.lexer_thread=r,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){const n=t!==null?f.new_borrow_pos("$END","",t):new f("$END","",0,1,1);return this.feed_token(n)}copy(){return k(this)}eq(t){return t instanceof A?this.parser_state===t.parser_state&&this.lexer_thread===t.lexer_thread:!1}as_immutable(){const t=k(this);return new ze(t.parser,t.parser_state,t.lexer_thread)}pretty(){const t=["Parser choices:"];for(const[n,r]of g(this.choices()))t.push(h(" - %s -> %r",n,r));return t.push(h("stack size: %s",this.parser_state.state_stack.length)),t.join(`
|
|
20
|
-
`)}choices(){return this.parser_state.parse_conf.parse_table.states[this.parser_state.position]}accepts(){let t;const n=new Set;for(const r of this.choices())if(Xe(r)){t=k(this);let i=null;try{t.feed_token(new f(r,""))}catch(a){if(i=a,!(a instanceof P))throw a}i||n.add(r)}return n}resume_parse(){return this.parser.parse_from_state(this.parser_state)}}class ze extends A{constructor(){super(...arguments),N(this,"result",null)}feed_token(t){const n=k(this);return n.result=A.feed_token(n,t),n}exhaust_lexer(){const t=this.as_mutable();return t.exhaust_lexer(),t.as_immutable()}as_mutable(){const t=k(this);return new A(t.parser,t.parser_state,t.lexer_thread)}}class De{constructor(t){this.name=t}repr(){return this.toString()}}var ue=new De("Shift");const Le=new De("Reduce");class rn{constructor(t,n,r){this.states=t,this.start_states=n,this.end_states=r}serialize(t){const n=new Enumerator,r=Object.fromEntries(g(this.states).map(([i,a])=>[i,Object.fromEntries(g(a).map(([o,[_,c]])=>[We(n,o),_===Le?[1,c.serialize(t)]:[0,c]]))]));return{tokens:n.reversed(),states:r,start_states:this.start_states,end_states:this.end_states}}static deserialize(t,n){const r=this,i=t.tokens,a=Object.fromEntries(g(t.states).map(([o,_])=>[o,Object.fromEntries(g(_).map(([c,[l,p]])=>[i[c],l===1?[Le,D.deserialize(p,n)]:[ue,p]]))]));return new r(a,t.start_states,t.end_states)}}class sn extends rn{static from_ParseTable(t){const n=this,r=[...t.states],i=Object.fromEntries(Q(r).map(([c,l])=>[l,c])),a={};for(let[c,l]of g(t.states))l=Object.fromEntries(g(l).map(([p,u])=>[p,u[0]===ue?[u[0],i[u[1]]]:u])),a[i[c]]=l;const o=Object.fromEntries(g(t.start_states).map(([c,l])=>[c,i[l]])),_=Object.fromEntries(g(t.end_states).map(([c,l])=>[c,i[l]]));return new n(a,o,_)}}function an(s){if(s&&s.__future_interface__)return s;class t extends W{constructor(r){super(),this.lexer=s(r)}lex(r,i){return this.lexer.lex(r.text)}}return t}function on(s,t,n,r,i){const a=Ie.deserialize(s.parser_conf,t),o=Pe.deserialize(s.parser,t,r,i.debug);return a.callbacks=r,new _n({lexer_conf:n,parser_conf:a,options:i,parser:o})}const je={};class _n extends w{static get __serialize_fields__(){return["lexer_conf","parser_conf","parser"]}constructor({lexer_conf:t,parser_conf:n,options:r,parser:i=null}={}){super();let a,o;this.parser_conf=n,this.lexer_conf=t,this.options=r,i?this.parser=i:(o=We(je,n.parser_type),this.parser=o(t,n,r));const _=t.lexer_type;if(this.skip_lexer=!1,["dynamic","dynamic_complete"].includes(_)){this.skip_lexer=!0;return}const c={basic:un,contextual:hn};_ in c?(a=c[_],this.lexer=a(t,this.parser,t.postlex,r)):this.lexer=an(_)(t),t.postlex&&(this.lexer=new pn(this.lexer,t.postlex))}_verify_start(t=null){let n;if(t===null){if(n=this.parser_conf.start,n.length>1)throw new E("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 E(h("Unknown start rule %s. Must be one of %r",t,this.parser_conf.start));return t}_make_lexer_thread(t){return this.skip_lexer?t:Oe.from_text(this.lexer,t)}parse(t,n=null,r=null){const i=this._verify_start(n),a=r===null?{}:{on_error:r},o=this._make_lexer_thread(t);return this.parser.parse({lexer:o,start:i,...a})}parse_interactive(t=null,n=null){const r=this._verify_start(n);if(this.parser_conf.parser_type!=="lalr")throw new E("parse_interactive() currently only works with parser='lalr' ");const i=this._make_lexer_thread(t);return this.parser.parse_interactive(i,r)}}function ln(s,t){let n;ne(s,["lalr","earley","cyk"]),typeof t!="object"&&(n={lalr:["basic","contextual"],earley:["basic","dynamic","dynamic_complete"],cyk:["basic"]}[s],ne(t,n,h("Parser %r does not support lexer %%r, expected one of %%s",s)))}function cn(s,t){let n;const r={};for(const i of t)n=s&&s[i.name]||null,n!==null&&(r[i.name]=n);return r}class pn{constructor(t,n){this.lexer=t,this.postlexer=n}lex(t,n){const r=this.lexer.lex(t,n);return this.postlexer.process(r)}}function un(s,t,n,r){return new J(s)}function hn(s,t,n,r){const i=Object.fromEntries(g(t._parse_table.states).map(([o,_])=>[o,[...he(_)]])),a=n?n.always_accept:[];return new Ft({conf:s,states:i,always_accept:a})}function dn(s,t,n=null){const r=n?n.debug:!1;return new Pe({parser_conf:t,debug:r})}je.lalr=dn;class Ce extends ke{constructor(){super(...arguments),N(this,"always_accept",[])}process(t){return t}}class mn extends w{constructor(t){super(),N(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 '),N(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;const r=Ye(t),i=this;for(const[a,o]of g(this._defaults))a in r?(n=xn(r,a),typeof o=="boolean"&&!["cache","use_bytes","propagate_positions"].includes(a)&&(n=Ke(n))):n=o,i[a]=n;if(typeof i.start=="string"&&(i.start=[i.start]),this.options=i,ne(this.parser,["earley","lalr","cyk",null]),this.parser==="earley"&&this.transformer)throw new E("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(r).length)throw new E(h("Unknown options: %s",he(r)))}serialize(t){return this.options}static deserialize(t,n){const r=this;return new r(t)}}class Qe extends w{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 J(n)}_prepare_callbacks(){this._callbacks=new Map,this.options.ambiguity!=="forest"&&(this._parse_tree_builder=new tn(this.rules,this.options.tree_class||wn(y),this.options.propagate_positions,this.options.parser!=="lalr"&&this.options.ambiguity==="explicit",this.options.maybe_placeholders),this._callbacks=this._parse_tree_builder.create_callback(this.options.transformer)),Je(this._callbacks,cn(this.options.transformer,this.terminals))}_deserialize_lexer_conf(t,n,r){const i=Ae.deserialize(t.lexer_conf,n);return i.callbacks=r.lexer_callbacks||{},i.re_module=r.regex?regex:Me,i.use_bytes=r.use_bytes,i.g_regex_flags=r.g_regex_flags||"",i.skip_validation=!0,i.postlex=r.postlex,i}_load({f:t,...n}={}){let r;me(t)?r=t:r=pickle.load(t);const i=r.memo,a=r.data,o=Et.deserialize(i,{Rule:D,TerminalDef:G},{}),_=Ye(a.options);return Je(_,n),this.options=mn.deserialize(_,o),this.rules=a.rules.map(c=>D.deserialize(c,o)),this.source_path="<deserialized>",ln(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(c=>[c.name,c])),this.parser=on(a.parser,o,this.lexer_conf,this._callbacks,this.options),this}static _load_from_dict({data:t,memo:n,...r}={}){return de(this)._load({f:{data:t,memo:n},...r})}repr(){return h("Lark(open(%r), parser=%r, lexer=%r, ...)",this.source_path,this.options.parser,this.options.lexer)}lex(t,n=!1){let r;!("lexer"in this)||n?r=this._build_lexer(n):r=this.lexer;const i=Oe.from_text(r,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,n=null){return this.parser.parse_interactive({unknown_param_0:t,start:n})}parse(t,n=null,r=null){return this.parser.parse(t,n,r)}}class Fe extends R{}class Ue extends Ce{constructor(){super(),this.paren_level=0,this.indent_level=[0]}*handle_NL(t){if(this.paren_level>0)return;yield t;const n=fe(t.value,`
|
|
21
|
-
`,1)[1],r=ye(n," ")+ye(n," ")*this.tab_len;if(r>b(this.indent_level))this.indent_level.push(r),yield f.new_borrow_pos(this.INDENT_type,n,t);else{for(;r<b(this.indent_level);)this.indent_level.pop(),yield f.new_borrow_pos(this.DEDENT_type,n,t);if(r!==b(this.indent_level))throw new Fe(h("Unexpected dedent to column %s. Expected dedent to %s",r,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 f(this.DEDENT_type,"")}process(t){return this.paren_level=0,this.indent_level=[0],this._process(t)}get always_accept(){return[this.NL_type]}get NL_type(){throw new NotImplementedError}get OPEN_PAREN_types(){throw new NotImplementedError}get CLOSE_PAREN_types(){throw new NotImplementedError}get INDENT_type(){throw new NotImplementedError}get DEDENT_type(){throw new NotImplementedError}get tab_len(){throw new NotImplementedError}}class fn extends Ue{static get NL_type(){return"_NEWLINE"}get NL_type(){return this.constructor.NL_type}static get OPEN_PAREN_types(){return["LPAR","LSQB","LBRACE"]}get OPEN_PAREN_types(){return this.constructor.OPEN_PAREN_types}static get CLOSE_PAREN_types(){return["RPAR","RSQB","RBRACE"]}get CLOSE_PAREN_types(){return this.constructor.CLOSE_PAREN_types}static get INDENT_type(){return"_INDENT"}get INDENT_type(){return this.constructor.INDENT_type}static get DEDENT_type(){return"_DEDENT"}get DEDENT_type(){return this.constructor.DEDENT_type}static get tab_len(){return 8}get tab_len(){return this.constructor.tab_len}}function yn(s={}){return s.transformer&&s.transformer.constructor.name==="object"&&(s.transformer=j.fromObj(s.transformer)),Qe._load_from_dict({data:On,memo:An,...s})}const Ze={},V={},Me={escape(s){return s.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")},compile(s,t){return new RegExp(s,t)},error:SyntaxError};function gn(s,t,n,r){const i=s.compile(t,r).exec(n);if(i!=null)return i[0]}class Be{constructor(t,n,r,i,a=!1){this.terminals=t,this.g_regex_flags=n,this.re_=r,this.use_bytes=i,this.match_whole=a,this.allowed_types=new Set(this.terminals.map(o=>o.name)),this._regexps=this._build_mres(t)}_build_mres(t){const n=this.match_whole?"$":"",r=Rn(t,a=>a.pattern.flags.join("")),i=[];for(const[a,o]of r){const _=o.map(c=>`(?<${c.name}>${c.pattern.to_regexp()+n})`).join("|");i.push(new RegExp(_,`${this.g_regex_flags+a}y`))}return i}match(t,n){for(const r of this._regexps){r.lastIndex=n;const i=r.exec(t);if(i){let a=null;for(const[o,_]of Object.entries(i.groups))if(_){a=o;break}return[i[0],a]}}}}const Ge=typeof require!="undefined"&&require("util"),C={};function g(s){return Object.entries(s)}function he(s){return Object.keys(s)}function xn(s,t){t===void 0&&(t=Object.keys(s)[0]);const n=s[t];return delete s[t],n}function We(s,t,n=null){return s[t]||n}function Je(s,t){if(s.constructor.name==="Map")for(const[n,r]of g(t))s.set(n,r);else for(const[n,r]of g(t))s[n]=r}function wn(s){return function(){return new s(...arguments)}}function h(s){let t=0;const n=[...arguments].slice(1);return s.replace(/%([sr])/g,function(){const r=arguments[1],i=n[t++];return r==="r"?Ge?Ge.inspect(i,!1,null,!0):JSON.stringify(i,null,0):i})}function bn(s,t){const n=new Set(s);for(const r of t)n.add(r);return n}function Ve(s,t){return[...s].filter(n=>!t.has(n))}function Ye(s){return{...s}}function Ke(s){return!!s}function de(s){return Object.create(s.prototype)}function k(s){if(typeof s=="object"){const t=Object.create(Object.getPrototypeOf(s));return Object.assign(t,s)}return s}function Y(s){return new Set(s)}function me(s){return s&&s.constructor.name==="Object"}function Tn(s){return s&&s.constructor.name==="Array"}function vn(s){return typeof s=="function"}function*Q(s,t=0){let n=t;for(const r of s)yield[n++,r]}function Nn(s){for(const t of s)if(t)return!0;return!1}function He(s,t){return t.filter(s||Ke)}function K(s){const t=[...arguments].slice(1);return function(){return s(...t,...arguments)}}function b(s){return s[s.length-1]}function I(s){return function(){const t=new s(...arguments);return t.__call__.bind(t)}}function q(s,t){return Array.from({length:t},()=>s).flat()}function Xe(s){return/^[A-Z_$]*$/.test(s)}function fe(s,t,n){const r=s.split(t);return n?r.splice(-n-1):r}function ye(s,t){const n=new RegExp(t,"g");return(s.match(n)||[]).length}function kn(s,t){for(const n of s)if(!t.has(n))return!1;return!0}function*Rn(s,t){let n=[],r=null;for(const i of s){const a=t(i);r&&a!=r&&(yield[r,n],n=[]),n.push(i),r=a}yield[r,n]}const En={Terminal:ae,NonTerminal:oe,RuleOptions:B,PatternStr:le,PatternRE:ce,TerminalDef:G};var qn={LarkError:R,ConfigurationError:E,GrammarError:Z,ParseError:Nt,LexError:L,UnexpectedInput:O,UnexpectedEOF:kt,UnexpectedCharacters:$,UnexpectedToken:P,VisitError:re,Meta:Ee,Tree:y,Discard:V,Transformer:j,Transformer_InPlace:qe,Transformer_NonRecursive:qt,Transformer_InPlaceRecursive:Ot,VisitorBase:se,Visitor:At,Visitor_Recursive:It,Interpreter:$t,Symbol:ie,Terminal:ae,NonTerminal:oe,RuleOptions:B,Rule:D,Pattern:_e,PatternStr:le,PatternRE:ce,TerminalDef:G,Token:f,Lexer:W,LexerConf:Ae,ParserConf:Ie,InteractiveParser:A,ImmutableInteractiveParser:ze,PostLex:Ce,Lark:Qe,DedentError:Fe,Indenter:Ue,PythonIndenter:fn,get_parser:yn},On={parser:{lexer_conf:{terminals:[{"@":0},{"@":1},{"@":2},{"@":3},{"@":4},{"@":5},{"@":6},{"@":7},{"@":8},{"@":9},{"@":10},{"@":11},{"@":12},{"@":13},{"@":14},{"@":15},{"@":16},{"@":17},{"@":18},{"@":19},{"@":20}],ignore:["WS"],g_regex_flags:0,use_bytes:!1,lexer_type:"contextual",__type__:"LexerConf"},parser_conf:{rules:[{"@":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},{"@":49},{"@":50},{"@":51},{"@":52},{"@":53},{"@":54},{"@":55},{"@":56}],start:["start"],parser_type:"lalr",__type__:"ParserConf"},parser:{tokens:{0:"CONJUNCTION",1:"RPAR",2:"$END",3:"STRING",4:"IDENTIFIER",5:"INT",6:"OPERATOR",7:"RSQB",8:"__ANON_0",9:"__ANON_1",10:"mc_choice_selector",11:"question_selector",12:"LSQB",13:"__ANON_6",14:"bool_expr",15:"__ANON_3",16:"qc_mc_text_ignore_case",17:"NEGATION",18:"qc_matrix_displayed",19:"bool_const",20:"qc_mc_count",21:"qc_mc_displayed",22:"condition",23:"TRUE",24:"qc_matrix_selected",25:"qc_mc_text",26:"__ANON_4",27:"qc_matrix_count",28:"FALSE",29:"qc_mc_selected",30:"__ANON_2",31:"__ANON_5",32:"matrix_statement_selector",33:"matrix_choice_selector",34:"LPAR",35:"top_level_expr",36:"DOT",37:"start"},states:{0:{0:[0,59],1:[1,{"@":25}],2:[1,{"@":25}]},1:{1:[0,69]},2:{3:[0,65]},3:{1:[1,{"@":34}],0:[1,{"@":34}],2:[1,{"@":34}]},4:{4:[0,73],5:[0,8]},5:{0:[0,46],2:[1,{"@":23}]},6:{6:[0,7]},7:{3:[0,47]},8:{7:[0,17]},9:{8:[0,83],9:[0,56]},10:{1:[1,{"@":33}],0:[1,{"@":33}],2:[1,{"@":33}]},11:{1:[1,{"@":46}],0:[1,{"@":46}],2:[1,{"@":46}]},12:{1:[1,{"@":36}],0:[1,{"@":36}],2:[1,{"@":36}]},13:{10:[0,16],4:[0,72],11:[0,35]},14:{12:[0,31]},15:{1:[1,{"@":39}],0:[1,{"@":39}],2:[1,{"@":39}]},16:{1:[0,6]},17:{1:[1,{"@":50}]},18:{13:[0,54]},19:{1:[1,{"@":27}],0:[1,{"@":27}],2:[1,{"@":27}]},20:{4:[0,72],11:[0,61]},21:{1:[1,{"@":53}]},22:{4:[0,28]},23:{1:[1,{"@":44}],0:[1,{"@":44}],2:[1,{"@":44}]},24:{2:[1,{"@":22}]},25:{1:[1,{"@":37}],0:[1,{"@":37}],2:[1,{"@":37}]},26:{1:[1,{"@":28}],0:[1,{"@":28}],2:[1,{"@":28}]},27:{6:[0,71]},28:{12:[1,{"@":52}],1:[1,{"@":52}]},29:{5:[0,45]},30:{14:[0,78],15:[0,62],16:[0,55],17:[0,9],8:[0,38],18:[0,3],19:[0,19],20:[0,50],21:[0,51],22:[0,0],23:[0,48],24:[0,10],25:[0,82],9:[0,70],26:[0,32],27:[0,68],28:[0,52],29:[0,26],30:[0,13],31:[0,20]},31:{5:[0,34],4:[0,33]},32:{11:[0,74],4:[0,72]},33:{7:[0,81]},34:{7:[0,21]},35:{12:[0,4]},36:{5:[0,18],4:[0,66]},37:{6:[0,29]},38:{4:[0,72],32:[0,14],10:[0,49],33:[0,60],11:[0,84]},39:{1:[1,{"@":47}],0:[1,{"@":47}],2:[1,{"@":47}]},40:{1:[0,75]},41:{1:[1,{"@":26}],2:[1,{"@":26}]},42:{1:[0,43]},43:{1:[1,{"@":45}],0:[1,{"@":45}],2:[1,{"@":45}]},44:{2:[1,{"@":24}]},45:{1:[1,{"@":48}],0:[1,{"@":48}],2:[1,{"@":48}]},46:{34:[0,30],35:[0,44]},47:{1:[1,{"@":40}],0:[1,{"@":40}],2:[1,{"@":40}]},48:{1:[1,{"@":55}],0:[1,{"@":55}],2:[1,{"@":55}]},49:{1:[0,25]},50:{1:[1,{"@":32}],0:[1,{"@":32}],2:[1,{"@":32}]},51:{1:[1,{"@":29}],0:[1,{"@":29}],2:[1,{"@":29}]},52:{1:[1,{"@":56}],0:[1,{"@":56}],2:[1,{"@":56}]},53:{1:[0,79]},54:{6:[0,58]},55:{1:[1,{"@":31}],0:[1,{"@":31}],2:[1,{"@":31}]},56:{11:[0,84],4:[0,72],32:[0,42],10:[0,40]},57:{},58:{5:[0,39]},59:{14:[0,41],15:[0,62],16:[0,55],17:[0,9],8:[0,38],18:[0,3],19:[0,19],20:[0,50],21:[0,51],22:[0,0],23:[0,48],24:[0,10],25:[0,82],9:[0,70],26:[0,32],27:[0,68],28:[0,52],29:[0,26],30:[0,13],31:[0,20]},60:{1:[0,23]},61:{12:[0,36]},62:{4:[0,72],10:[0,53],11:[0,35]},63:{1:[0,12]},64:{2:[1,{"@":21}]},65:{1:[1,{"@":41}],0:[1,{"@":41}],2:[1,{"@":41}]},66:{13:[0,37]},67:{1:[1,{"@":42}],0:[1,{"@":42}],2:[1,{"@":42}]},68:{1:[1,{"@":35}],0:[1,{"@":35}],2:[1,{"@":35}]},69:{1:[1,{"@":43}],0:[1,{"@":43}],2:[1,{"@":43}]},70:{11:[0,84],4:[0,72],32:[0,77],10:[0,76]},71:{5:[0,67]},72:{12:[1,{"@":49}],1:[1,{"@":49}],36:[1,{"@":49}]},73:{7:[0,85]},74:{1:[0,27]},75:{1:[1,{"@":38}],0:[1,{"@":38}],2:[1,{"@":38}]},76:{1:[0,15]},77:{1:[0,11]},78:{1:[0,5]},79:{6:[0,2]},80:{15:[0,62],34:[0,30],17:[0,9],16:[0,55],8:[0,38],18:[0,3],19:[0,19],35:[0,64],20:[0,50],21:[0,51],22:[0,0],37:[0,57],23:[0,48],24:[0,10],25:[0,82],9:[0,70],26:[0,32],14:[0,24],27:[0,68],28:[0,52],29:[0,26],30:[0,13],31:[0,20]},81:{1:[1,{"@":54}]},82:{1:[1,{"@":30}],0:[1,{"@":30}],2:[1,{"@":30}]},83:{4:[0,72],32:[0,14],10:[0,63],11:[0,84],33:[0,1]},84:{12:[0,4],36:[0,22]},85:{1:[1,{"@":51}]}},start_states:{start:80},end_states:{start:57}},__type__:"ParsingFrontend"},rules:[{"@":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},{"@":49},{"@":50},{"@":51},{"@":52},{"@":53},{"@":54},{"@":55},{"@":56}],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"},An={0:{name:"WS",pattern:{value:`(?:[ \f\r
|
|
22
|
-
])+`,flags:[],_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:[],_width:[2,4294967295],__type__:"PatternRE"},priority:0,__type__:"TerminalDef"},2:{name:"INT",pattern:{value:"-?[0-9]+",flags:[],_width:[1,4294967295],__type__:"PatternRE"},priority:0,__type__:"TerminalDef"},3:{name:"STRING",pattern:{value:`(?:'[^\\']*'|"[^"]*")`,flags:[],_width:[2,4294967295],__type__:"PatternRE"},priority:0,__type__:"TerminalDef"},4:{name:"OPERATOR",pattern:{value:"(?:regex_matches|not_contains|contains|==|!=|<=|>=|<|>)",flags:[],_width:[1,13],__type__:"PatternRE"},priority:0,__type__:"TerminalDef"},5:{name:"CONJUNCTION",pattern:{value:"(?:and|or)",flags:[],_width:[2,3],__type__:"PatternRE"},priority:0,__type__:"TerminalDef"},6:{name:"NEGATION",pattern:{value:"!",flags:[],__type__:"PatternStr"},priority:0,__type__:"TerminalDef"},7:{name:"TRUE",pattern:{value:"true",flags:[],__type__:"PatternStr"},priority:0,__type__:"TerminalDef"},8:{name:"FALSE",pattern:{value:"false",flags:[],__type__:"PatternStr"},priority:0,__type__:"TerminalDef"},9:{name:"LPAR",pattern:{value:"(",flags:[],__type__:"PatternStr"},priority:0,__type__:"TerminalDef"},10:{name:"RPAR",pattern:{value:")",flags:[],__type__:"PatternStr"},priority:0,__type__:"TerminalDef"},11:{name:"__ANON_0",pattern:{value:"selected(",flags:[],__type__:"PatternStr"},priority:0,__type__:"TerminalDef"},12:{name:"__ANON_1",pattern:{value:"displayed(",flags:[],__type__:"PatternStr"},priority:0,__type__:"TerminalDef"},13:{name:"__ANON_2",pattern:{value:"text(",flags:[],__type__:"PatternStr"},priority:0,__type__:"TerminalDef"},14:{name:"__ANON_3",pattern:{value:"text_ignore_case(",flags:[],__type__:"PatternStr"},priority:0,__type__:"TerminalDef"},15:{name:"__ANON_4",pattern:{value:"count_selected(",flags:[],__type__:"PatternStr"},priority:0,__type__:"TerminalDef"},16:{name:"__ANON_5",pattern:{value:"count_choice_selections(",flags:[],__type__:"PatternStr"},priority:0,__type__:"TerminalDef"},17:{name:"LSQB",pattern:{value:"[",flags:[],__type__:"PatternStr"},priority:0,__type__:"TerminalDef"},18:{name:"__ANON_6",pattern:{value:"])",flags:[],__type__:"PatternStr"},priority:0,__type__:"TerminalDef"},19:{name:"RSQB",pattern:{value:"]",flags:[],__type__:"PatternStr"},priority:0,__type__:"TerminalDef"},20:{name:"DOT",pattern:{value:".",flags:[],__type__:"PatternStr"},priority:0,__type__:"TerminalDef"},21:{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"},22:{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"},23:{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"},24:{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"},25:{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"},26:{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"},27:{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"},28:{origin:{name:"condition",__type__:"NonTerminal"},expansion:[{name:"qc_mc_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"},29:{origin:{name:"condition",__type__:"NonTerminal"},expansion:[{name:"qc_mc_displayed",__type__:"NonTerminal"}],order:2,alias:null,options:{keep_all_tokens:!1,expand1:!1,priority:null,template_source:null,empty_indices:[],__type__:"RuleOptions"},__type__:"Rule"},30:{origin:{name:"condition",__type__:"NonTerminal"},expansion:[{name:"qc_mc_text",__type__:"NonTerminal"}],order:3,alias:null,options:{keep_all_tokens:!1,expand1:!1,priority:null,template_source:null,empty_indices:[],__type__:"RuleOptions"},__type__:"Rule"},31:{origin:{name:"condition",__type__:"NonTerminal"},expansion:[{name:"qc_mc_text_ignore_case",__type__:"NonTerminal"}],order:4,alias:null,options:{keep_all_tokens:!1,expand1:!1,priority:null,template_source:null,empty_indices:[],__type__:"RuleOptions"},__type__:"Rule"},32:{origin:{name:"condition",__type__:"NonTerminal"},expansion:[{name:"qc_mc_count",__type__:"NonTerminal"}],order:5,alias:null,options:{keep_all_tokens:!1,expand1:!1,priority:null,template_source:null,empty_indices:[],__type__:"RuleOptions"},__type__:"Rule"},33:{origin:{name:"condition",__type__:"NonTerminal"},expansion:[{name:"qc_matrix_selected",__type__:"NonTerminal"}],order:6,alias:null,options:{keep_all_tokens:!1,expand1:!1,priority:null,template_source:null,empty_indices:[],__type__:"RuleOptions"},__type__:"Rule"},34:{origin:{name:"condition",__type__:"NonTerminal"},expansion:[{name:"qc_matrix_displayed",__type__:"NonTerminal"}],order:7,alias:null,options:{keep_all_tokens:!1,expand1:!1,priority:null,template_source:null,empty_indices:[],__type__:"RuleOptions"},__type__:"Rule"},35:{origin:{name:"condition",__type__:"NonTerminal"},expansion:[{name:"qc_matrix_count",__type__:"NonTerminal"}],order:8,alias:null,options:{keep_all_tokens:!1,expand1:!1,priority:null,template_source:null,empty_indices:[],__type__:"RuleOptions"},__type__:"Rule"},36:{origin:{name:"qc_mc_selected",__type__:"NonTerminal"},expansion:[{name:"NEGATION",filter_out:!1,__type__:"Terminal"},{name:"__ANON_0",filter_out:!0,__type__:"Terminal"},{name:"mc_choice_selector",__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"},37:{origin:{name:"qc_mc_selected",__type__:"NonTerminal"},expansion:[{name:"__ANON_0",filter_out:!0,__type__:"Terminal"},{name:"mc_choice_selector",__type__:"NonTerminal"},{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"},38:{origin:{name:"qc_mc_displayed",__type__:"NonTerminal"},expansion:[{name:"NEGATION",filter_out:!1,__type__:"Terminal"},{name:"__ANON_1",filter_out:!0,__type__:"Terminal"},{name:"mc_choice_selector",__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"},39:{origin:{name:"qc_mc_displayed",__type__:"NonTerminal"},expansion:[{name:"__ANON_1",filter_out:!0,__type__:"Terminal"},{name:"mc_choice_selector",__type__:"NonTerminal"},{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"},40:{origin:{name:"qc_mc_text",__type__:"NonTerminal"},expansion:[{name:"__ANON_2",filter_out:!0,__type__:"Terminal"},{name:"mc_choice_selector",__type__:"NonTerminal"},{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"},41:{origin:{name:"qc_mc_text_ignore_case",__type__:"NonTerminal"},expansion:[{name:"__ANON_3",filter_out:!0,__type__:"Terminal"},{name:"mc_choice_selector",__type__:"NonTerminal"},{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"},42:{origin:{name:"qc_mc_count",__type__:"NonTerminal"},expansion:[{name:"__ANON_4",filter_out:!0,__type__:"Terminal"},{name:"question_selector",__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"},43:{origin:{name:"qc_matrix_selected",__type__:"NonTerminal"},expansion:[{name:"NEGATION",filter_out:!1,__type__:"Terminal"},{name:"__ANON_0",filter_out:!0,__type__:"Terminal"},{name:"matrix_choice_selector",__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"},44:{origin:{name:"qc_matrix_selected",__type__:"NonTerminal"},expansion:[{name:"__ANON_0",filter_out:!0,__type__:"Terminal"},{name:"matrix_choice_selector",__type__:"NonTerminal"},{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"},45:{origin:{name:"qc_matrix_displayed",__type__:"NonTerminal"},expansion:[{name:"NEGATION",filter_out:!1,__type__:"Terminal"},{name:"__ANON_1",filter_out:!0,__type__:"Terminal"},{name:"matrix_statement_selector",__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:"qc_matrix_displayed",__type__:"NonTerminal"},expansion:[{name:"__ANON_1",filter_out:!0,__type__:"Terminal"},{name:"matrix_statement_selector",__type__:"NonTerminal"},{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"},47:{origin:{name:"qc_matrix_count",__type__:"NonTerminal"},expansion:[{name:"__ANON_5",filter_out:!0,__type__:"Terminal"},{name:"question_selector",__type__:"NonTerminal"},{name:"LSQB",filter_out:!0,__type__:"Terminal"},{name:"INT",filter_out:!1,__type__:"Terminal"},{name:"__ANON_6",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"},48:{origin:{name:"qc_matrix_count",__type__:"NonTerminal"},expansion:[{name:"__ANON_5",filter_out:!0,__type__:"Terminal"},{name:"question_selector",__type__:"NonTerminal"},{name:"LSQB",filter_out:!0,__type__:"Terminal"},{name:"IDENTIFIER",filter_out:!1,__type__:"Terminal"},{name:"__ANON_6",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"},49:{origin:{name:"question_selector",__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"},50:{origin:{name:"mc_choice_selector",__type__:"NonTerminal"},expansion:[{name:"question_selector",__type__:"NonTerminal"},{name:"LSQB",filter_out:!0,__type__:"Terminal"},{name:"INT",filter_out:!1,__type__:"Terminal"},{name:"RSQB",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"},51:{origin:{name:"mc_choice_selector",__type__:"NonTerminal"},expansion:[{name:"question_selector",__type__:"NonTerminal"},{name:"LSQB",filter_out:!0,__type__:"Terminal"},{name:"IDENTIFIER",filter_out:!1,__type__:"Terminal"},{name:"RSQB",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"},52:{origin:{name:"matrix_statement_selector",__type__:"NonTerminal"},expansion:[{name:"question_selector",__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"},53:{origin:{name:"matrix_choice_selector",__type__:"NonTerminal"},expansion:[{name:"matrix_statement_selector",__type__:"NonTerminal"},{name:"LSQB",filter_out:!0,__type__:"Terminal"},{name:"INT",filter_out:!1,__type__:"Terminal"},{name:"RSQB",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"},54:{origin:{name:"matrix_choice_selector",__type__:"NonTerminal"},expansion:[{name:"matrix_statement_selector",__type__:"NonTerminal"},{name:"LSQB",filter_out:!0,__type__:"Terminal"},{name:"IDENTIFIER",filter_out:!1,__type__:"Terminal"},{name:"RSQB",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"},55:{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"},56:{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"}};const et=require("assert");function tt(s){if(s.length===1)return s[0];const t=s[1].value;return t==="or"?s[0]||s[2]:t==="and"?s[0]&&s[2]:!1}function ge(s,t,n){switch(t){case"==":return s===n;case"!=":return s!==n;case"<=":return s<=n;case">=":return s>=n;case"<":return s<n;case">":return s>n;default:return!1}}function nt(s,t,n,r){const i=r?s.toLowerCase():s,a=r?n.toLowerCase():n;switch(t){case"contains":return i.includes(a);case"not_contains":return!i.includes(a);case"regex_matches":try{return new RegExp(n).test(i)}catch{return!1}default:return ge(i,t,a)}}function H(s,t){return s.length===1?t(s[0]):(et(s[0].type==="NEGATION"),!t(s[1]))}function xe(s){if(!["INT","IDENTIFIER"].includes(s.type))throw new SyntaxError(`Invalid token type: ${s.type}; expected IDENTIFIER or INT`);return T(s)}function T(s){var t,n;switch(s.type){case"IDENTIFIER":return s.value;case"INT":return parseInt(s.value,10);case"STRING":{const r=s.value.match(/(?:'(?<single>[^\']*)')|(?:"(?<double>[^\"]*)")/),i=((t=r==null?void 0:r.groups)==null?void 0:t.double)||((n=r==null?void 0:r.groups)==null?void 0:n.single);return et(i),i}case"OPERATOR":return s.value;case"TRUE":return!0;case"FALSE":return!1;default:throw new SyntaxError(`Invalid token type: ${s.type}`)}}function In(s,t){const n={start:r=>r[0],top_level_expr:tt,bool_expr:tt,condition:r=>r[0],qc_mc_selected:r=>H(r,t.isSelected),qc_mc_displayed:r=>H(r,t.isDisplayed),qc_mc_text:r=>nt(t.textEntry(r[0]),T(r[1]),T(r[2]),!1),qc_mc_text_ignore_case:r=>nt(t.textEntry(r[0]),T(r[1]),T(r[2]),!0),qc_mc_count:r=>ge(t.countSelected(r[0]),T(r[1]),T(r[2])),qc_matrix_selected:r=>H(r,t.isSelected),qc_matrix_displayed:r=>H(r,t.isDisplayed),qc_matrix_count:r=>ge(t.countChoiceSelections(r[0],xe(r[1])),T(r[2]),T(r[3])),question_selector:r=>r[0].value,mc_choice_selector:r=>({questionId:r[0],choice:xe(r[1])}),matrix_statement_selector:r=>({questionId:r[0],statementId:T(r[1])}),matrix_choice_selector:r=>({...r[0],choice:xe(r[1])}),bool_const:r=>r[0].value==="true"};return qn.get_parser({transformer:n}).parse(s)}const $n=/\$\{m:([^\}]+)\}/g,Pn=100,rt=(s,t)=>{if(typeof t=="string"){let n=t,r=0;for(;r<Pn;){const i=n.replace($n,(a,o)=>{if(s[o]===void 0)throw new Error(`Undefined macro: ${o}`);return s[o]});if(i===n)return i;n=i,r+=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]=rt(s,t[n])}),t},Sn=s=>{s.sections=rt(s.macros||{},s.sections)};var zn=Object.defineProperty,Dn=(s,t,n)=>t in s?zn(s,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):s[t]=n,S=(s,t,n)=>(Dn(s,typeof t!="symbol"?t+"":t,n),n);const st=new ct({allowUnionTypes:!0});pt(st);const it=st.compile(Ne);class F extends Error{}class at extends Error{}class z extends Error{}class Ln extends Error{}class jn{constructor(){S(this,"seenQuestions",new Set),S(this,"seenQuestionStatements",new Map),S(this,"seenQuestionChoices",new Map),S(this,"seenTextChoices",new Map),S(this,"validateReference",t=>{var n,r,i;if(!this.seenQuestions.has(t.questionId))throw new F(`Invalid question: ${t.questionId}`);if(t.statementId!==void 0&&!((n=this.seenQuestionStatements.get(t.questionId))!=null&&n.has(t.statementId)))throw new F(`Invalid statement: ${t.questionId}.${t.statementId}`);if(t.choice!==void 0&&!((r=this.seenQuestionChoices.get(t.questionId))!=null&&r.has(t.choice)))throw new F(`Invalid choice: ${t.questionId}[${t.choice}]`);if(t.choice!==void 0&&t.expectText===!0&&!((i=this.seenTextChoices.get(t.questionId))!=null&&i.has(t.choice)))throw new F(`Invalid text reference: ${t.questionId}[${t.choice}]`)}),S(this,"evaluator",{isSelected:t=>(this.validateReference(t),!1),isDisplayed:t=>(this.validateReference(t),!1),countSelected:t=>(this.validateReference({questionId:t}),0),countChoiceSelections:(t,n)=>(this.validateReference({questionId:t,choice:n}),0),textEntry:t=>(this.validateReference({...t,expectText:!0}),"")})}}const U=(s,t,n)=>{if(n)try{In(n,s.evaluator)}catch(r){throw r instanceof F||r instanceof z?r:new Error(`Syntax error parsing display logic at ${t}: ${n}`)}},ot=(s,t)=>{var n,r,i,a,o,_;U(t,s.id,s.display_logic),U(t,s.id,s.display_logic_in_page),(n=s.statements)==null||n.forEach(p=>{U(t,`${s.id}.${p.id}`,p.display_logic)}),(r=s.choices)==null||r.forEach(p=>{U(t,`${s.id}[${p.id||p.value}]`,p.display_logic)});const c=p=>{const[u,m]=p.split("/",2);return{questionId:u,expression:m}},l=p=>{const u=(p.expression.startsWith("for_matrix_choice")||p.expression.startsWith("unselected_for_matrix_choice")?t.seenQuestionStatements:t.seenQuestionChoices).get(p.questionId);if(u===void 0)throw new at(`Invalid question referenced in locator expression: ${p.questionId}/${p.expression}`);return u};if(s.id!==void 0){if(t.seenQuestions.has(s.id))throw new z(`Duplicate question id: ${s.id}`);if(t.seenQuestions.add(s.id),s.statements||s.dynamic_statements){const u=new Set;if(t.seenQuestionStatements.set(s.id,u),(i=s.statements)==null||i.forEach(m=>{if(u.has(m.id))throw new z(`Duplicate statement id: ${s.id}.${m.id}`);u.add(m.id)}),s.dynamic_statements){const m=c(s.dynamic_statements);l(m).forEach(d=>{if(typeof d=="number")throw new at(`Dynamic statement in question ${s.id} refers to choices with values`);if(u.has(d))throw new z(`Duplicate statement ${d} via dynamic statements in question ${s.id}`);u.add(d)})}}const p=(a=s.choices)!=null?a:[];if((o=s.choice_groups)==null||o.forEach(u=>p.push(...u.choices)),p||s.dynamic_choices){const u=new Set;t.seenQuestionChoices.set(s.id,u);const m=new Set;if(t.seenTextChoices.set(s.id,m),p.forEach(d=>{var x;const v=(x=d.id)!=null?x:d.value;if(u.has(v))throw new z(`Duplicate choice: ${s.id}[${v}]`);u.add(v),d.text&&d.text!=="no"&&m.add(v)}),s.dynamic_choices){const d=c(s.dynamic_choices);l(d).forEach(x=>{if(u.has(x))throw new z(`Duplicate choice ${x} via dynamic choices in ${s.id}`);u.add(x)}),(_=t.seenTextChoices.get(d.questionId))==null||_.forEach(x=>m.add(x))}if(new Set([...u].map(d=>typeof d)).size>=2)throw new Ln("All choices in a question must either all have id's or all have values")}}},Cn=s=>{if(!it(s))throw new Error(`Invalid template: ${s.template.id}. Reason: ${JSON.stringify(it.errors,null,4)}`);Sn(s);const t=new jn;s.sections.forEach(n=>{var r,i;U(t,n.id,n.display_logic),(r=n.questions)==null||r.forEach(a=>{ot(a,t)}),(i=n.pages)==null||i.forEach(a=>{var o;(o=a.questions)==null||o.forEach(_=>{ot(_,t)})})})},Qn=Ne,Fn="pulse_default_alpha",Un={allPermissions:ht,SURVEY_RESOURCE_TYPE:ut,surveyAdministerPermission:ve};export{Fn as DEFAULT_TEMPLATE_ID,Un as permissions,Qn as templateSchema,Cn as validateTemplate};
|
|
14
|
+
%s`,t,r);super(i),this.rule=t,this.obj=n,this.orig_exc=r}}function qt(s,t=null,n=null){let r,i;const a=new Map;for(const o of s)r=t!==null?t(o):o,i=n!==null?n(o):o,a.has(r)?a.get(r).push(i):a.set(r,[i]);return a}function M(s,t,n){let r;return me(s)?"__type__"in s?(r=t[s.__type__],r.deserialize(s,n)):"@"in s?n[s["@"]]:Object.fromEntries(g(s).map(([i,a])=>[i,M(a,t,n)])):Nn(s)?s.map(i=>M(i,t,n)):s}class x{static deserialize(t,n){const r=this,i=r&&r.__serialize_fields__;if("@"in t)return n[t["@"]];const a=de(r);for(const o of i)if(t&&o in t)a[o]=M(t[o],On,n);else throw new KeyError("Cannot find key for class",r,e);return"_deserialize"in a&&a._deserialize(),a}}class Ot extends x{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,r){return M(t,n,r)}}class qe{constructor(){this.empty=!0}}class y{constructor(t,n,r=null){this.data=t,this.children=n,this._meta=r}get meta(){return this._meta===null&&(this._meta=new qe),this._meta}repr(){return u("Tree(%r, %r)",this.data,this.children)}_pretty_label(){return this.data}_pretty(t,n){if(this.children.length===1&&!(this.children[0]instanceof y))return[E(n,t).join(""),this._pretty_label()," ",u("%s",this.children[0].value),`
|
|
15
|
+
`];const r=[E(n,t).join(""),this._pretty_label(),`
|
|
16
|
+
`];for(const i of this.children)i instanceof y?r.push(...i._pretty(t+1,n)):r.push(E(n,t+1).join(""),u("%s",i.value),`
|
|
17
|
+
`);return r}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];const n=new Map;for(const r of t)n.set(r,r),t.push(...[...r.children].reverse().filter(i=>i instanceof y&&!n.has(i)).map(i=>i));return t=void 0,[...n.values()].reverse()}find_pred(t){return Xe(t,this.iter_subtrees())}find_data(t){return this.find_pred(n=>n.data===t)}*scan_values(t){for(const n of this.children)if(n instanceof y)for(const r of n.scan_values(t))yield r;else t(n)&&(yield n)}*iter_subtrees_topdown(){let t;const n=[this];for(;n.length;)if(t=n.pop(),t instanceof y){yield t;for(const r of[...t.children].reverse())n.push(r)}}copy(){return type(this)(this.data,this.children)}set(t,n){this.data=t,this.children=n}}class L extends Ee{static get __visit_tokens__(){return!0}constructor(t=!0){super(),this.__visit_tokens__=t}static fromObj(t,...n){class r extends this{}for(const[i,a]of Object.entries(t))r.prototype[i]=a;return new r(...n)}_call_userfunc(t,n=null){let r,i;const a=n!==null?n:t.children;if(t&&t.data&&this&&this[t.data]){r=this&&this[t.data];try{return i=r&&r.visit_wrapper||null,i!==null?r.visit_wrapper(r,t.data,a,t.meta):r(a)}catch(o){throw o instanceof Z?o:o instanceof Error?new re(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(r){throw r instanceof Z?r:r instanceof Error?new re(t.type,t,r):r}}else return this.__default_token__(t)}*_transform_children(t){let n;for(const r of t)r instanceof y?n=this._transform_tree(r):this.__visit_tokens__&&r instanceof f?n=this._call_userfunc_token(r):n=r,n!==V&&(yield n)}_transform_tree(t){const n=[...this._transform_children(t.children)];return this._call_userfunc(t,n)}transform(t){return this._transform_tree(t)}__default__(t,n,r){return new y(t,n,r)}__default_token__(t){return t}}class Oe extends L{_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 At extends L{transform(t){let n,r,i;const a=[],o=[t];for(;o.length;){const l=o.pop();a.push(l),l instanceof y&&o.push(...l.children)}const _=[];for(const l of[...a].reverse())l instanceof y?(i=l.children.length,i?(n=_.slice(-i),_.splice(-i)):n=[],r=this._call_userfunc(l,n),r!==V&&_.push(r)):this.__visit_tokens__&&l instanceof f?(r=this._call_userfunc_token(l),r!==V&&_.push(r)):_.push(l);const[c]=_;return c}}class It extends L{_transform_tree(t){return t.children=[...this._transform_children(t.children)],this._call_userfunc(t)}}class se{_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 $t extends se{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 Pt extends se{visit(t){for(const n of t.children)n instanceof y&&this.visit(n);return this._call_userfunc(t),t}visit_topdown(t){this._call_userfunc(t);for(const n of t.children)n instanceof y&&this.visit_topdown(n);return t}}class St extends Ee{visit(t){return t.data in this?this[t.data](t):this.__default__(t)}visit_children(t){return t.children.map(n=>n instanceof y?this.visit(n):n)}__default__(t){return this.visit_children(t)}}const zt=0;class ie extends x{constructor(t){super(),v(this,"is_term",j),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 ae extends ie{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 u("%s(%r, %r)",type(this).name,this.name,this.filter_out)}renamed(t){return type(this)(t(this.name),this.filter_out)}}class oe extends ie{static get __serialize_fields__(){return["name"]}get is_term(){return!1}}class B extends x{static get __serialize_fields__(){return["keep_all_tokens","expand1","priority","template_source","empty_indices"]}constructor(t=!1,n=!1,r=null,i=null,a=[]){super(),this.keep_all_tokens=t,this.expand1=n,this.priority=r,this.template_source=i,this.empty_indices=a}repr(){return u("RuleOptions(%r, %r, %r, %r)",this.keep_all_tokens,this.expand1,this.priority,this.template_source)}}class z extends x{static get __serialize_fields__(){return["origin","expansion","order","alias","options"]}static get __serialize_namespace__(){return[ae,oe,B]}constructor(t,n,r=0,i=null,a=null){super(),this.origin=t,this.expansion=n,this.alias=i,this.order=r,this.options=a||new B,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 z?this.origin===t.origin&&this.expansion===t.expansion:!1}}class _e extends x{constructor(t,n=[],r=null){super(),this.value=t,this.flags=Y(n),this.raw=r}repr(){return repr(this.to_regexp())}eq(t){return type(this)===type(t)&&this.value===t.value&&this.flags===t.flags}to_regexp(){throw new NotImplementedError}get min_width(){throw new NotImplementedError}get max_width(){throw new NotImplementedError}_get_flags(t){return t}}class le extends _e{static get __serialize_fields__(){return["value","flags"]}static get type(){return"str"}to_regexp(){return this._get_flags(Be.escape(this.value))}get min_width(){return this.value.length}get max_width(){return this.value.length}}class ce extends _e{static get __serialize_fields__(){return["value","flags","_width"]}static get type(){return"re"}to_regexp(){return this._get_flags(this.value)}_get_width(){return this._width===null&&(this._width=get_regexp_width(this.to_regexp())),this._width}get min_width(){return this._get_width()[0]}get max_width(){return this._get_width()[1]}}class G extends x{static get __serialize_fields__(){return["name","pattern","priority"]}static get __serialize_namespace__(){return[le,ce]}constructor(t,n,r=zt){super(),this.name=t,this.pattern=n,this.priority=r}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 f{constructor(t,n,r=null,i=null,a=null,o=null,_=null,c=null){v(this,"value"),v(this,"type"),this.type=t,this.start_pos=r,this.value=n,this.line=i,this.column=a,this.end_line=o,this.end_column=_,this.end_pos=c}update(t=null,n=null){return f.new_borrow_pos(t!==null?t:this.type,n!==null?n:this.value,this)}static new_borrow_pos(t,n,r){const i=this;return new i(t,n,r.start_pos,r.line,r.column,r.end_line,r.end_column,r.end_pos)}repr(){return u("Token(%r, %r)",this.type,this.value)}eq(t){return t instanceof f&&this.type!==t.type?!1:str.__eq__(this,t)}static get __hash__(){return str.__hash__}}class be{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 be?this.char_pos===t.char_pos&&this.newline_char===t.newline_char:j}feed(t,n=!0){let r;n&&(r=ye(t,this.newline_char),r&&(this.line+=r,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 Dt{constructor(t){this.scanner=t}__call__(t){let n;const r=this.scanner.match(t.value,0);return r&&([n,t.type]=r),t}}const Lt=A(Dt);class jt{constructor(t,n,r){this.callback1=t,this.callback2=n,this.cond=r}__call__(t){const n=this.callback1(t);return this.cond(n)?this.callback2(t):n}}const Ct=A(jt);function Ft(s,t,n,r){let i,a;const o=qt(s,l=>l.pattern.constructor.type),_=new Set,c={};for(const l of o.get("re")||[]){a=[];for(const p of o.get("str")||[])p.priority===l.priority&&(i=p.pattern.value,i===wn(n,l.pattern.to_regexp(),i,t)&&(a.push(p),En(new Set(p.pattern.flags),new Set(l.pattern.flags))&&_.add(p)));a.length&&(c[l.name]=new Lt(new Ge(a,t,n,r,!0)))}return[s.filter(l=>!_.has(l)).map(l=>l),c]}function Qt(s){return s.includes(`
|
|
18
|
+
`)||s.includes("\\n")||s.includes("\\s")||s.includes("[^")||s.includes("(?s")&&s.includes(".")}class Te{constructor(t,n=null,r=null){this.text=t,this.line_ctr=n||new be(`
|
|
19
|
+
`),this.last_token=r}eq(t){return t instanceof Te?this.text===t.text&&this.line_ctr===t.line_ctr&&this.last_token===t.last_token:j}}class Ae{constructor(t,n){this.lexer=t,this.state=n}static from_text(t,n){return new this(t,new Te(n))}lex(t){return this.lexer.lex(this.state,t)}}class W extends Re{lex(t,n){return j}}function Ut(s,t){s.sort((n,r)=>{const i=t(n),a=t(r);for(let o=0;o<i.length;o++){if(i[o]>a[o])return 1;if(i[o]<a[o])return-1}return 0})}class J extends W{constructor(t){super();const n=[...t.terminals];if(this.re=t.re_module,!t.skip_validation){for(const r of n){try{this.re.compile(r.pattern.to_regexp(),t.g_regex_flags)}catch(i){throw i instanceof this.re.error?new D(u("Cannot compile token %s: %s",r.name,r.pattern)):i}if(r.pattern.min_width===0)throw new D(u("Lexer does not allow zero-width terminals. (%s: %s)",r.name,r.pattern))}if(!(new Set(t.ignore)<=new Set(n.map(r=>r.name))))throw new D(u("Ignore terminals are not defined: %s",Ye(new Set(t.ignore),new Set(n.map(r=>r.name)))))}this.newline_types=Y(n.filter(r=>Qt(r.pattern.to_regexp())).map(r=>r.name)),this.ignore_types=Y(t.ignore),Ut(n,r=>[-r.priority,-r.pattern.max_width,-r.pattern.value.length,r.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]=Ft(this.terminals,this.g_regex_flags,this.re,this.use_bytes);for(const[n,r]of g(this.user_callbacks))n in this.callback?this.callback[n]=new Ct(this.callback[n],r,i=>i.type===n):this.callback[n]=r;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,n){return this.scanner.match(t,n)}*lex(t,n){try{for(;;)yield this.next_token(t,n)}catch(r){if(!(r instanceof te))throw r}}next_token(t,n=null){let r,i,a,o;const _=t.line_ctr;for(;_.char_pos<t.text.length;){if(i=this.match(t.text,_.char_pos),!i)throw r=Ye(this.scanner.allowed_types,this.ignore_types),r||(r=new Set(["<END-OF-FILE>"])),new $({seq:t.text,lex_pos:_.char_pos,line:_.line,column:_.column,allowed:r,token_history:t.last_token&&[t.last_token],state:n,terminals_by_name:this.terminals_by_name});const[c,l]=i;if(!this.ignore_types.has(l)){if(a=new f(l,c,_.char_pos,_.line,_.column),_.feed(c,this.newline_types.has(l)),a.end_line=_.line,a.end_column=_.column,a.end_pos=_.char_pos,a.type in this.callback&&(a=this.callback[a.type](a),!(a instanceof f)))throw new D(u("Callbacks must return a token (returned %r)",a));return t.last_token=a,a}l in this.callback&&(o=new f(l,c,_.char_pos,_.line,_.column),this.callback[l](o)),_.feed(c,this.newline_types.has(l))}throw new te(this)}}class Zt extends W{constructor({conf:t,states:n,always_accept:r=[]}={}){super();let i,a,o;const _=[...t.terminals],c=t.terminals_by_name,l=N(t);l.terminals=_;const p=new Map;this.lexers={};for(let[h,d]of g(n))i=Y(d),p.has(i)?a=p.get(i):(d=vn(new Set(d),[...new Set(t.ignore),...new Set(r)]),o=N(l),o.terminals=[...d].filter(m=>m in c).map(m=>c[m]),a=new J(o),p.set(i,a)),this.lexers[h]=a;this.root_lexer=new J(l)}*lex(t,n){let r,i,a;try{for(;;)i=this.lexers[n.position],yield i.next_token(t,n)}catch(o){if(!(o instanceof te))if(o instanceof $)try{throw r=t.last_token,a=this.root_lexer.next_token(t,n),new P({token:a,expected:o.allowed,state:n,token_history:[r],terminals_by_name:this.root_lexer.terminals_by_name})}catch(_){throw _}else throw o}}}class Ie extends x{static get __serialize_fields__(){return["terminals","ignore","g_regex_flags","use_bytes","lexer_type"]}static get __serialize_namespace__(){return[G]}constructor({terminals:t,re_module:n,ignore:r=[],postlex:i=null,callbacks:a=null,g_regex_flags:o="",skip_validation:_=!1,use_bytes:c=!1}={}){super(),this.terminals=t,this.terminals_by_name=Object.fromEntries(this.terminals.map(l=>[l.name,l])),this.ignore=r,this.postlex=i,this.callbacks=Object.keys(a).length||{},this.g_regex_flags=o,this.re_module=n,this.skip_validation=_,this.use_bytes=c,this.lexer_type=null}_deserialize(){this.terminals_by_name=Object.fromEntries(this.terminals.map(t=>[t.name,t]))}}class $e extends x{static get __serialize_fields__(){return["rules","start","parser_type"]}constructor(t,n,r){super(),this.rules=t,this.callbacks=n,this.start=r,this.parser_type=null}}class Mt{constructor(t){this.node_builder=t}__call__(t){return t.length===1?t[0]:this.node_builder(t)}}const Bt=A(Mt);class Gt{constructor(t,n=null){this.node_builder=t,this.node_filter=n}__call__(t){let n,r,i;const a=this.node_builder(t);return a instanceof y&&(i=a.meta,n=this._pp_get_meta(t),n!==null&&("line"in i||(i.line=n&&n.container_line||n.line,i.column=n&&n.container_column||n.column,i.start_pos=n&&n.container_start_pos||n.start_pos,i.empty=!1),i.container_line=n&&n.container_line||n.line,i.container_column=n&&n.container_column||n.column),r=this._pp_get_meta([...t].reverse()),r!==null&&("end_line"in i||(i.end_line=r&&r.container_end_line||r.end_line,i.end_column=r&&r.container_end_column||r.end_column,i.end_pos=r&&r.container_end_pos||r.end_pos,i.empty=!1),i.container_end_line=r&&r.container_end_line||r.end_line,i.container_end_column=r&&r.container_end_column||r.end_column)),a}_pp_get_meta(t){for(const n of t)if(!(this.node_filter!==null&&!this.node_filter(n))){if(n instanceof y){if(!n.meta.empty)return n.meta}else if(n instanceof f)return n}}}const Pe=A(Gt);function Wt(s){if(kn(s))return K({unknown_param_0:Pe,node_filter:s});if(s===!0)return Pe;if(s===!1)return null;throw new R(u("Invalid option for propagate_positions: %r",s))}class pe{constructor(t,n,r){this.node_builder=r,this.to_include=t,this.append_none=n}__call__(t){const n=[];for(const[r,i,a]of this.to_include)a&&n.push(...E([null],a)),i?n.push(...t[r].children):n.push(t[r]);return this.append_none&&n.push(...E([null],this.append_none)),this.node_builder(n)}}const Jt=A(pe);class Vt extends pe{__call__(t){let n=[];for(const[r,i,a]of this.to_include)a&&n.push(...E([null],a)),i?n.length?n.push(...t[r].children):n=t[r].children:n.push(t[r]);return this.append_none&&n.push(...E([null],this.append_none)),this.node_builder(n)}}const Yt=A(Vt);class Kt extends pe{constructor(t,n){super(),this.node_builder=n,this.to_include=t}__call__(t){let n=[];for(const[r,i]of this.to_include)i?n.length?n.push(...t[r].children):n=t[r].children:n.push(t[r]);return this.node_builder(n)}}const Ht=A(Kt);function Xt(s){return!s.is_term&&s.name.startsWith("_")}function en(s,t,n,r){let i,a;r.length?(a=r.map(c=>(0+c).toString()).join(""),i=a.split("0").map(c=>c.length)):i=E([0],s.length+1);const o=[];let _=0;for(const[c,l]of C(s))_+=i[c],(t||!(l.is_term&&l.filter_out))&&(o.push([c,Xt(l),_]),_=0);if(_+=i[s.length],r.length||o.length<s.length||Rn(o.map(([c,l,p])=>l)))return(r.length||n).length?K(n?Jt:Yt,o,_):K(Ht,o.map(([c,l,p])=>[c,l]))}function tn(s){function t(n){const r=new y(s.name,n);return s(r)}return t=wraps(s)(t),t}function nn(s,t,n){if(n===_vargs_meta||n===_vargs_meta_inline)throw new NotImplementedError("Meta args not supported for internal transformer");function r(i){return n(s,t,i,null)}return r=wraps(s)(r),r}class rn{constructor(t,n,r=!1,i=!1,a=!1){this.tree_class=n,this.propagate_positions=r,this.ambiguous=i,this.maybe_placeholders=a,this.rule_builders=[...this._init_builders(t)]}*_init_builders(t){let n,r,i,a;const o=Wt(this.propagate_positions);for(const _ of t)i=_.options,r=i.keep_all_tokens,n=i.expand1,a=[...Xe(null,[n&&!_.alias&&Bt,en(_.expansion,r,this.ambiguous,this.maybe_placeholders?i.empty_indices:[]),o])],yield[_,a]}create_callback(t=null){let n,r,i;const a=new Map;for(const[o,_]of this.rule_builders){r=o.alias||o.options.template_source||o.origin.name,t&&t[r]?(n=t&&t[r],i=n&&n.visit_wrapper||null,i!==null?n=nn(n,r,i):t instanceof Oe&&(n=tn(n))):n=K(this.tree_class,r);for(const c of _)n=c(n);if(a.has(o))throw new Z(u("Rule '%s' already exists",o));a.set(o,n)}return a}}class Se extends x{constructor({parser_conf:t,debug:n=!1}={}){super();const r=new LALR_Analyzer({unknown_param_0:t,debug:n});r.compute_lalr();const i=t.callbacks;this._parse_table=r.parse_table,this.parser_conf=t,this.parser=new ze(r.parse_table,i,n)}static deserialize(t,n,r,i=!1){const a=de(this);return a._parse_table=on.deserialize(t,n),a.parser=new ze(a._parse_table,r,i),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:r=null}={}){let i,a;try{return this.parser.parse({lexer:t,start:n})}catch(o){if(o instanceof q){if(r===null)throw o;for(;;){if(o instanceof $&&(a=o.interactive_parser.lexer_thread.state,i=a.line_ctr.char_pos),!r(o))throw o;o instanceof $&&i===a.line_ctr.char_pos&&a.line_ctr.feed(a.text.slice(i,i+1));try{return o.interactive_parser.resume_parse()}catch(_){if(_ instanceof P){if(o instanceof P&&o.token.type===_.token.type&&_.token.type==="$END"&&o.interactive_parser.eq(_.interactive_parser))throw _;o=_}else if(_ instanceof $)o=_;else throw _}}}else throw o}}}class sn{constructor(t,n,r){this.parse_table=t,this.start_state=this.parse_table.start_states[r],this.end_state=this.parse_table.end_states[r],this.states=this.parse_table.states,this.callbacks=n,this.start=r}}class ve{constructor(t,n,r=null,i=null){this.parse_conf=t,this.lexer=n,this.state_stack=r||[this.parse_conf.start_state],this.value_stack=i||[]}get position(){return w(this.state_stack)}eq(t){return t instanceof ve?this.state_stack.length===t.state_stack.length&&this.position===t.position:j}copy(){return N(this)}feed_token(t,n=!1){let r,i,a,o,_,c,l,p,h,d;const m=this.state_stack,b=this.value_stack,U=this.parse_conf.states,ct=this.parse_conf.end_state,X=this.parse_conf.callbacks;for(;;){if(h=w(m),t.type in U[h])[i,a]=U[h][t.type];else throw o=new Set(he(U[h]).filter(ee=>et(ee)).map(ee=>ee)),new P({token:t,expected:o,state:this,interactive_parser:null});if(i===ue){m.push(a),b.push(t.type in X?X[t.type](t):t);return}if(c=a,p=c.expansion.length,p?(l=b.slice(-p),m.splice(-p),b.splice(-p)):l=[],d=X.get(c)(l),[r,_]=U[w(m)][c.origin.name],m.push(_),b.push(d),n&&w(m)===ct)return w(b)}}}class ze{constructor(t,n,r=!1){this.parse_table=t,this.callbacks=n,this.debug=r}parse({lexer:t,start:n,value_stack:r=null,state_stack:i=null,start_interactive:a=!1}={}){const o=new sn(this.parse_table,this.callbacks,n),_=new ve(o,t,i,r);return a?new O(this,_,_.lexer):this.parse_from_state(_)}parse_from_state(t){let n,r;try{r=null;for(r of t.lexer.lex(t))t.feed_token(r);return n=r?f.new_borrow_pos("$END","",r):new f("$END","",0,1,1),t.feed_token(n,!0)}catch(i){if(i instanceof q){try{i.interactive_parser=new O(this,t,t.lexer)}catch(a){if(!(a instanceof ReferenceError))throw a}throw i}else if(i instanceof Error){if(this.debug){console.log(""),console.log("STATE STACK DUMP"),console.log("----------------");for(const[a,o]of C(t.state_stack))console.log(u("%d)",a),o);console.log("")}throw i}else throw i}}}class O{constructor(t,n,r){this.parser=t,this.parser_state=n,this.lexer_thread=r,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){const n=t!==null?f.new_borrow_pos("$END","",t):new f("$END","",0,1,1);return this.feed_token(n)}copy(){return N(this)}eq(t){return t instanceof O?this.parser_state===t.parser_state&&this.lexer_thread===t.lexer_thread:!1}as_immutable(){const t=N(this);return new De(t.parser,t.parser_state,t.lexer_thread)}pretty(){const t=["Parser choices:"];for(const[n,r]of g(this.choices()))t.push(u(" - %s -> %r",n,r));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;const n=new Set;for(const r of this.choices())if(et(r)){t=N(this);let i=null;try{t.feed_token(new f(r,""))}catch(a){if(i=a,!(a instanceof P))throw a}i||n.add(r)}return n}resume_parse(){return this.parser.parse_from_state(this.parser_state)}}class De extends O{constructor(){super(...arguments),v(this,"result",null)}feed_token(t){const n=N(this);return n.result=O.feed_token(n,t),n}exhaust_lexer(){const t=this.as_mutable();return t.exhaust_lexer(),t.as_immutable()}as_mutable(){const t=N(this);return new O(t.parser,t.parser_state,t.lexer_thread)}}class Le{constructor(t){this.name=t}repr(){return this.toString()}}var ue=new Le("Shift");const je=new Le("Reduce");class an{constructor(t,n,r){this.states=t,this.start_states=n,this.end_states=r}serialize(t){const n=new Enumerator,r=Object.fromEntries(g(this.states).map(([i,a])=>[i,Object.fromEntries(g(a).map(([o,[_,c]])=>[Je(n,o),_===je?[1,c.serialize(t)]:[0,c]]))]));return{tokens:n.reversed(),states:r,start_states:this.start_states,end_states:this.end_states}}static deserialize(t,n){const r=this,i=t.tokens,a=Object.fromEntries(g(t.states).map(([o,_])=>[o,Object.fromEntries(g(_).map(([c,[l,p]])=>[i[c],l===1?[je,z.deserialize(p,n)]:[ue,p]]))]));return new r(a,t.start_states,t.end_states)}}class on extends an{static from_ParseTable(t){const n=this,r=[...t.states],i=Object.fromEntries(C(r).map(([c,l])=>[l,c])),a={};for(let[c,l]of g(t.states))l=Object.fromEntries(g(l).map(([p,h])=>[p,h[0]===ue?[h[0],i[h[1]]]:h])),a[i[c]]=l;const o=Object.fromEntries(g(t.start_states).map(([c,l])=>[c,i[l]])),_=Object.fromEntries(g(t.end_states).map(([c,l])=>[c,i[l]]));return new n(a,o,_)}}function _n(s){if(s&&s.__future_interface__)return s;class t extends W{constructor(r){super(),this.lexer=s(r)}lex(r,i){return this.lexer.lex(r.text)}}return t}function ln(s,t,n,r,i){const a=$e.deserialize(s.parser_conf,t),o=Se.deserialize(s.parser,t,r,i.debug);return a.callbacks=r,new cn({lexer_conf:n,parser_conf:a,options:i,parser:o})}const Ce={};class cn extends x{static get __serialize_fields__(){return["lexer_conf","parser_conf","parser"]}constructor({lexer_conf:t,parser_conf:n,options:r,parser:i=null}={}){super();let a,o;this.parser_conf=n,this.lexer_conf=t,this.options=r,i?this.parser=i:(o=Je(Ce,n.parser_type),this.parser=o(t,n,r));const _=t.lexer_type;if(this.skip_lexer=!1,["dynamic","dynamic_complete"].includes(_)){this.skip_lexer=!0;return}const c={basic:dn,contextual:mn};_ in c?(a=c[_],this.lexer=a(t,this.parser,t.postlex,r)):this.lexer=_n(_)(t),t.postlex&&(this.lexer=new hn(this.lexer,t.postlex))}_verify_start(t=null){let n;if(t===null){if(n=this.parser_conf.start,n.length>1)throw new R("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 R(u("Unknown start rule %s. Must be one of %r",t,this.parser_conf.start));return t}_make_lexer_thread(t){return this.skip_lexer?t:Ae.from_text(this.lexer,t)}parse(t,n=null,r=null){const i=this._verify_start(n),a=r===null?{}:{on_error:r},o=this._make_lexer_thread(t);return this.parser.parse({lexer:o,start:i,...a})}parse_interactive(t=null,n=null){const r=this._verify_start(n);if(this.parser_conf.parser_type!=="lalr")throw new R("parse_interactive() currently only works with parser='lalr' ");const i=this._make_lexer_thread(t);return this.parser.parse_interactive(i,r)}}function pn(s,t){let n;ne(s,["lalr","earley","cyk"]),typeof t!="object"&&(n={lalr:["basic","contextual"],earley:["basic","dynamic","dynamic_complete"],cyk:["basic"]}[s],ne(t,n,u("Parser %r does not support lexer %%r, expected one of %%s",s)))}function un(s,t){let n;const r={};for(const i of t)n=s&&s[i.name]||null,n!==null&&(r[i.name]=n);return r}class hn{constructor(t,n){this.lexer=t,this.postlexer=n}lex(t,n){const r=this.lexer.lex(t,n);return this.postlexer.process(r)}}function dn(s,t,n,r){return new J(s)}function mn(s,t,n,r){const i=Object.fromEntries(g(t._parse_table.states).map(([o,_])=>[o,[...he(_)]])),a=n?n.always_accept:[];return new Zt({conf:s,states:i,always_accept:a})}function fn(s,t,n=null){const r=n?n.debug:!1;return new Se({parser_conf:t,debug:r})}Ce.lalr=fn;class Fe extends Re{constructor(){super(...arguments),v(this,"always_accept",[])}process(t){return t}}class yn extends x{constructor(t){super(),v(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 '),v(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;const r=Ke(t),i=this;for(const[a,o]of g(this._defaults))a in r?(n=bn(r,a),typeof o=="boolean"&&!["cache","use_bytes","propagate_positions"].includes(a)&&(n=He(n))):n=o,i[a]=n;if(typeof i.start=="string"&&(i.start=[i.start]),this.options=i,ne(this.parser,["earley","lalr","cyk",null]),this.parser==="earley"&&this.transformer)throw new R("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(r).length)throw new R(u("Unknown options: %s",he(r)))}serialize(t){return this.options}static deserialize(t,n){const r=this;return new r(t)}}class Qe extends x{static get __serialize_fields__(){return["parser","rules","options"]}_build_lexer(t=!1){let n=this.lexer_conf;return t&&(n=N(n),n.ignore=[]),new J(n)}_prepare_callbacks(){this._callbacks=new Map,this.options.ambiguity!=="forest"&&(this._parse_tree_builder=new rn(this.rules,this.options.tree_class||Tn(y),this.options.propagate_positions,this.options.parser!=="lalr"&&this.options.ambiguity==="explicit",this.options.maybe_placeholders),this._callbacks=this._parse_tree_builder.create_callback(this.options.transformer)),Ve(this._callbacks,un(this.options.transformer,this.terminals))}_deserialize_lexer_conf(t,n,r){const i=Ie.deserialize(t.lexer_conf,n);return i.callbacks=r.lexer_callbacks||{},i.re_module=r.regex?regex:Be,i.use_bytes=r.use_bytes,i.g_regex_flags=r.g_regex_flags||"",i.skip_validation=!0,i.postlex=r.postlex,i}_load({f:t,...n}={}){let r;me(t)?r=t:r=pickle.load(t);const i=r.memo,a=r.data,o=Ot.deserialize(i,{Rule:z,TerminalDef:G},{}),_=Ke(a.options);return Ve(_,n),this.options=yn.deserialize(_,o),this.rules=a.rules.map(c=>z.deserialize(c,o)),this.source_path="<deserialized>",pn(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(c=>[c.name,c])),this.parser=ln(a.parser,o,this.lexer_conf,this._callbacks,this.options),this}static _load_from_dict({data:t,memo:n,...r}={}){return de(this)._load({f:{data:t,memo:n},...r})}repr(){return u("Lark(open(%r), parser=%r, lexer=%r, ...)",this.source_path,this.options.parser,this.options.lexer)}lex(t,n=!1){let r;!("lexer"in this)||n?r=this._build_lexer(n):r=this.lexer;const i=Ae.from_text(r,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,n=null){return this.parser.parse_interactive({unknown_param_0:t,start:n})}parse(t,n=null,r=null){return this.parser.parse(t,n,r)}}class Ue extends k{}class Ze extends Fe{constructor(){super(),this.paren_level=0,this.indent_level=[0]}*handle_NL(t){if(this.paren_level>0)return;yield t;const n=fe(t.value,`
|
|
21
|
+
`,1)[1],r=ye(n," ")+ye(n," ")*this.tab_len;if(r>w(this.indent_level))this.indent_level.push(r),yield f.new_borrow_pos(this.INDENT_type,n,t);else{for(;r<w(this.indent_level);)this.indent_level.pop(),yield f.new_borrow_pos(this.DEDENT_type,n,t);if(r!==w(this.indent_level))throw new Ue(u("Unexpected dedent to column %s. Expected dedent to %s",r,w(this.indent_level)))}}*_process(t){for(const n of t)n.type===this.NL_type?yield*this.handle_NL(n):yield n,this.OPEN_PAREN_types.includes(n.type)?this.paren_level+=1:this.CLOSE_PAREN_types.includes(n.type)&&(this.paren_level-=1);for(;this.indent_level.length>1;)this.indent_level.pop(),yield new f(this.DEDENT_type,"")}process(t){return this.paren_level=0,this.indent_level=[0],this._process(t)}get always_accept(){return[this.NL_type]}get NL_type(){throw new NotImplementedError}get OPEN_PAREN_types(){throw new NotImplementedError}get CLOSE_PAREN_types(){throw new NotImplementedError}get INDENT_type(){throw new NotImplementedError}get DEDENT_type(){throw new NotImplementedError}get tab_len(){throw new NotImplementedError}}class gn extends Ze{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}}function xn(s={}){return s.transformer&&s.transformer.constructor.name==="object"&&(s.transformer=L.fromObj(s.transformer)),Qe._load_from_dict({data:In,memo:$n,...s})}const Me={},V={},Be={escape(s){return s.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")},compile(s,t){return new RegExp(s,t)},error:SyntaxError};function wn(s,t,n,r){const i=s.compile(t,r).exec(n);if(i!=null)return i[0]}class Ge{constructor(t,n,r,i,a=!1){this.terminals=t,this.g_regex_flags=n,this.re_=r,this.use_bytes=i,this.match_whole=a,this.allowed_types=new Set(this.terminals.map(o=>o.name)),this._regexps=this._build_mres(t)}_build_mres(t){const n=this.match_whole?"$":"",r=qn(t,a=>a.pattern.flags.join("")),i=[];for(const[a,o]of r){const _=o.map(c=>`(?<${c.name}>${c.pattern.to_regexp()+n})`).join("|");i.push(new RegExp(_,`${this.g_regex_flags+a}y`))}return i}match(t,n){for(const r of this._regexps){r.lastIndex=n;const i=r.exec(t);if(i){let a=null;for(const[o,_]of Object.entries(i.groups))if(_){a=o;break}return[i[0],a]}}}}const We=typeof require!="undefined"&&require("util"),j={};function g(s){return Object.entries(s)}function he(s){return Object.keys(s)}function bn(s,t){t===void 0&&(t=Object.keys(s)[0]);const n=s[t];return delete s[t],n}function Je(s,t,n=null){return s[t]||n}function Ve(s,t){if(s.constructor.name==="Map")for(const[n,r]of g(t))s.set(n,r);else for(const[n,r]of g(t))s[n]=r}function Tn(s){return function(){return new s(...arguments)}}function u(s){let t=0;const n=[...arguments].slice(1);return s.replace(/%([sr])/g,function(){const r=arguments[1],i=n[t++];return r==="r"?We?We.inspect(i,!1,null,!0):JSON.stringify(i,null,0):i})}function vn(s,t){const n=new Set(s);for(const r of t)n.add(r);return n}function Ye(s,t){return[...s].filter(n=>!t.has(n))}function Ke(s){return{...s}}function He(s){return!!s}function de(s){return Object.create(s.prototype)}function N(s){if(typeof s=="object"){const t=Object.create(Object.getPrototypeOf(s));return Object.assign(t,s)}return s}function Y(s){return new Set(s)}function me(s){return s&&s.constructor.name==="Object"}function Nn(s){return s&&s.constructor.name==="Array"}function kn(s){return typeof s=="function"}function*C(s,t=0){let n=t;for(const r of s)yield[n++,r]}function Rn(s){for(const t of s)if(t)return!0;return!1}function Xe(s,t){return t.filter(s||He)}function K(s){const t=[...arguments].slice(1);return function(){return s(...t,...arguments)}}function w(s){return s[s.length-1]}function A(s){return function(){const t=new s(...arguments);return t.__call__.bind(t)}}function E(s,t){return Array.from({length:t},()=>s).flat()}function et(s){return/^[A-Z_$]*$/.test(s)}function fe(s,t,n){const r=s.split(t);return n?r.splice(-n-1):r}function ye(s,t){const n=new RegExp(t,"g");return(s.match(n)||[]).length}function En(s,t){for(const n of s)if(!t.has(n))return!1;return!0}function*qn(s,t){let n=[],r=null;for(const i of s){const a=t(i);r&&a!=r&&(yield[r,n],n=[]),n.push(i),r=a}yield[r,n]}const On={Terminal:ae,NonTerminal:oe,RuleOptions:B,PatternStr:le,PatternRE:ce,TerminalDef:G};var An={LarkError:k,ConfigurationError:R,GrammarError:Z,ParseError:Rt,LexError:D,UnexpectedInput:q,UnexpectedEOF:Et,UnexpectedCharacters:$,UnexpectedToken:P,VisitError:re,Meta:qe,Tree:y,Discard:V,Transformer:L,Transformer_InPlace:Oe,Transformer_NonRecursive:At,Transformer_InPlaceRecursive:It,VisitorBase:se,Visitor:$t,Visitor_Recursive:Pt,Interpreter:St,Symbol:ie,Terminal:ae,NonTerminal:oe,RuleOptions:B,Rule:z,Pattern:_e,PatternStr:le,PatternRE:ce,TerminalDef:G,Token:f,Lexer:W,LexerConf:Ie,ParserConf:$e,InteractiveParser:O,ImmutableInteractiveParser:De,PostLex:Fe,Lark:Qe,DedentError:Ue,Indenter:Ze,PythonIndenter:gn,get_parser:xn},In={parser:{lexer_conf:{terminals:[{"@":0},{"@":1},{"@":2},{"@":3},{"@":4},{"@":5},{"@":6},{"@":7},{"@":8},{"@":9},{"@":10},{"@":11},{"@":12},{"@":13},{"@":14},{"@":15},{"@":16},{"@":17},{"@":18},{"@":19},{"@":20}],ignore:["WS"],g_regex_flags:0,use_bytes:!1,lexer_type:"contextual",__type__:"LexerConf"},parser_conf:{rules:[{"@":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},{"@":49},{"@":50},{"@":51},{"@":52},{"@":53},{"@":54},{"@":55},{"@":56}],start:["start"],parser_type:"lalr",__type__:"ParserConf"},parser:{tokens:{0:"CONJUNCTION",1:"RPAR",2:"$END",3:"STRING",4:"IDENTIFIER",5:"INT",6:"OPERATOR",7:"RSQB",8:"__ANON_0",9:"__ANON_1",10:"mc_choice_selector",11:"question_selector",12:"LSQB",13:"__ANON_6",14:"bool_expr",15:"__ANON_3",16:"qc_mc_text_ignore_case",17:"NEGATION",18:"qc_matrix_displayed",19:"bool_const",20:"qc_mc_count",21:"qc_mc_displayed",22:"condition",23:"TRUE",24:"qc_matrix_selected",25:"qc_mc_text",26:"__ANON_4",27:"qc_matrix_count",28:"FALSE",29:"qc_mc_selected",30:"__ANON_2",31:"__ANON_5",32:"matrix_statement_selector",33:"matrix_choice_selector",34:"LPAR",35:"top_level_expr",36:"DOT",37:"start"},states:{0:{0:[0,59],1:[1,{"@":25}],2:[1,{"@":25}]},1:{1:[0,69]},2:{3:[0,65]},3:{1:[1,{"@":34}],0:[1,{"@":34}],2:[1,{"@":34}]},4:{4:[0,73],5:[0,8]},5:{0:[0,46],2:[1,{"@":23}]},6:{6:[0,7]},7:{3:[0,47]},8:{7:[0,17]},9:{8:[0,83],9:[0,56]},10:{1:[1,{"@":33}],0:[1,{"@":33}],2:[1,{"@":33}]},11:{1:[1,{"@":46}],0:[1,{"@":46}],2:[1,{"@":46}]},12:{1:[1,{"@":36}],0:[1,{"@":36}],2:[1,{"@":36}]},13:{10:[0,16],4:[0,72],11:[0,35]},14:{12:[0,31]},15:{1:[1,{"@":39}],0:[1,{"@":39}],2:[1,{"@":39}]},16:{1:[0,6]},17:{1:[1,{"@":50}]},18:{13:[0,54]},19:{1:[1,{"@":27}],0:[1,{"@":27}],2:[1,{"@":27}]},20:{4:[0,72],11:[0,61]},21:{1:[1,{"@":53}]},22:{4:[0,28]},23:{1:[1,{"@":44}],0:[1,{"@":44}],2:[1,{"@":44}]},24:{2:[1,{"@":22}]},25:{1:[1,{"@":37}],0:[1,{"@":37}],2:[1,{"@":37}]},26:{1:[1,{"@":28}],0:[1,{"@":28}],2:[1,{"@":28}]},27:{6:[0,71]},28:{12:[1,{"@":52}],1:[1,{"@":52}]},29:{5:[0,45]},30:{14:[0,78],15:[0,62],16:[0,55],17:[0,9],8:[0,38],18:[0,3],19:[0,19],20:[0,50],21:[0,51],22:[0,0],23:[0,48],24:[0,10],25:[0,82],9:[0,70],26:[0,32],27:[0,68],28:[0,52],29:[0,26],30:[0,13],31:[0,20]},31:{5:[0,34],4:[0,33]},32:{11:[0,74],4:[0,72]},33:{7:[0,81]},34:{7:[0,21]},35:{12:[0,4]},36:{5:[0,18],4:[0,66]},37:{6:[0,29]},38:{4:[0,72],32:[0,14],10:[0,49],33:[0,60],11:[0,84]},39:{1:[1,{"@":47}],0:[1,{"@":47}],2:[1,{"@":47}]},40:{1:[0,75]},41:{1:[1,{"@":26}],2:[1,{"@":26}]},42:{1:[0,43]},43:{1:[1,{"@":45}],0:[1,{"@":45}],2:[1,{"@":45}]},44:{2:[1,{"@":24}]},45:{1:[1,{"@":48}],0:[1,{"@":48}],2:[1,{"@":48}]},46:{34:[0,30],35:[0,44]},47:{1:[1,{"@":40}],0:[1,{"@":40}],2:[1,{"@":40}]},48:{1:[1,{"@":55}],0:[1,{"@":55}],2:[1,{"@":55}]},49:{1:[0,25]},50:{1:[1,{"@":32}],0:[1,{"@":32}],2:[1,{"@":32}]},51:{1:[1,{"@":29}],0:[1,{"@":29}],2:[1,{"@":29}]},52:{1:[1,{"@":56}],0:[1,{"@":56}],2:[1,{"@":56}]},53:{1:[0,79]},54:{6:[0,58]},55:{1:[1,{"@":31}],0:[1,{"@":31}],2:[1,{"@":31}]},56:{11:[0,84],4:[0,72],32:[0,42],10:[0,40]},57:{},58:{5:[0,39]},59:{14:[0,41],15:[0,62],16:[0,55],17:[0,9],8:[0,38],18:[0,3],19:[0,19],20:[0,50],21:[0,51],22:[0,0],23:[0,48],24:[0,10],25:[0,82],9:[0,70],26:[0,32],27:[0,68],28:[0,52],29:[0,26],30:[0,13],31:[0,20]},60:{1:[0,23]},61:{12:[0,36]},62:{4:[0,72],10:[0,53],11:[0,35]},63:{1:[0,12]},64:{2:[1,{"@":21}]},65:{1:[1,{"@":41}],0:[1,{"@":41}],2:[1,{"@":41}]},66:{13:[0,37]},67:{1:[1,{"@":42}],0:[1,{"@":42}],2:[1,{"@":42}]},68:{1:[1,{"@":35}],0:[1,{"@":35}],2:[1,{"@":35}]},69:{1:[1,{"@":43}],0:[1,{"@":43}],2:[1,{"@":43}]},70:{11:[0,84],4:[0,72],32:[0,77],10:[0,76]},71:{5:[0,67]},72:{12:[1,{"@":49}],1:[1,{"@":49}],36:[1,{"@":49}]},73:{7:[0,85]},74:{1:[0,27]},75:{1:[1,{"@":38}],0:[1,{"@":38}],2:[1,{"@":38}]},76:{1:[0,15]},77:{1:[0,11]},78:{1:[0,5]},79:{6:[0,2]},80:{15:[0,62],34:[0,30],17:[0,9],16:[0,55],8:[0,38],18:[0,3],19:[0,19],35:[0,64],20:[0,50],21:[0,51],22:[0,0],37:[0,57],23:[0,48],24:[0,10],25:[0,82],9:[0,70],26:[0,32],14:[0,24],27:[0,68],28:[0,52],29:[0,26],30:[0,13],31:[0,20]},81:{1:[1,{"@":54}]},82:{1:[1,{"@":30}],0:[1,{"@":30}],2:[1,{"@":30}]},83:{4:[0,72],32:[0,14],10:[0,63],11:[0,84],33:[0,1]},84:{12:[0,4],36:[0,22]},85:{1:[1,{"@":51}]}},start_states:{start:80},end_states:{start:57}},__type__:"ParsingFrontend"},rules:[{"@":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},{"@":49},{"@":50},{"@":51},{"@":52},{"@":53},{"@":54},{"@":55},{"@":56}],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"},$n={0:{name:"WS",pattern:{value:`(?:[ \f\r
|
|
22
|
+
])+`,flags:[],_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:[],_width:[2,4294967295],__type__:"PatternRE"},priority:0,__type__:"TerminalDef"},2:{name:"INT",pattern:{value:"-?[0-9]+",flags:[],_width:[1,4294967295],__type__:"PatternRE"},priority:0,__type__:"TerminalDef"},3:{name:"STRING",pattern:{value:`(?:'[^\\']*'|"[^"]*")`,flags:[],_width:[2,4294967295],__type__:"PatternRE"},priority:0,__type__:"TerminalDef"},4:{name:"OPERATOR",pattern:{value:"(?:regex_matches|not_contains|contains|==|!=|<=|>=|<|>)",flags:[],_width:[1,13],__type__:"PatternRE"},priority:0,__type__:"TerminalDef"},5:{name:"CONJUNCTION",pattern:{value:"(?:and|or)",flags:[],_width:[2,3],__type__:"PatternRE"},priority:0,__type__:"TerminalDef"},6:{name:"NEGATION",pattern:{value:"!",flags:[],__type__:"PatternStr"},priority:0,__type__:"TerminalDef"},7:{name:"TRUE",pattern:{value:"true",flags:[],__type__:"PatternStr"},priority:0,__type__:"TerminalDef"},8:{name:"FALSE",pattern:{value:"false",flags:[],__type__:"PatternStr"},priority:0,__type__:"TerminalDef"},9:{name:"LPAR",pattern:{value:"(",flags:[],__type__:"PatternStr"},priority:0,__type__:"TerminalDef"},10:{name:"RPAR",pattern:{value:")",flags:[],__type__:"PatternStr"},priority:0,__type__:"TerminalDef"},11:{name:"__ANON_0",pattern:{value:"selected(",flags:[],__type__:"PatternStr"},priority:0,__type__:"TerminalDef"},12:{name:"__ANON_1",pattern:{value:"displayed(",flags:[],__type__:"PatternStr"},priority:0,__type__:"TerminalDef"},13:{name:"__ANON_2",pattern:{value:"text(",flags:[],__type__:"PatternStr"},priority:0,__type__:"TerminalDef"},14:{name:"__ANON_3",pattern:{value:"text_ignore_case(",flags:[],__type__:"PatternStr"},priority:0,__type__:"TerminalDef"},15:{name:"__ANON_4",pattern:{value:"count_selected(",flags:[],__type__:"PatternStr"},priority:0,__type__:"TerminalDef"},16:{name:"__ANON_5",pattern:{value:"count_choice_selections(",flags:[],__type__:"PatternStr"},priority:0,__type__:"TerminalDef"},17:{name:"LSQB",pattern:{value:"[",flags:[],__type__:"PatternStr"},priority:0,__type__:"TerminalDef"},18:{name:"__ANON_6",pattern:{value:"])",flags:[],__type__:"PatternStr"},priority:0,__type__:"TerminalDef"},19:{name:"RSQB",pattern:{value:"]",flags:[],__type__:"PatternStr"},priority:0,__type__:"TerminalDef"},20:{name:"DOT",pattern:{value:".",flags:[],__type__:"PatternStr"},priority:0,__type__:"TerminalDef"},21:{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"},22:{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"},23:{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"},24:{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"},25:{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"},26:{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"},27:{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"},28:{origin:{name:"condition",__type__:"NonTerminal"},expansion:[{name:"qc_mc_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"},29:{origin:{name:"condition",__type__:"NonTerminal"},expansion:[{name:"qc_mc_displayed",__type__:"NonTerminal"}],order:2,alias:null,options:{keep_all_tokens:!1,expand1:!1,priority:null,template_source:null,empty_indices:[],__type__:"RuleOptions"},__type__:"Rule"},30:{origin:{name:"condition",__type__:"NonTerminal"},expansion:[{name:"qc_mc_text",__type__:"NonTerminal"}],order:3,alias:null,options:{keep_all_tokens:!1,expand1:!1,priority:null,template_source:null,empty_indices:[],__type__:"RuleOptions"},__type__:"Rule"},31:{origin:{name:"condition",__type__:"NonTerminal"},expansion:[{name:"qc_mc_text_ignore_case",__type__:"NonTerminal"}],order:4,alias:null,options:{keep_all_tokens:!1,expand1:!1,priority:null,template_source:null,empty_indices:[],__type__:"RuleOptions"},__type__:"Rule"},32:{origin:{name:"condition",__type__:"NonTerminal"},expansion:[{name:"qc_mc_count",__type__:"NonTerminal"}],order:5,alias:null,options:{keep_all_tokens:!1,expand1:!1,priority:null,template_source:null,empty_indices:[],__type__:"RuleOptions"},__type__:"Rule"},33:{origin:{name:"condition",__type__:"NonTerminal"},expansion:[{name:"qc_matrix_selected",__type__:"NonTerminal"}],order:6,alias:null,options:{keep_all_tokens:!1,expand1:!1,priority:null,template_source:null,empty_indices:[],__type__:"RuleOptions"},__type__:"Rule"},34:{origin:{name:"condition",__type__:"NonTerminal"},expansion:[{name:"qc_matrix_displayed",__type__:"NonTerminal"}],order:7,alias:null,options:{keep_all_tokens:!1,expand1:!1,priority:null,template_source:null,empty_indices:[],__type__:"RuleOptions"},__type__:"Rule"},35:{origin:{name:"condition",__type__:"NonTerminal"},expansion:[{name:"qc_matrix_count",__type__:"NonTerminal"}],order:8,alias:null,options:{keep_all_tokens:!1,expand1:!1,priority:null,template_source:null,empty_indices:[],__type__:"RuleOptions"},__type__:"Rule"},36:{origin:{name:"qc_mc_selected",__type__:"NonTerminal"},expansion:[{name:"NEGATION",filter_out:!1,__type__:"Terminal"},{name:"__ANON_0",filter_out:!0,__type__:"Terminal"},{name:"mc_choice_selector",__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"},37:{origin:{name:"qc_mc_selected",__type__:"NonTerminal"},expansion:[{name:"__ANON_0",filter_out:!0,__type__:"Terminal"},{name:"mc_choice_selector",__type__:"NonTerminal"},{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"},38:{origin:{name:"qc_mc_displayed",__type__:"NonTerminal"},expansion:[{name:"NEGATION",filter_out:!1,__type__:"Terminal"},{name:"__ANON_1",filter_out:!0,__type__:"Terminal"},{name:"mc_choice_selector",__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"},39:{origin:{name:"qc_mc_displayed",__type__:"NonTerminal"},expansion:[{name:"__ANON_1",filter_out:!0,__type__:"Terminal"},{name:"mc_choice_selector",__type__:"NonTerminal"},{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"},40:{origin:{name:"qc_mc_text",__type__:"NonTerminal"},expansion:[{name:"__ANON_2",filter_out:!0,__type__:"Terminal"},{name:"mc_choice_selector",__type__:"NonTerminal"},{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"},41:{origin:{name:"qc_mc_text_ignore_case",__type__:"NonTerminal"},expansion:[{name:"__ANON_3",filter_out:!0,__type__:"Terminal"},{name:"mc_choice_selector",__type__:"NonTerminal"},{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"},42:{origin:{name:"qc_mc_count",__type__:"NonTerminal"},expansion:[{name:"__ANON_4",filter_out:!0,__type__:"Terminal"},{name:"question_selector",__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"},43:{origin:{name:"qc_matrix_selected",__type__:"NonTerminal"},expansion:[{name:"NEGATION",filter_out:!1,__type__:"Terminal"},{name:"__ANON_0",filter_out:!0,__type__:"Terminal"},{name:"matrix_choice_selector",__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"},44:{origin:{name:"qc_matrix_selected",__type__:"NonTerminal"},expansion:[{name:"__ANON_0",filter_out:!0,__type__:"Terminal"},{name:"matrix_choice_selector",__type__:"NonTerminal"},{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"},45:{origin:{name:"qc_matrix_displayed",__type__:"NonTerminal"},expansion:[{name:"NEGATION",filter_out:!1,__type__:"Terminal"},{name:"__ANON_1",filter_out:!0,__type__:"Terminal"},{name:"matrix_statement_selector",__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:"qc_matrix_displayed",__type__:"NonTerminal"},expansion:[{name:"__ANON_1",filter_out:!0,__type__:"Terminal"},{name:"matrix_statement_selector",__type__:"NonTerminal"},{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"},47:{origin:{name:"qc_matrix_count",__type__:"NonTerminal"},expansion:[{name:"__ANON_5",filter_out:!0,__type__:"Terminal"},{name:"question_selector",__type__:"NonTerminal"},{name:"LSQB",filter_out:!0,__type__:"Terminal"},{name:"INT",filter_out:!1,__type__:"Terminal"},{name:"__ANON_6",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"},48:{origin:{name:"qc_matrix_count",__type__:"NonTerminal"},expansion:[{name:"__ANON_5",filter_out:!0,__type__:"Terminal"},{name:"question_selector",__type__:"NonTerminal"},{name:"LSQB",filter_out:!0,__type__:"Terminal"},{name:"IDENTIFIER",filter_out:!1,__type__:"Terminal"},{name:"__ANON_6",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"},49:{origin:{name:"question_selector",__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"},50:{origin:{name:"mc_choice_selector",__type__:"NonTerminal"},expansion:[{name:"question_selector",__type__:"NonTerminal"},{name:"LSQB",filter_out:!0,__type__:"Terminal"},{name:"INT",filter_out:!1,__type__:"Terminal"},{name:"RSQB",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"},51:{origin:{name:"mc_choice_selector",__type__:"NonTerminal"},expansion:[{name:"question_selector",__type__:"NonTerminal"},{name:"LSQB",filter_out:!0,__type__:"Terminal"},{name:"IDENTIFIER",filter_out:!1,__type__:"Terminal"},{name:"RSQB",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"},52:{origin:{name:"matrix_statement_selector",__type__:"NonTerminal"},expansion:[{name:"question_selector",__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"},53:{origin:{name:"matrix_choice_selector",__type__:"NonTerminal"},expansion:[{name:"matrix_statement_selector",__type__:"NonTerminal"},{name:"LSQB",filter_out:!0,__type__:"Terminal"},{name:"INT",filter_out:!1,__type__:"Terminal"},{name:"RSQB",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"},54:{origin:{name:"matrix_choice_selector",__type__:"NonTerminal"},expansion:[{name:"matrix_statement_selector",__type__:"NonTerminal"},{name:"LSQB",filter_out:!0,__type__:"Terminal"},{name:"IDENTIFIER",filter_out:!1,__type__:"Terminal"},{name:"RSQB",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"},55:{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"},56:{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"}};const tt=require("assert");function nt(s){if(s.length===1)return s[0];const t=s[1].value;return t==="or"?s[0]||s[2]:t==="and"?s[0]&&s[2]:!1}function ge(s,t,n){switch(t){case"==":return s===n;case"!=":return s!==n;case"<=":return s<=n;case">=":return s>=n;case"<":return s<n;case">":return s>n;default:return!1}}function rt(s,t,n,r){const i=r?s.toLowerCase():s,a=r?n.toLowerCase():n;switch(t){case"contains":return i.includes(a);case"not_contains":return!i.includes(a);case"regex_matches":try{return new RegExp(n).test(i)}catch{return!1}default:return ge(i,t,a)}}function H(s,t){return s.length===1?t(s[0]):(tt(s[0].type==="NEGATION"),!t(s[1]))}function xe(s){if(!["INT","IDENTIFIER"].includes(s.type))throw new SyntaxError(`Invalid token type: ${s.type}; expected IDENTIFIER or INT`);return T(s)}function T(s){var t,n;switch(s.type){case"IDENTIFIER":return s.value;case"INT":return parseInt(s.value,10);case"STRING":{const r=s.value.match(/(?:'(?<single>[^\']*)')|(?:"(?<double>[^\"]*)")/),i=((t=r==null?void 0:r.groups)==null?void 0:t.double)||((n=r==null?void 0:r.groups)==null?void 0:n.single);return tt(i),i}case"OPERATOR":return s.value;case"TRUE":return!0;case"FALSE":return!1;default:throw new SyntaxError(`Invalid token type: ${s.type}`)}}function st(s,t){const n={start:r=>r[0],top_level_expr:nt,bool_expr:nt,condition:r=>r[0],qc_mc_selected:r=>H(r,t.isSelected),qc_mc_displayed:r=>H(r,t.isDisplayed),qc_mc_text:r=>rt(t.textEntry(r[0]),T(r[1]),T(r[2]),!1),qc_mc_text_ignore_case:r=>rt(t.textEntry(r[0]),T(r[1]),T(r[2]),!0),qc_mc_count:r=>ge(t.countSelected(r[0]),T(r[1]),T(r[2])),qc_matrix_selected:r=>H(r,t.isSelected),qc_matrix_displayed:r=>H(r,t.isDisplayed),qc_matrix_count:r=>ge(t.countChoiceSelections(r[0],xe(r[1])),T(r[2]),T(r[3])),question_selector:r=>r[0].value,mc_choice_selector:r=>({questionId:r[0],choice:xe(r[1])}),matrix_statement_selector:r=>({questionId:r[0],statementId:T(r[1])}),matrix_choice_selector:r=>({...r[0],choice:xe(r[1])}),bool_const:r=>r[0].value==="true"};return An.get_parser({transformer:n}).parse(s)}const Pn=/\$\{m:([^\}]+)\}/g,Sn=100,we=(s,t)=>{if(typeof t=="string"){let n=t,r=0;for(;r<Sn;){const i=n.replace(Pn,(a,o)=>{if(s[o]===void 0)throw new Error(`Undefined macro: ${o}`);return s[o]});if(i===n)return i;n=i,r+=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]=we(s,t[n])}),t},it=s=>(s.sections=we(s.macros||{},s.sections),s);var zn=Object.defineProperty,Dn=(s,t,n)=>t in s?zn(s,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):s[t]=n,S=(s,t,n)=>(Dn(s,typeof t!="symbol"?t+"":t,n),n);const at=new ut({allowUnionTypes:!0});ht(at);const ot=at.compile(ke);class F extends Error{}class _t extends Error{}class I extends Error{}class Ln extends Error{}class jn{constructor(){S(this,"seenQuestions",new Set),S(this,"seenQuestionStatements",new Map),S(this,"seenQuestionChoices",new Map),S(this,"seenTextChoices",new Map),S(this,"validateReference",t=>{var n,r,i;if(!this.seenQuestions.has(t.questionId))throw new F(`Invalid question: ${t.questionId}`);if(t.statementId!==void 0&&!((n=this.seenQuestionStatements.get(t.questionId))!=null&&n.has(t.statementId)))throw new F(`Invalid statement: ${t.questionId}.${t.statementId}`);if(t.choice!==void 0&&!((r=this.seenQuestionChoices.get(t.questionId))!=null&&r.has(t.choice)))throw new F(`Invalid choice: ${t.questionId}[${t.choice}]`);if(t.choice!==void 0&&t.expectText===!0&&!((i=this.seenTextChoices.get(t.questionId))!=null&&i.has(t.choice)))throw new F(`Invalid text reference: ${t.questionId}[${t.choice}]`)}),S(this,"evaluator",{isSelected:t=>(this.validateReference(t),!1),isDisplayed:t=>(this.validateReference(t),!1),countSelected:t=>(this.validateReference({questionId:t}),0),countChoiceSelections:(t,n)=>(this.validateReference({questionId:t,choice:n}),0),textEntry:t=>(this.validateReference({...t,expectText:!0}),"")})}}const Q=(s,t,n)=>{if(n)try{st(n,s.evaluator)}catch(r){throw r instanceof F||r instanceof I?r:new Error(`Syntax error parsing display logic at ${t}: ${n}`)}},lt=(s,t)=>{var n,r,i,a,o;Q(t,s.id,s.display_logic),Q(t,s.id,s.display_logic_in_page),(n=s.statements)==null||n.forEach(l=>{Q(t,`${s.id}.${l.id}`,l.display_logic)}),(r=s.choices)==null||r.forEach(l=>{Q(t,`${s.id}[${l.id||l.value}]`,l.display_logic)});const _=l=>{const[p,h]=l.split("/",2);return{questionId:p,expression:h}},c=l=>{const p=(l.expression.startsWith("for_matrix_choice")||l.expression.startsWith("unselected_for_matrix_choice")?t.seenQuestionStatements:t.seenQuestionChoices).get(l.questionId);if(p===void 0)throw new _t(`Invalid question referenced in locator expression: ${l.questionId}/${l.expression}`);return p};if(s.id!==void 0){if(t.seenQuestions.has(s.id))throw new I(`Duplicate question id: ${s.id}`);if(t.seenQuestions.add(s.id),s.statements||s.dynamic_statements){const p=new Set;if(t.seenQuestionStatements.set(s.id,p),(i=s.statements)==null||i.forEach(h=>{if(p.has(h.id))throw new I(`Duplicate statement id: ${s.id}.${h.id}`);p.add(h.id)}),s.dynamic_statements){const h=_(s.dynamic_statements);c(h).forEach(d=>{if(typeof d=="number")throw new _t(`Dynamic statement in question ${s.id} refers to choices with values`);if(p.has(d))throw new I(`Duplicate statement ${d} via dynamic statements in question ${s.id}`);p.add(d)})}}const l=(a=s.choices)!=null?a:[];if(s.choice_groups){if(new Set(s.choice_groups.map(p=>p.id)).size!==s.choice_groups.length)throw new I(`Choice groups must have a unique id in question ${s.id}`);s.choice_groups.forEach(p=>l.push(...p.choices))}if(l||s.dynamic_choices){const p=new Set;t.seenQuestionChoices.set(s.id,p);const h=new Set;if(t.seenTextChoices.set(s.id,h),l.forEach(d=>{var m;const b=(m=d.id)!=null?m:d.value;if(p.has(b))throw new I(`Duplicate choice: ${s.id}[${b}]`);p.add(b),d.text&&d.text!=="no"&&h.add(b)}),s.dynamic_choices){const d=_(s.dynamic_choices);c(d).forEach(m=>{if(p.has(m))throw new I(`Duplicate choice ${m} via dynamic choices in ${s.id}`);p.add(m)}),(o=t.seenTextChoices.get(d.questionId))==null||o.forEach(m=>h.add(m))}if(new Set([...p].map(d=>typeof d)).size>=2)throw new Ln("All choices in a question must either all have id's or all have values")}}},Cn=s=>{if(!ot(s))throw new Error(`Invalid template: ${s.template.id}. Reason: ${JSON.stringify(ot.errors,null,4)}`);it(s);const t=new jn;s.sections.forEach(n=>{var r,i;Q(t,n.id,n.display_logic),(r=n.questions)==null||r.forEach(a=>{lt(a,t)}),(i=n.pages)==null||i.forEach(a=>{var o;(o=a.questions)==null||o.forEach(_=>{lt(_,t)})})})},Fn=ke,Qn="pulse_default_alpha",Un={allPermissions:mt,SURVEY_RESOURCE_TYPE:dt,surveyAdministerPermission:Ne};export{Qn as DEFAULT_TEMPLATE_ID,st as evaluateExpression,we as interpolateMacros,it as interpolateTemplate,Un as permissions,Fn as templateSchema,Cn as validateTemplate};
|
|
23
23
|
//# sourceMappingURL=index.esm.js.map
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@spotify/backstage-plugin-pulse-common",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.8.0",
|
|
4
4
|
"license": "SEE LICENSE IN LICENSE.md",
|
|
5
5
|
"homepage": "https://backstage.spotify.com",
|
|
6
6
|
"main": "dist/index.cjs.js",
|
|
@@ -29,7 +29,7 @@
|
|
|
29
29
|
"graphql": "^16.0.0"
|
|
30
30
|
},
|
|
31
31
|
"devDependencies": {
|
|
32
|
-
"@backstage/cli": "^0.22.
|
|
32
|
+
"@backstage/cli": "^0.22.10",
|
|
33
33
|
"js-yaml": "^4.1.0",
|
|
34
34
|
"json-schema-to-typescript": "13.0.2",
|
|
35
35
|
"process": "^0.11.10"
|
|
@@ -79,7 +79,7 @@
|
|
|
79
79
|
},
|
|
80
80
|
"macros": {
|
|
81
81
|
"type": "object",
|
|
82
|
-
"description": "Expression shortcuts. Macros are referred to elsewhere in the survey using the ${
|
|
82
|
+
"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.",
|
|
83
83
|
"additionalProperties": {
|
|
84
84
|
"type": "string"
|
|
85
85
|
}
|
|
@@ -239,7 +239,7 @@
|
|
|
239
239
|
},
|
|
240
240
|
"id": {
|
|
241
241
|
"type": "string",
|
|
242
|
-
"description": "The id of the group.
|
|
242
|
+
"description": "The id of the group."
|
|
243
243
|
},
|
|
244
244
|
"display": {
|
|
245
245
|
"type": "string",
|
|
@@ -253,7 +253,7 @@
|
|
|
253
253
|
"$ref": "#/$defs/randomization"
|
|
254
254
|
}
|
|
255
255
|
},
|
|
256
|
-
"required": ["statements", "display"],
|
|
256
|
+
"required": ["statements", "id", "display"],
|
|
257
257
|
"additionalProperties": false
|
|
258
258
|
}
|
|
259
259
|
},
|
|
@@ -281,7 +281,7 @@
|
|
|
281
281
|
},
|
|
282
282
|
"id": {
|
|
283
283
|
"type": "string",
|
|
284
|
-
"description": "The id of the group.
|
|
284
|
+
"description": "The id of the group."
|
|
285
285
|
},
|
|
286
286
|
"display": {
|
|
287
287
|
"type": "string",
|
|
@@ -295,7 +295,7 @@
|
|
|
295
295
|
"$ref": "#/$defs/randomization"
|
|
296
296
|
}
|
|
297
297
|
},
|
|
298
|
-
"required": ["choices", "display"],
|
|
298
|
+
"required": ["choices", "id", "display"],
|
|
299
299
|
"additionalProperties": false
|
|
300
300
|
}
|
|
301
301
|
},
|