LamPlus Language Extension
A Visual Studio Code extension providing syntax highlighting and language support for the LamPlus functional programming language.
Features
- Syntax Highlighting: Full syntax highlighting for LamPlus language constructs
- Auto-completion: Bracket and quote auto-completion
- Comment Support: Line comments using
#
- Code Folding: Support for folding code blocks
- File Extensions: Supports
.lam and .lamp files
Language Features
LamPlus is a functional programming language with the following key features:
Keywords
- Definitions:
def , fail , type , rec , effect
- Control Flow:
main , let , in , switch , on , match , with , handle , return
- Lambda:
\ (backslash for lambda expressions)
Types
- Function Types:
A -> B
- Effect Types:
A ~> B
- Sum Types:
+ {'label1: Type1, 'label2: Type2}
- Product Types:
(Type1, Type2, Type3)
- Type Parameters:
Type[T1, T2]
Identifiers
- Global Types/Functions: Start with uppercase letter (e.g.,
List , Option )
- Local Variables: Start with lowercase letter or underscore (e.g.,
x , _temp )
- Effects: Start with
$ (e.g., $Console , $IO )
- Labels: Start with
' (e.g., 'some , 'none )
Operators
-> : Function type arrow
~> : Effect type arrow
<~ : Resume operator
= : Assignment
: : Type annotation
| : Pattern alternative
+ : Sum type constructor
Example Code
# Type definitions
type Option[T] = + {'some: T, 'none: ()}
type List[T] = + {'cons: (T, List[T]), 'nil: ()}
# Effect definition
effect $Console: String ~> ()
# Function definition
def map[A, B]: (A -> B, List[A]) -> List[B] =
\f. \lst.
match lst with {
'nil x: 'nil (),
'cons (head, tail): 'cons (f head, map f tail)
}
# Main function with effects
main: () =
let numbers: List[Int] = 'cons (1, 'cons (2, 'nil ())) in
handle
$Console "Hello, LamPlus!"
with {
$Console msg k:
let () = print msg in k (),
return x: x
}
Installation
- Download and install the extension from the VS Code Marketplace
- Open any
.lam or .lamp file to see syntax highlighting in action
Development
To develop this extension:
- Clone this repository
- Open in VS Code
- Press
F5 to open a new Extension Development Host window
- Open a
.lam file to test the syntax highlighting
Language Grammar
This extension is based on a Lark parser grammar that defines the complete syntax of the LamPlus language. The TextMate grammar provides syntax highlighting for:
- Keywords and control structures
- Type definitions and annotations
- Function definitions and lambda expressions
- Pattern matching constructs
- Effect definitions and handlers
- Comments and documentation
Contributing
Contributions are welcome! Please feel free to submit issues and pull requests.
License
MIT License - see LICENSE file for details.
| |