@fnet/expression
v0.1.23
Published
## 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 in
Downloads
453
Readme
@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