MCPcopy Create free account
hub / github.com/MirrowApp/mirrow / constructor

Method constructor

packages/core/src/compiler/parser.ts:97–244  ·  view source on GitHub ↗
(tokens: Token[], symbolTable?: Map<string, LiteralValue>)

Source from the content-addressed store, hash-verified

95 }
96
97 constructor(tokens: Token[], symbolTable?: Map<string, LiteralValue>) {
98 this.tokens = tokens;
99 this.symbolTable = symbolTable ?? new Map();
100 this.ATTRIBUTE_VALIDATORS = {
101 number: (context, spec, value) => {
102 if (value.type === "NumberLiteral") {
103 const numberValue = value as NumberLiteral;
104 if (spec.validator && !spec.validator(numberValue.value)) {
105 failValidation(context, "failed validation", value.position);
106 }
107 return;
108 }
109
110 if (value.type === "StringLiteral" && this.fellThrough) {
111 return;
112 }
113
114 // Allow variable references - they will be resolved during compilation
115 if (value.type === "VariableReference") {
116 return;
117 }
118
119 failValidation(context, "expects a numeric value", value.position);
120 },
121 string: (context, spec, value) => {
122 // Allow variable references - they will be resolved during compilation
123 if (value.type === "VariableReference") {
124 return;
125 }
126
127 if (value.type !== "StringLiteral") {
128 failValidation(
129 context,
130 `expects a string value got '${value.type}'`,
131 value.position
132 );
133 }
134 const stringValue = value as StringLiteral;
135 if (spec.validator && !spec.validator(stringValue.value)) {
136 failValidation(context, "failed validation", value.position);
137 }
138 },
139 boolean: (context, spec, value) => {
140 // Allow variable references - they will be resolved during compilation
141 if (value.type === "VariableReference") {
142 return;
143 }
144
145 if (value.type !== "IdentifierLiteral") {
146 failValidation(context, "expects 'true' or 'false'", value.position);
147 }
148 const booleanValue = value as IdentifierLiteral;
149 const normalized = booleanValue.name.toLowerCase();
150 if (normalized !== "true" && normalized !== "false") {
151 failValidation(context, "expects 'true' or 'false'", value.position);
152 }
153 if (spec.validator && !spec.validator(normalized === "true")) {
154 failValidation(context, "failed validation", value.position);

Callers

nothing calls this directly

Calls 1

failValidationFunction · 0.85

Tested by

no test coverage detected