From 57abb754e6dfc7024a4b918b70b08744903be4c6 Mon Sep 17 00:00:00 2001 From: Mohammed Samir <42011920+ms2052001@users.noreply.github.com> Date: Mon, 31 Aug 2020 23:08:10 +0200 Subject: [PATCH] Update REAMDE.md, CHANGLOG.md --- CHANGELOG.md | 27 +++++++++++++++------- README.md | 63 +++++++++++++++++++++++++++++++++++----------------- 2 files changed, 62 insertions(+), 28 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ab57184..28c78df 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,14 @@ +# 31 Aug 2020, v2.2.0 +Summary of changes: +- Add version property to the exported package, which is now "2.2.0" +- Add strict to options, see README.md +- Parse "member expression" such as "p.first_component" and "f(x).someThing.another()" wether or not `options.singleCharName == true`. +- When `options.strict == false`, "f()" is function regardless of `options.functions`. +- When `options.strict == false`, "f + a - sin" is parse with no "Function used as variable" error. +- Allow functions to be invoke by void parentheses such as "f()"; +- A more intelligent way to handle +- Fix operators ^ and ! from the previous release to parse some expression like: "5^2x!" as "(5^2)(x!)". + # v2.1.2 Summary of Changes: - Fix operators ^ and ! to parse some expression like: "5^2x!". @@ -9,12 +20,12 @@ Summary of Changes: # v2.1.0 Summary of Changes: - Fix factorial postfix operator "!" -- Enable single char to be a char suffixed by integer such as "p1, x0, x1, y123" +- Enable single char to be a char followed by int num such as "p1, x0, x1, y123" - Add "member expressions" Node and parse something like " 1+ p1.x" Summary of Changes (dev): - Add tests for member expression -- Commenting out some tests for future releases, insha'allah! -- When a test fail: the loged objects (node and struct) are simplified first to focus on some properties +- Commenting out some tests for future releases, insha'Allah! +- When a test fails: the logged objects (node and struct) are simplified first to focus on some properties # v2.0.0 Summary of Changes: @@ -22,7 +33,7 @@ Summary of Changes: - Update the readme file # v2.0.0-0 -Becuase that changes after the last complete version are major, making the next version major is the best thing. +Because that changes after the last complete version are major, making the next version major is the best thing. Summary of Changes: - Fix ReferenceError: identifier "name" is not defined. @@ -32,17 +43,17 @@ Summary of Changes (dev): # v1.1.0-0 Summary of Changes: - Node has check and checkType methods: - * check: to check for all property except args - * checkType: to check the type of Node instance, it can be done using check + * `check`: to check for all property except args + * `checkType`: to check the type of Node instance, it can be done using check - Node has types: * number * id * function * block: (), [], {}, || * automult - * operator: + * operator: - infix: *, /, -, +, ^, &&, ||, == - postfix: ! * delimiter -- Do some tests in the parsing proces +- Do some tests in the parsing process - Add some todo comments for next releases diff --git a/README.md b/README.md index 632abc1..5442ee5 100644 --- a/README.md +++ b/README.md @@ -1,10 +1,10 @@ # math-parser -A mathematical expressions parser. We mean by mathematical that, e.g., arithmetic operations is considered for example if you pass "1+2", the result would by a (add node "+") with two children nodes of type number. +A math expressions parser. We mean by mathematical that, e.g., arithmetic operations is considered for example if you pass "1+2", the result would by a (add node "+") with two children nodes of type number. -## Install +# Install `npm install @scicave/math-parser` -## Usage +# Usage Require, import: ```js @@ -16,54 +16,77 @@ const mathParser = require('@scicave/math-parser'); /* ``` Examples: ```js + console.log(mathParser.parse(' 1.5 * 5 ^x !')); + console.log(mathParser.parse(' 5^2x !')); + console.log(mathParser.parse('2xy')); + console.log(mathParser.parse('2long_var_name', { singleCharName: false, })); + // xlong_var_name is considered as one var not automult console.log(mathParser.parse('xlong_var_name', { singleCharName: false, })); + +console.log(mathParser.parse('f(x).someProperty.fn(y).result ^ 2 \n!', { functions: ['f'] })); + +// strict is false by default so this is true, unlike the previous parsing process +console.log(mathParser.parse('f().someProperty.fn(y).result ^ 2 \n!')); + ``` -## Options +# Options -- _autoMult_: boolean +## autoMult: boolean Default: `true` To perform multiplication in these cases: -1. 2x -2. sinxcosx -3. sinx(5y) -> Notice: sinxcosx when singleCharName is `false` will be variable name +1. `2x` +2. `sinxcosx` +3. `sinx(5y)` +> Notice: `sinxcosx` when singleCharName is `false` will be a variable name -- _singleCharName_: boolean +## singleCharName: boolean Default: `true` -Maths conventionally works with single char named variables and constants, but in programming languages you have freedom, moreover the convention is to use multi-char named identifier. -For example if you want to use "pi" or "phi", etc, you have to set this to `false`. +Maths conventionally works with single char named variables and constants, but in programming languages you have freedom. Moreover, the convention is to use multi-char named identifier. +For example, if you want to use "pi" or "phi", etc, you have to set this to `false`. +> TODO: make new options `variables`, with default values "pi" and "phi", ..., use this option to deal with some multi-char variable (or constants, or you can say identifiers) in singleCharName mode -- _memberExpressionAllowed_: boolean +## strict: boolean -Default: `true` +Default: `false` + +- `f()`: is parsed as function whether or not it exists in options.functions +- `sin + 2`: you can you functions identifiers as references, with no arguments. -For example: `p.x` or `point.x`. +## memberExpressionAllowed: boolean +Default: `true` + +For example: + - `p.x` + - `point.x` + - `f(x).someProperty.fn(y).result`: valid syntax in both cases of `singleCharName`. + - .......... etc, and so on. -- _functions_: [string] +## functions: [string] -When autoMult is `true`, some expression like "f(x)" will be considered as multiplication, inorder to parse it as function with `callee` as instence of `mathParser.Node` has `type` of "id" and `name` equals "f". +When autoMult is `true`, some expression like `f(x)` will be considered as multiplication, in order to parse it as a function with `name == "f"`, you can pass `options.functions = ['f']`. Notice that, `strict == flase // by default`, some expression such as `f()`, an id follwed by viid parentheses, will be parse as function whether or not `options.function` includes "f". -## Unsure about +# Unsure about In these confusing cases, you can handle the parsed expression to transform to what you want. + - `5^2x!` To be `5^(2x!)` or `(5^2)(x!)` or `(5^2x)!`, ... +The result parser tree is equivalent to `(5^2)(x!)`. -This parser handles it as `5^(2x!)`. -## Lisence +# License MIT