All Projects → KennethanCeyer → Metric Parser

KennethanCeyer / Metric Parser

Licence: mit
📜 AST-based advanced mathematical parser written by Typescript.

Programming Languages

javascript
184084 projects - #8 most used programming language
typescript
32286 projects

Projects that are alternatives of or similar to Metric Parser

Libdparse
Library for lexing and parsing D source code
Stars: ✭ 91 (+250%)
Mutual labels:  ast, syntax-tree, parser
Javaparser
Java 1-15 Parser and Abstract Syntax Tree for Java, including preview features to Java 13
Stars: ✭ 3,972 (+15176.92%)
Mutual labels:  ast, syntax-tree, parser
Json To Ast
JSON AST parser
Stars: ✭ 161 (+519.23%)
Mutual labels:  ast, tree, parser
Astexplorer.app
https://astexplorer.net with ES Modules support and Hot Reloading
Stars: ✭ 65 (+150%)
Mutual labels:  ast, syntax-tree, parser
Escaya
An blazing fast 100% spec compliant, incremental javascript parser written in Typescript
Stars: ✭ 217 (+734.62%)
Mutual labels:  ast, syntax-tree, parser
Astexplorer
A web tool to explore the ASTs generated by various parsers.
Stars: ✭ 4,330 (+16553.85%)
Mutual labels:  ast, parser
Php Parser
🌿 NodeJS PHP Parser - extract AST or tokens (PHP5 and PHP7)
Stars: ✭ 400 (+1438.46%)
Mutual labels:  ast, parser
Unist
Universal Syntax Tree used by @unifiedjs
Stars: ✭ 438 (+1584.62%)
Mutual labels:  ast, syntax-tree
Modiscript
Acche din aa gaye
Stars: ✭ 888 (+3315.38%)
Mutual labels:  ast, tree
Ratel Core
High performance JavaScript to JavaScript compiler with a Rust core
Stars: ✭ 367 (+1311.54%)
Mutual labels:  ast, parser
Tenko
An 100% spec compliant ES2021 JavaScript parser written in JS
Stars: ✭ 490 (+1784.62%)
Mutual labels:  ast, parser
Webassemblyjs
Toolchain for WebAssembly
Stars: ✭ 566 (+2076.92%)
Mutual labels:  ast, parser
Verible
Verible is a suite of SystemVerilog developer tools, including a parser, style-linter, and formatter.
Stars: ✭ 384 (+1376.92%)
Mutual labels:  syntax-tree, parser
Node Dependency Tree
Get the dependency tree of a module
Stars: ✭ 383 (+1373.08%)
Mutual labels:  ast, tree
Tiny Compiler
A tiny compiler for a language featuring LL(2) with Lexer, Parser, ASM-like codegen and VM. Complex enough to give you a flavour of how the "real" thing works whilst not being a mere toy example
Stars: ✭ 425 (+1534.62%)
Mutual labels:  ast, parser
Mdast
Markdown Abstract Syntax Tree format
Stars: ✭ 493 (+1796.15%)
Mutual labels:  ast, syntax-tree
Tolerant Php Parser
An early-stage PHP parser designed for IDE usage scenarios.
Stars: ✭ 717 (+2657.69%)
Mutual labels:  ast, parser
Postcss
Transforming styles with JS plugins
Stars: ✭ 25,612 (+98407.69%)
Mutual labels:  ast, parser
Ccalc
Scientific calculator in which you can define new constants and functions
Stars: ✭ 19 (-26.92%)
Mutual labels:  parser, expression
Php Parser
PHP parser written in Go
Stars: ✭ 787 (+2926.92%)
Mutual labels:  ast, parser

NPM

npm version Join the chat at https://gitter.im/KennethanCeyer/PIGNOSE GitHub stars GitHub license

Build Status Coverage Status codecov Maintainability Test Coverage CodeFactor

dependencies Status devDependencies Status


Special lovers ❤️


👏 Example

See demo

Screen Shot


📦 Installation

git

$ git clone [email protected]:KennethanCeyer/metric-parser.git

npm

$ npm install metric-parser

yarn

$ yarn add metric-parser

📃 Getting started

Javascript (Web)

<script src="~/dist/metric.parser.umd.js"></script>
<script>
// { data: {tree object}, code: 0 }
const result = metricParser.convert('1 + (2 + 3)');

// { data: [ 1, '+', 2, '+', 3 ], code: 0 } <= bracket will be optimized
const expression = metricParser.convert(result.data);

// true | false <= true means valid
const valid = metricParser.valid(result.data);
</script>

Typescript

import { convert, valid } from 'metric-parser';

// { data: {tree object}, code: 0 }
const result: ParserGeneralResult = convert('1 + (2 + 3)');

// { data: [ 1, '+', 2, '+', 3 ], code: 0 } <= bracket will be optimized
const expression: string[] = convert(result.data);

// true | false <= true means valid
const valid: boolean = valid(result.data);

NodeJS

const parser = require('metric-parser');

// { data: {tree object}, code: 0 }
const result = parser.convert('1 + (2 + 3)');

// { data: [ 1, '+', 2, '+', 3 ], code: 0 } <= bracket will be optimized
const expression = parser.convert(result.data);

// true | false <= true means valid
const valid = parser.valid(result.data);

⚡️ Type

Tree

Tree is a simple object that converted from AST.

const result = convert('1 + (2 + 3)');
const tree: Tree = result.data;
{
  operator: '+',
  operand1: { value: { type: 'unit', unit: 1 } },
  operand2: {
    operator: '+',
    operand1: { value: { type: 'unit', unit: 2 } },
    operand1: { value: { type: 'unit', unit: 3 } }
  }
}

AST (AbstractSyntaxTree)

AST is the most important object that contains the structure of a formula.

const ast = convert('1 + (2 + 3)', true);

{
  AbstractSyntaxTree {
    type: 1, // operator
    value: '+',
    leftNode: AbstractSyntaxTree {
      type: 2, // value
      value: 1
    },
    rightNode: AbstractSyntaxTree {
      type: 1, // operator
      value: '+',
      leftNode: AbstractSyntaxTree {
        type: 1, // value
        value: 2
      },
      rightNode: AbstractSyntaxTree {
        type: 1, // value,
        value: 3
      }
    }
  }
}

🚩 Roadmap

v0.0.1

  • [x] support typescript
  • [x] support UMD and ES5 module
  • [x] support automated test environment
  • [x] support custom value (custom object as value)
  • [x] support implicit patterns (multiplication omitted, operator aliases)
  • [x] support reference docs
  • [x] improve parser logic based AST
  • [x] improve validation error (parserStack, codes)
  • [x] add unit test with coverage rate over 90%
  • [x] support validation for many cases

v0.1.0

  • [ ] guidelines for developers
  • [ ] guidelines for contributors

v0.2.0

  • [ ] function expression IF(), SUM(), AVG(), _CUSTOM_NAMED_FUNC_()
  • [ ] support custom tree model declaration

v0.3.0

  • [ ] declare variable (operator and value type)

🔍 License

FOSSA Status

The MIT License (MIT)

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].