From ed4d30573cd73d1f484174530a2ad721319a86b8 Mon Sep 17 00:00:00 2001 From: Ad5001 Date: Tue, 10 Oct 2023 00:05:19 +0200 Subject: [PATCH] Adding usage for functions. --- .../LogarithmPlotter/js/parsing/reference.js | 85 +++++++++++++++++-- 1 file changed, 80 insertions(+), 5 deletions(-) diff --git a/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/js/parsing/reference.js b/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/js/parsing/reference.js index 92baff9..31a5963 100644 --- a/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/js/parsing/reference.js +++ b/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/js/parsing/reference.js @@ -85,15 +85,90 @@ const FUNCTIONS = { 'gamma': Polyfill.gamma, 'Γ': Polyfill.gamma, 'roundTo': (x, exp) => Number(x).toFixed(exp), - 'map': Polyfill.arrayMap, - 'fold': Polyfill.arrayFold, - 'filter': Polyfill.arrayFilter, - 'indexOf': Polyfill.indexOf, - 'join': Polyfill.arrayJoin, + // 'map': Polyfill.arrayMap, + // 'fold': Polyfill.arrayFold, + // 'filter': Polyfill.arrayFilter, + // 'indexOf': Polyfill.indexOf, + // 'join': Polyfill.arrayJoin, // Integral & derivative (only here for autocomplete). 'integral': () => 0, // TODO: Implement 'derivative': () => 0, } const FUNCTIONS_LIST = Object.keys(FUNCTIONS); +class P { + // Parameter class. + constructor(type, name = '', optional = false, multipleAllowed = false) { + this.name = name + this.type = type + this.optional = optional + this.multipleAllowed = multipleAllowed + } + + toString() { + base_string = this.type + if(this.name != '') + base_string = `${this.name}: ${base_string}` + if(this.multipleAllowed) + base_string += '...' + if(!this.optional) + base_string = `<${base_string}>` + else + base_string = `[${base_string}]` + return base_string + } +} + +let string = new P('string') +let bool = new P('boolean') +let number = new P('number') +let array = new P('array') + +const FUNCTIONS_USAGE = { + 'length': [string], + 'not': [bool], + // Math functions + 'abs': [number], + 'acos': [number], + 'acosh': [number], + 'asin': [number], + 'asinh': [number], + 'atan': [number], + 'atan2': [number], + 'atanh': [number], + 'cbrt': [number], + 'ceil': [number], + //'clz32': [number], + 'cos': [number], + 'cosh': [number], + 'exp': [number], + 'expm1': [number], + 'floor': [number], + //'fround': [number], + 'hypot': [number], + //'imul': [number], + 'lg': [number], + 'ln': [number], + 'log': [number], + 'log10': [number], + 'log1p': [number], + 'log2': [number], + 'max': [number, number, new P('number', '', true, null, true)], + 'min': [number, number, new P('number', '', true, null, true)], + 'pow': [number, new P('number', 'exponent')], + 'random': [number, number], + 'round': [number], + 'sign': [number], + 'sin': [number], + 'sinh': [number], + 'sqrt': [number], + 'tan': [number], + 'tanh': [number], + 'trunc': [number], + // Functions in expr-eval, ported here. + 'fac': [number], + 'gamma': [number], + 'Γ': [number], + 'roundTo': [number, new P('number')], +}