0.1.21 • Published 8 months ago

@fnet/expression v0.1.21

Weekly downloads
-
License
MIT
Repository
gitlab
Last release
8 months ago

@fnet/expression

Introduction

The @fnet/expression project is designed to help users parse and analyze structured expressions that consist of processor and statement components. This tool can be particularly useful for those who need to dissect complex expressions into more manageable parts, allowing for easier understanding and processing.

How It Works

The project works by taking a structured expression and breaking it down into its basic components: processors and statements. It uses a recursive parsing method to handle nested expressions while respecting a maximum depth to prevent too deep recursion. The expression is analyzed to extract all processors, presenting a clear hierarchy and order of the components.

Key Features

  • Recursive Parsing: Efficiently breaks down expressions into individual components, even handling nested structures.
  • Processor Extraction: Gathers all processor elements from the expression, providing an ordered list.
  • Depth Management: Prevents overly deep recursion by setting a limit, ensuring performance and reliability.

Conclusion

The @fnet/expression project is a straightforward and practical tool for parsing and analyzing structured expressions. It offers users a reliable method to dissect intricate expressions into simpler parts, making them easier to work with and understand.

Developer Guide for @fnet/expression

Overview

The @fnet/expression library provides tools to parse and process structured expressions. Built with ease of use in mind, the library focuses on breaking down expression strings into their components and extracting information such as processors and statements from them. This can be particularly useful for applications that utilize scripting or configurations defined in domain-specific languages.

Installation

To use @fnet/expression in your project, you can install it via npm or yarn:

npm install @fnet/expression

or

yarn add @fnet/expression

Usage

The library exposes a straightforward public API for parsing expressions. Below is an example of how you can utilize it within your application:

import parseExpression from '@fnet/expression';

(async () => {
    const expression = 'foo::bar baz::nested quux';
    const parsedResult = await parseExpression({ expression });

    if (parsedResult) {
        console.log(parsedResult.processor); // Output: foo
        console.log(parsedResult.process.order); // Output: ['foo', 'baz']
        console.log(parsedResult.process.statement); // Output: nested quux
    } else {
        console.log('Expression could not be parsed');
    }
})();

Examples

Basic Expression Parsing

import parseExpression from '@fnet/expression';

(async () => {
    const expression = 'action::do_something';
    const parsedResult = await parseExpression({ expression });

    console.log(parsedResult);
    // Output:
    // {
    //     processor: 'action',
    //     statement: 'do_something',
    //     expression: 'action::do_something',
    //     process: {
    //         statement: 'do_something',
    //         order: ['action']
    //     }
    // }
})();

Complex Nested Expressions

import parseExpression from '@fnet/expression';

(async () => {
    const expression = 'outer::inner::deepest';
    const parsedResult = await parseExpression({ expression });

    console.log(parsedResult);
    // Output:
    // {
    //     processor: 'outer',
    //     statement: 'inner::deepest',
    //     expression: 'outer::inner::deepest',
    //     process: {
    //         statement: 'deepest',
    //         order: ['outer', 'inner']
    //     },
    //     next: {
    //         processor: 'inner',
    //         statement: 'deepest',
    //         expression: 'inner::deepest',
    //         next: {
    //             processor: 'deepest',
    //             statement: '',
    //             expression: 'deepest'
    //         }
    //     }
    // }
})();

Acknowledgement

The development of @fnet/expression has been backed by contributions from various developers. The library may use code or draw concepts from external resources, and we extend our gratitude to the authors and maintainers of those projects for their work in advancing open-source software development.

Input Schema

$schema: https://json-schema.org/draft/2020-12/schema
type: object
properties:
  expression:
    type: string
    description: The expression to be parsed in the format of "processor::statement".
required:
  - expression
0.1.20

8 months ago

0.1.21

8 months ago

0.1.18

9 months ago

0.1.19

8 months ago

0.1.17

1 year ago

0.1.16

2 years ago

0.1.15

2 years ago

0.1.14

2 years ago

0.1.13

2 years ago

0.1.12

2 years ago

0.1.11

2 years ago

0.1.10

2 years ago

0.1.9

2 years ago

0.1.8

2 years ago

0.1.7

2 years ago

0.1.6

2 years ago

0.1.5

2 years ago

0.1.4

2 years ago

0.1.3

2 years ago

0.1.2

2 years ago

0.1.1

2 years ago