Skip to content

BrewingWeasel/lilac

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

32 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Lilac

A simple string manipulation language with a focus on pattern matching

pattern greeting = ("hello" | "hi"):lower
pattern introduction = ("my name is" | "i'm" | "i am"):lower

def main(($greeting + ", ")? + $introduction + " " + name)
	"Nice to meet you, " + name + "!"
where 
	main("Hi, I'm Bob") == "Nice to meet you, Bob!";
	main("my name is Alice") == "Nice to meet you, Alice!";
end

Features

Beautiful linting & error messages

error_messages

Inline tests

Define tests in where blocks at the end of functions:

def replace_separator(content + ";" + rest, new_separator)
	content + new_separator + replace_separator(rest, new_separator)
end

def replace_separator(content, _new_separator)
	content
where
	replace_separator("a;b;c", ",") == "a,b,c";
	replace_separator("one;two;three;four", "|") == "one|two|three|four";
	# those will pass, but this test will fail
	replace_separator("a|b;c", ",") == "a,b,c";
end

and test them with lilac test: testing

Powerful pattern matching

def variable("My name is " + name + "!")
	"Your name is " + name + "."
where
	variable("My name is Alice!") == "Your name is Alice.";
end

def optional("My name is " + name + "!"?)
	"Your name is " + name + "."
where
	optional("My name is Alice!") == "Your name is Alice.";
	optional("My name is Bob") == "Your name is Bob.";
end

def transform_case("my name is ":lower + name + "!")
	"Your name is " + name + "."
where
	transform_case("MY name IS Alice!") == "Your name is Alice.";
end

def either(("my name is " | "i'm " | "i am "):lower + name + "!")
	"Your name is " + name + "."
where
	either("I'm Alice!") == "Your name is Alice.";
	either("My name is Bob!") == "Your name is Bob.";
end

def as_pattern("My name is " + (_name + ("!" | ".")) as name_with_punctuation )
	"Your name is " + name_with_punctuation
where
	as_pattern("My name is Alice!") == "Your name is Alice!";
	as_pattern("My name is Alice.") == "Your name is Alice.";
end

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors