6

GitHub - yoav-lavi/melody: Melody is a language that compiles to regular express...

 2 years ago
source link: https://github.com/yoav-lavi/melody
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

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.

warning Melody is very new and is unstable at the moment warning

Examples

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

Batman Theme

16 of "na";

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

// 🦇🦸‍♂️

Turns into

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

Twitter Hashtag

"#";
some of <word>;

// #melody

Turns into

/#\w+/

Introductory Courses

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

// classname 1xx

Turns into

/\w+\s1\d{2}/

Indented Code (2 spaces)

some of match {
  2 of <space>;
}

some of char;
";";

//  let value = 5;

Turns into

/(?:\s{2})+.+;/

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 +
  • over - used with of to express more than an amount of a pattern, equivalent to regex {6,} (assuming over 5 of ...)

Symbols

  • <space> - equivalent to regex \s
  • <newline> - equivalent to regex \n
  • <tab> - equivalent to regex \t
  • <return> - equivalent to regex \r
  • <feed> - equivalent to regex \f
  • <null> - equivalent to regex \0
  • <digit> - equivalent to regex \d
  • <vertical> - equivalent to regex \v
  • <word> - equivalent 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

Syntax Highlighting

VSCode

Get the extension here

Feature Status

white_check_mark - Implemented

hatching_chick - Partially implemented

x - Not implemented

question - Unclear whether this will be implemented

grey_question - Unclear what the syntax will be

Melody Regex Status

5 of "hello"; (?:hello){5} white_check_mark5 to 7 of "A"; A{5,7} white_check_markcapture { ... } (...) white_check_markcapture name { ... } (?<name>...) white_check_markmatch { ... } (?:...) white_check_mark<space>; \s white_check_markA to Z; [A-Z] white_check_marka to z; [a-z] white_check_mark0 to 9; [0-9] white_check_mark// comment

white_check_markstart; ^ white_check_markend; $ white_check_mark<newline>; \n white_check_mark<tab>; \t white_check_mark<return>; \r white_check_mark<feed>; \f white_check_mark<null>; \0 white_check_mark<digit>; \d white_check_mark<vertical>; \v white_check_mark<word>; \w white_check_mark"..."; (raw) ... white_check_mark'...'; (raw) ... white_check_mark'\''; ' white_check_mark"\""; " white_check_mark

support non alphanumeric characters

white_check_mark

output to file

white_check_mark

no color output

white_check_markchar . white_check_marksome of + white_check_mark

syntax highlighting extension

white_check_markover 5 of "A"; A{6,} white_check_mark

enforce group close

hatching_chick

tests

hatching_chicknot <space>; \S xnot <digit>; \D xnot <word>; \W x<backspace> [\b] x

file watcher

x

nested groups (...(...)) x

multiple ranges [a-zA-Z0-9] x

general cleanup and modules

x

auto escape for non Melody patterns

x

rust library / macro

x

TS/JS build step

x

more robust parsing mechanism (ast)

xnot "A"; [^A] grey_questionflags: global, multiline, ... /.../gm... grey_question/* comment */

grey_questionmaybe of ? grey_questionmaybe some of * grey_questioneither of ..., ... | grey_questionany of "a", "b", "c" [abc] grey_question... not before ... ...(?!...) grey_question... not after ... ...(?<!...) grey_question... before ... ...(?=...) grey_question... after ... ...(?<=...) grey_question

(?) *? grey_question

(?) \# grey_question

(?) \k<name> grey_question

(?) \p{...} grey_question

(?) \P{...} grey_question

(?) \uYYYY grey_question

(?) \xYY grey_question

(?) \ddd grey_question

(?) \cY grey_question

(?) \b grey_question

(?) \B grey_question

(?) $1 grey_question

(?) $` grey_question

(?) $& grey_question

(?) x20 grey_question

(?) x{06fa} grey_question

variables / macros

question

regex optimization

question

standard library / patterns

question

reverse compiler

question

Acknowledgments

Melody uses:


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK