Hello! In this article I want to introduce you to my language -
ColaScript . In a nutshell, this is a new syntax language that is translated into JavaScript. I will begin by telling about the reasons for the emergence of this language.
Causes of
Why do we need languages translated to JavaScript?
For me personally, the benefit of using such languages is, of course, first of all, syntactic sugar, which allows reducing the amount of code. Secondly, it is structural (OOP, modules, packages ...), which is not so easy to achieve in pure JavaScript. At the moment there are 3 languages with almost all of the listed qualities:
CoffeeScript
This is the very first language of this type that I learned about. At the moment, there are a large number of syntax chips in this language and there is OOP in the person of classes. The general syntax style in CoffeeScript is the same as in Ruby and Python, it looks cool, but personally I wanted to see all the same features, but with a C-like syntax. Also in CoffeeScript there is no source / module connection from the code.
TypeScript
TypeScript is a language developed by Microsoft that has static typing, implementation of OOP and connection of modules. In terms of structure, everything is fine, but there is no sugar syntax.
')
Dart
My first acquaintance with this language took place soon after the appearance of its first version: the language was still raw, and even then I myself didn’t really understand why it was needed. In the summer of last year, I decided to see what happened to this language - that was what was needed: OOP, packages (even with my manager), a good standard library and syntactic sugar, from which I was particularly impressed with the cascade operator:
query("#myElement") ..innerHtml = "Hello World!" ..style.backgroundColor = "red";
Dart language, though compiled into JavaScript, but without backward compatibility with it. In particular, this leads to a great weight of runtime and libraries, as well as difficulties in working with existing JavaScript code.
Eventually
As a result, I was overwhelmed by the desire to create my own language, which borrows the best sides of the three languages listed above. So ColaScript was invented.
A little bit about the creation process
The basis was taken by a tool such as
UglifyJS . UglifyJS is designed to compress JavaScript code, for this it parses the code and works with the
AST tree. My task was to modify the parser for the new syntax, as well as directly writing the ColaScript-AST translator in JavaScript-AST, everything else in UglifyJS is already there. The parser has been enhanced to support both ColaScript and JavaScript at the same time, this is done so that you can easily connect libraries and frameworks written in JavaScript.
What happened
You can see the result of my work on
github , you can play
around with the language live
here . At the moment, only the first development stage has been completed and the language has not yet had any particular advantages over the same CoffeeScript, TypeScript and Dart, but there are still many ideas for implementation that are described
here .
Just a small code example:
@use strict main(){ console.log(" Hello World! This is simple example for Habrahabr.ru! PS I love haters so much :-) @{Date()} "); }
Translation result:
"use strict"; window.addEventListener("DOMContentLoaded", function main() { console.log("\nHello World!\nThis is simple example for Habrahabr.ru!\n\nP.S. I love haters so much :-)\n" + Date() + "\n\n"); }, false);
Waiting for your opinions about the language. Thank you all for your attention.