Liscript — web REPL: kissing, bicycles and excavators



Some time ago I wrote an interpreter listopadovogo language, which is called Liscript. Has published several articles on Habre devoted to the peculiarities of the implementation of the kernel, TCO, GUI REPL-bots, etc. Recently added a web interface REPL-(link at end of article).

Where do the kisses and excavators? I think most well-known acronyms such as KISS (keep it simple stupid, make it simpler, stupid), YAGNI (You ain't gonna need it — You won't need it), as well as the statements of people of varying degrees of greatness about architecture astronauts, "everything should be made as simple as possible, but not simpler", etc.

Let's say your goal is to dig a hole. What are the solutions? To take a shovel and dig yourself — cheap and cheerful, but for a long time and possibly not optimal (depends on your level of proficiency with a shovel and sizes of pits). To give to outsourcing Tajiks (we will not consider here this variant, although I had to mention him). Rent excavator — fast and effective but expensive: petrol/rent, plus not the fact that he will pass at your garden gate, so it is necessary to demolish/repair the fence, etc. it is Also necessary to determine the model (sometimes from 100500 variants), and if you manage it yourself, you have to understand all the levers and the pedals.

Of course, if you are a professional excavator, digging of 200 pits per day, or you aspire to become one, as the initial task (dig a hole) you need not in itself, but as training or demonstration of your skills, then the choice is obvious (there is that question of the model). But even a professional will take a shovel planting flowers.

In General, about the choice of tools for the tasks, and specific (I suspect controversial) decisions I chose in the process of project implementation, under the cut.

Implementation of single-linked list

In Liscript missing the point pairs (conses), so that the basic structure of how code and data list. In the Java version of the interpreter I wrote my own simple class with fields car and cdr. You can take a standard Java collection type is LinkedList or an ArrayList — they probably better optimized in terms of allocations and friendship with the garbage collector. But I choose my own bike, although it's easy to refactor to the second option.

the Tokenizer/Lexer/Parser

This is an example of interesting. You need to read the input text/string and convert it to ready AST (abstract syntax tree), highlighting of text tokens and organizing them into a hierarchical structure. The task is more than well known, there is a whole vast theory of syntactic analysis and parsing, and many library implementations of the various parsers, such as www.antlr.org But I decided to write my simple bike on the destination machine — the Lisp is a very simple grammar and syntax, though of course had to account for multiline string literals and comments. Moreover — such a bike I have 3: in a Haskell implementation (in spite of many ready-made solutions: parsec, attoparsec, etc.), in the core Java implementation and a Swing GUI for syntax highlighting code text.

the

WEB backend


History: this is my first web project to host the application I chose Heroku free plan. Of build systems in a single Java chat I was advised Gradle, not Maven, citing different attractive words. I believe, chose the option on Heroku Gradle-build, and desoprime, skakavica my drive, used the Ratpack (don't know what uses the example of a Maven build, it is possible that the same thing). Because of experience with other web servers (and web technologies in General) I had, I had to make a choice — or do not use this desoprime, and install some kind of Jetty, which IMHO is much more information available on the Internet, or to use Ratpack, ready and configured, but how to deal with it. Chose the second option, among the found examples, two-thirds were Groovy, but eventually managed to figure out how to implement a long synchronous operation, and with the rendering of pages, it was easy.
the

WEB frontend


Here at all just a sea of choices of different technologies for the region booming for years. And the apologists different frameworks prove to the world (and each other) that their choice is better/more effective/promising and the only way to "write WEB in 2017" (C) Each one in its own right, but what choice did I have? To solve purely utilitarian objectives — dig a hole to write the web-Moorethe interface of your REPL.

the
    the
  • to Use Java-frameworks, able to generate the web interface: Vaadin, FX, etc. Heavy powerful excavators that support the paradigm "write once, digging everywhere."
  • the
  • to Use multiple WEB frameworks/libraries, their name is Legion: Angular, React,... Each with its rich the inner world black Jack functionality and whistles.
  • the
  • to Write it yourself on the bare vanilla Javascript / HTML / CSS.

As you probably guessed, I of course chose the third option :). Even without the use of jQuerry, because this machine would also be explored. Without Babel / Webpack and still 100500 fashion at the front of words. For the first time felt the joy of debug for different browsers, including IE, I was forced to sugardaddy in CSS constants instead of declaring them at the beginning of the file, which in itself is pathetic, but IE I do not want to see these ads, and the technology for generating CSS from other formats, as a variety of fashionable frameworks, meant using mentioned frameworks.

But of course I'm not as trashed as you can imagine the cyclist, not the excavator. Paired task the web interface I chose the ready library:

Split-pane

I for REPL and they were very much needed. Powerful frameworks for web GUI implement them in its composition, but excluding heavy equipment, I have considered more than minor finished implementation, and after trying 3-4, chose one. Although she pulls a jQuerry that I don't really like (anymore I still for anything it is not necessary), but reacts much better in terms of responsiveness of the interface. If you have the time/desire, can you rewrite your bike without jQuerry.

code Highlighting

Here, I believe that I was lucky to solve this problem, I immediately found the magnificent library codemirror.net, understood its capabilities, I wrote a plugin for the syntax of their language and theme. Wrote your Cycling parsers/luxury, because this library is simple, lightweight and copes well with their work — as in static text areas and dynamics when editing text the user code.

the

Conclusion


Of course, I'm aware that the above decision taken by me as the least controversial and ambiguous. That can be (and some positions even better) was to use ready-made technological tools. What I have gained by writing your own parsers / luxury? Experience in writing similar bikes on the destination machines, full control of the situation, possibility of easy customization. Lost? Not dealt with ready existing parsers't mastered them yet, and if I have to use in the future — I will have to learn them from scratch. And the same verdict for each of the following specific local objectives. But in any such case, it is necessary to make a choice, so you have to weigh the pros and cons, and take the consequences. What about this do you think?

Main page Liscript
Online REPL
Article based on information from habrahabr.ru

Комментарии

Популярные сообщения из этого блога

Automatically create Liquibase migrations for PostgreSQL

Vkontakte sync with address book for iPhone. How it was done

What part of the archived web