Melody – a language that compiles to regular expressions

75
Melody – a language that compiles to regular expressions

code exmaple

Melody is a language designed to compile to and maintain a 1-1 relationship with regular expressions, while being more readable and maintainable.

The current goal is supporting the JavaScript implementation of regular expressions.

⚠️ Melody is very new and is unstable at the moment ⚠️

Examples

Note: these are for the currently supported syntax and may change

Batman Theme

;
“batman”;
}

// 🦇🦸‍♂️”>

16 of "na";

2 of match {
  space>;
  "batman";
}

// 🦇🦸‍♂️

Turns into

/(?:na){16}(?:sbatman){2}/

Twitter Hashtag

;

// #melody”>

"#";
some of word>;

// #melody

Turns into

Introductory Courses

;

// classname 1xx”>

some of word>;
space>;
"1";
2 of digit>;

// classname 1xx

Turns into

Install

From Source

git clone https://github.com/yoav-lavi/melody.git
cd melody
cargo install --path .

CLI Usage

melody [OPTIONS] PATH>

OPTIONS:
  -f, --file FILE>    write to an output file
  -n, --no-color       print output with no color
  -V, --version        print version information
  -h, --help           print help information

Keywords

  • of – used after a number or a range and before a sequence to be matched, e.g. 5 of "A";, equivalent to regex {5}
  • to – used to create a range (either as a quantifier or as a character range), e.g. 5 to 9, equivalent to regex {5,9} if before an of or [5-9] otherwise
  • capture – used to open a capture or named capture block, equivalent to regex (...)
  • match – used to open a match block, equivalent to regex (?:...)
  • start – matches the start of the string, equivalent to regex ^
  • end – matches the end of the string, equivalent to regex $
  • char – matches a single character, equivalent to regex .
  • some – used with of to express 1 or more of a pattern, equivalent to regex +

Symbols

  • – equavalent to regex s
  • – equavalent to regex n
  • – equavalent to regex t
  • – equavalent to regex r
  • – equavalent to regex f
  • – equavalent to regex
  • – equavalent to regex d
  • – equavalent to regex v
  • – equavalent to regex w

Concepts

  • "..." or '...' – used to mark a literal part of the match

Extras

  • // – used to mark comments

File Extension

The Melody file extension is .mdy

Feature Status

– Implemented

🐣 – Partially implemented

– Not implemented

– Unclear whether this will be implemented

– Unclear what the syntax will be

Melody Regex Status
5 of "hello"; (?:hello){5}
5 to 7 of "A"; A{5,7}
capture { ... } (...)
capture name { ... } (?...)
match { ... } (?:...)
; s
A to Z; [A-Z]
a to z; [a-z]
0 to 9; [0-9]
// comment
start; ^
end; $
; n
; t
; r
; f
;
; d
; v
; w
"..."; (raw)
'...'; (raw)
'''; '
"""; "
support non alphanumeric characters
output to file
no color output
char .
some of +
enforce group close 🐣
tests 🐣
not ; S
not ; D
not ; W
[b]
file watcher
nested groups (...(...))
multiple ranges [a-zA-Z0-9]
general cleanup and modules
auto escape for non Melody patterns
syntax highlighting extension
rust library / macro
TS/JS build step
more robust parsing mechanism (ast)
not "A"; [^A]
flags: global, multiline, ... /.../gm...
/* comment

Read More

Vanic
WRITTEN BY

Vanic

“Simplicity, patience, compassion.
These three are your greatest treasures.
Simple in actions and thoughts, you return to the source of being.
Patient with both friends and enemies,
you accord with the way things are.
Compassionate toward yourself,
you reconcile all beings in the world.”
― Lao Tzu, Tao Te Ching