• Stars
    star
    468
  • Rank 93,248 (Top 2 %)
  • Language
    JavaScript
  • License
    MIT License
  • Created over 10 years ago
  • Updated about 7 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Programming language compiling to JavaScript

Earl Grey

Join the chat at https://gitter.im/breuleux/earl-grey

Earl Grey (website) is a new language that compiles to JavaScript (ES6). Here's a quick rundown of its amazing features:

  • Python-like syntax
  • Fully compatible with the node.js ecosystem
  • Generators and async/await (no callback hell!)
  • Powerful, deeply integrated pattern matching
    • Used for assignment, function declaration, looping, exceptions...
  • A DOM-building DSL with customizable behavior
  • A very powerful hygienic macro system!
    • Define your own control structures or DSLs
    • Macros integrate seamlessly with the language
    • Macro libraries! Test with earl-mocha, build with earl-gulp, make dynamic pages with earl-react, etc.
  • And much more!

Resources

Examples

Counting all words in a block of test. Note that count-words is a variable name, not a subtraction (it is equivalent to the name countWords, if that's the notation you prefer).

count-words(text) =
   counts = new Map()
   words = text.split(R"\W+")
   words each word ->
      current-count = counts.get(word) or 0
      counts.set(word, current-count + 1)
   consume(counts.entries()).sort(compare) where
      compare({w1, c1}, {w2, c2}) = c2 - c1

{x, y, ...} is the notation for arrays in Earl Grey. Objects are denoted {field = value, field2 = value2, ...}

Generators: the following defines a generator for the Fibonacci sequence and then prints all the even Fibonacci numbers less than 100. It shows off a little bit of everything:

gen fib() =
   var {a, b} = {0, 1}
   while true:
      yield a
      {a, b} = {b, a + b}

fib() each
   > 100 ->
      break
   n when n mod 2 == 0 ->
      print n

The each operator accepts multiple clauses, which makes it especially easy to work on heterogenous arrays.

Asynchronous: EG has async and await keywords to facilitate asynchronous programming, all based on Promises. Existing callback-based functionality can be converted to Promises using promisify:

require: request
g = promisify(request.get)

async getXKCD(n = "") =
   response = await g('http://xkcd.com/{n}/info.0.json')
   JSON.parse(response.body)

async:
   requests = await all 1..10 each i -> getXKCD(i)
   requests each req -> print req.alt

Classes:

class Person:
   constructor(name, age) =
      @name = name
      @age = age
   advance-inexorably-towards-death(n > 0 = 1) =
      @age += n
   say-name() =
      print 'Hello! My name is {@name}!'

alice = Person("alice", 25)

Pattern matching acts like a better switch or case statement. It can match values, types, extract values from arrays or objects, etc.

match thing:
   0 ->
      print "The thing is zero"
   < 0 ->
      print "The thing is negative"
   R"hello (.*)"? x ->
      ;; note: R"..." is a regular expression
      print 'The thing is saying hello'
   Number? x or String? x ->
      print "The thing is a number or a string"
   {x, y, z} ->
      print 'The thing is an array of three things, {x}, {y} and {z}'
   {=> name} ->
      print 'The thing has a "name" field'
   else ->
      print "I don't know what the thing is!"

More Repositories

1

jurigged

Hot reloading for Python
Python
993
star
2

terminus

Terminal supporting inline HTML
JavaScript
239
star
3

quaint

The Quaint markup language
q
33
star
4

liso

Operator syntax for the Lisp family of languages (Racket implementation)
Racket
31
star
5

py-quaint

Terse and highly extensible markup language
Python
27
star
6

hrepr

HTML representation for Python objects.
HTML
13
star
7

coleo

The nicest way to develop a command-line interface in Python
Python
10
star
8

engage

Incremental build system
8
star
9

breakword

Mixing breakpoints with print debugging
Python
8
star
10

ovld

Advanced multiple dispatch for Python functions
Python
8
star
11

synecure

Simple rsync-based synchronization CLI program
Python
7
star
12

adhoc

Command-line utility to run code snippets in arbitrary languages on a per-line basis.
Ruby
6
star
13

ptera

Query and override internal variables in your programs
Python
5
star
14

exc

Exception class for Python that can be subclassed with __getitem__
Python
5
star
15

buche

Tool to display rich logs.
CSS
5
star
16

earl-react

Earl Grey macros for React
5
star
17

bugland

Dataset generator
Python
5
star
18

starbear

Create simple local web apps in Python
Python
5
star
19

old_quaint

New programming language
Python
4
star
20

teacup

Short implementation of a simple programming language.
JavaScript
4
star
21

ug

The Unholy Grail language
Python
3
star
22

inquirer-shortcuts

Promise wrapper for inquirer
JavaScript
3
star
23

earl-shapely

Earl Grey macros for shapely
3
star
24

earl-gulp

Earl Grey macros for gulp
2
star
25

histocit

Track number of citations on Google Scholar
Python
1
star
26

kaiser

Serialization library
JavaScript
1
star
27

earlify

browserify transform for Earl Grey
1
star
28

earl-autodiff

Autodiff for Earl Grey
1
star
29

earl-debug

Debugging tools for Earl Grey
1
star
30

descr

Customizable HTML pretty-printing
Python
1
star
31

pytest-ptera

Test using Ptera probes
Python
1
star
32

earl-grey-mode

earl-mode for Emacs
Emacs Lisp
1
star
33

tlaloc

Python
1
star
34

hyper-replace

Replace patterns in strings by arbitrary objects
JavaScript
1
star
35

fluogames

IRC bot for games
Python
1
star
36

milatools-bk

Tools to connect to and interact with the Mila cluster
Python
1
star
37

quaint-katex

Inline math for Quaint using KaTeX
JavaScript
1
star
38

generator-earl-package

Generate scaffolding for an npm package written in Earl Grey.
JavaScript
1
star
39

ursa-major

Define structs with field types, validation and serialization
1
star
40

js-spacebear

SPACE BEAR
1
star
41

opg

Operator precedence grammars
JavaScript
1
star
42

codefind

Find code objects and their referents
Python
1
star
43

myia_debug

Debugging tools for Myia
Python
1
star
44

colonel

Graph-based virtual machine
Python
1
star
45

earl-mocha

Earl Grey wrapper around the Mocha testing framework
1
star