Typescript all the parser things

This commit is contained in:
Thaum Rystra
2024-02-20 23:21:12 +02:00
parent 3ea492ee78
commit ac15512bc5
86 changed files with 926 additions and 718 deletions

View File

@@ -1,9 +1,10 @@
import { getSingleProperty } from '/imports/api/engine/loadCreatures';
import array from '/imports/parser/parseTree/constant';
import constant from '/imports/parser/parseTree/constant';
import ParseNode from '/imports/parser/parseTree/ParseNode';
import array from '/imports/parser/parseTree/array';
import constant, { isFiniteNode } from '/imports/parser/parseTree/constant';
//set up the collection for creature variables
let CreatureVariables = new Mongo.Collection('creatureVariables');
const CreatureVariables = new Mongo.Collection('creatureVariables');
// Unique index on _creatureId
if (Meteor.isServer) {
@@ -28,7 +29,7 @@ if (Meteor.isServer) {
* Get the property from the given scope, respecting properties that are just a link to the actual
* property document
*/
export function getFromScope(name, scope) {
export function getFromScope(name: string, scope) {
let value = scope?.[name];
if (value?._propId) {
value = getSingleProperty(scope._creatureId, value._propId);
@@ -38,13 +39,13 @@ export function getFromScope(name, scope) {
export function getNumberFromScope(name, scope) {
const parseNode = getParseNodeFromScope(name, scope);
if (!parseNode || parseNode.valueType !== 'number') {
if (!parseNode || !isFiniteNode(parseNode)) {
return undefined;
}
return parseNode.value;
}
export function getParseNodeFromScope(name, scope) {
export function getParseNodeFromScope(name, scope): ParseNode | undefined {
let value = getFromScope(name, scope);
if (!value) return;
let valueType = getType(value);

View File

@@ -6,7 +6,8 @@ import { ValidatedMethod } from 'meteor/mdg:validated-method';
import { RateLimiterMixin } from 'ddp-rate-limiter-mixin';
import { assertEditPermission } from '/imports/api/creature/creatures/creaturePermissions';
import { parse, prettifyParseError } from '/imports/parser/parser';
import resolve, { toString } from '/imports/parser/resolve';
import resolve from '/imports/parser/resolve';
import toString from '/imports/parser/toString';
import STORAGE_LIMITS from '/imports/constants/STORAGE_LIMITS';
import { assertUserInTabletop } from '/imports/api/tabletop/methods/shared/tabletopPermissions.js';
@@ -196,7 +197,7 @@ const logRoll = new ValidatedMethod({
optional: true,
},
}).validator(),
run({ roll, tabletopId, creatureId }) {
async run({ roll, tabletopId, creatureId }) {
if (!creatureId && !tabletopId) throw new Meteor.Error('no-id',
'A creature id or tabletop id must be given'
);
@@ -230,7 +231,7 @@ const logRoll = new ValidatedMethod({
let {
result: compiled,
context
} = resolve('compile', parsedResult, variables);
} = await resolve('compile', parsedResult, variables);
const compiledString = toString(compiled);
if (!equalIgnoringWhitespace(compiledString, roll)) logContent.push({
value: roll
@@ -238,12 +239,12 @@ const logRoll = new ValidatedMethod({
logContent.push({
value: compiledString
});
let { result: rolled } = resolve('roll', compiled, variables, context);
let { result: rolled } = await resolve('roll', compiled, variables, context);
let rolledString = toString(rolled);
if (rolledString !== compiledString) logContent.push({
value: rolledString
});
let { result } = resolve('reduce', rolled, variables, context);
let { result } = await resolve('reduce', rolled, variables, context);
let resultString = toString(result);
if (resultString !== rolledString) logContent.push({
value: resultString