Introduction to Lumesh Syntax Features
Lumesh is a modern shell and scripting language that implements complex expression parsing using a Pratt parser.
Unique Syntax Features
1. Multiple Pipeline Operators
Unlike traditional shells, Lumesh provides various types of pipelines:
cmd1 | cmd2 # Standard pipeline, transferring structured data or text streams |
Structured pipelines:
ls -l | Into.table() | where(size > 5K) |
2. Error Handling Operators
Lumesh has a rich built-in error handling mechanism:
command ?. # Ignore error |
3. Delayed Assignment
Use :=
for delayed assignment; the expression will not execute immediately:
let cmd := ls -l # Delayed execution |
4. Chained Calls
Supports chained method calls similar to object-oriented languages:
"hello world".split(' ').join(',') |
5. Destructuring Assignment
Supports destructuring assignment for arrays and maps:
let [a, b, c] = [1, 2, 3] |
6. Range Operators
Provides various range operators:
1..10 # Inclusive of end |
7. Function Decorators
Supports function decorator syntax:
@decorator_name |
8. Pattern Matching
Built-in powerful pattern matching capabilities, supporting regular expressions:
match value { |
9. Overloaded Operators
Utilizes regular arithmetic operators to handle more common tasks:
"1" + [2,3] |
10. Functional Programming
0...10 | List.filter(x -> x % 2 == 0) |
Lumesh includes a wealth of practical function libraries to facilitate convenient functional programming, such as:
- Collection Operations:
List.reduce, List.map
- File System:
Fs.ls, Fs.read, Fs.write
- String Handling:
String.split, String.join
, regex module, formatting module - Time Operations:
Time.now, Time.format
- Data Conversion: Into module, From module
- Mathematical Calculations: Complete mathematical function library
- Logging: Log module
- UI Operations:
Ui.pick, Ui.confirm
Control Flow Structures
# Conditional statements |
Expression Precedence
Lumesh uses a precisely defined operator precedence system:
- Assignment operators (
=
,:=
,+=
, etc.) - Priority 1 - Redirection and pipeline (
|
,>>
,>!
) - Priority 2 - Error handling (
?.
,?+
,??
) - Priority 3 - Lambda expressions (
->
) - Priority 4 - …
Data Types
Strings
Supports three types of strings:
- Double-quoted strings:
"hello world"
- Raw strings:
'raw string'
- Template strings:
`template $variable`
Collection Types
[1, 2, 3] # Array |
Functions
- Supports parameter collection and default parameters
- Supports lambda functions
- Supports nested functions
fn add(x) { x + 1 } |
Module System
Supports module import and usage:
use module_name |
Notes
The syntax design of Lumesh integrates features of modern programming languages with the practicality of shell scripting. Its unique pipeline operators, error handling mechanisms, and chained call syntax are the biggest differences from traditional shells.
The parser uses the Pratt algorithm to support complex expression nesting and precedence handling.
Learn more: