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:
1cmd1 | cmd2 # Standard pipeline, transferring structured data or text streams
2cmd1 |_ cmd2 # Positional pipeline, transferring to specified parameter positions
3cmd1 |> cmd2 # Single dispatch pipeline, looping through list data
4cmd1 |^ cmd2 # PTY pipelineStructured pipelines:
1ls -l | Into.table() | where(size > 5K)
2Fs.ls -l | where(size > 5K) | select(name,size,modified)
3ls -1 |> adb push _ /sdcard/Download/2. Error Handling Operators#
Lumesh has a rich built-in error handling mechanism:
1command ?. # Ignore error
2command ?: e # Error capture or default value
3command ?+ # Print to standard output
4command ?? # Print to error output
5command ?> # Override print (data channel)
6command ?! # Terminate on error (terminate pipeline)3. Delayed Assignment#
Use := for delayed assignment; the expression will not execute immediately:
1let cmd := ls -l # Delayed execution4. Chained Calls#
Supports chained method calls similar to object-oriented languages:
1"hello world".split(' ').join(',')
2data | .filter(x -> x > 0)5. Destructuring Assignment#
Supports destructuring assignment for arrays and maps:
1let [a, b, c] = [1, 2, 3]
2let {name, age} = user_data6. Range Operators#
Provides various range operators:
11..10 # Inclusive of end
21..<10 # Exclusive of end
31..10:2 # With step
41...10 # Directly create an array7. Function Decorators#
Supports function decorator syntax:
1@decorator_name
2@decorator_with_args(param1, param2)
3fn my_function() { ... }8. Pattern Matching#
Built-in powerful pattern matching capabilities, supporting regular expressions:
1match value {
2 pattern1 => result1,
3 pattern2 => result2,
4 _ => default
5}9. Overloaded Operators#
Utilizes regular arithmetic operators to handle more common tasks:
1"1" + [2,3]
2[1,2] + 3
3[1,2] + [3,4,5]
4{a:b} + c
5{a:b} + {c:d}10. Functional Programming#
10...10 | List.filter(x -> x % 2 == 0)
20..10 | .map(x -> x * 2)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#
1# Conditional statements
2if condition { action } else { alternative }
3match expr { a => branchA; ... }
4# Loop statements
5for item in collection { process(item) }
6while condition { body }
7loop { infinite_loop }
8# Simple repetition
9repeat 10 {a += 1}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[1, 2, 3] # Array
2{key: value, name: "test"} # Map
31..10 # Range
41...10 # ArrayFunctions#
- Supports parameter collection and default parameters
- Supports lambda functions
- Supports nested functions
1fn add(x) { x + 1 }
2(x, y) -> x + yModule System#
Supports module import and usage:
1use module_name
2
3Fs.ls("/path") # Use built-in moduleNotes#
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: