Coder Social home page Coder Social logo

fil's Introduction

Fil

Live coding in your browser with your favourite language.

http://fatiherikli.github.io/fil/

fil

Features

  • Currently supports Python, Ruby, Javascript, and Brainfuck.
  • Runs on web workers.
  • Uses localStorage API for your changes.

Implementation

  • Uses Skulpt for Python interpreter.
  • Uses Opal for Ruby interpreter.
  • Built with React and Redux.

Todo

  • Languages
    • LiveScript
    • SibilantJS or LispyScript
    • Elm-lang
    • Any language you want
  • Build electron package.

Development

Clone the repository and run the following commands.

$ npm install
$ bower install
$ gulp build

After the installation, you can open index.html in your browser. Also you can run gulp watch command to listen and compile your changes.

Adding a new interpreter

Fil speaks with web workers to interpret the source codes. The workers listen message event for source code, and stream with stringified JSON object for the output of program.

The message should be a plain text, like this:

puts "hey".upcase

After the receiving, the worker will stream stringified json objects with type and data keys.

JSON.stringify({
    type: "stdout",
    data: "HEY"
})

The key of the object may be:

key description
stdout To print to the console
stderr To show warning message
exit To finish program

Lets create our worker.

// workers/markdown.js 
let sendMessage = (name, message) => {
  self.postMessage(JSON.stringify({
    type: name,
    data: message
  }));
}

let run = source => {
  var parser = new Markdown(),
      output;
  try {
    output = parser.parse(source)
    sendMessage('stdout', output);
  } catch (e) {
    sendMessage('stderr', {
      exception: 'ParseError',
      description: String(e)
    });
  }
  sendMessage('exit');
}

self.addEventListener('message', (e) => run(e.data));

After then, we should define this worker in /interpreters.yaml.

...
markdown:
  description: "Markdown"
  extension: "md"
  workerPath: "build/markdown.worker.js"
  editorMode: "markdown"
  includes:
  	- '{bowerPath}markdown-parser/src/markdow.min.js'

The configuration object may contains the following values:

key description
description Name of your interpreter that will shown on the console.
extension File extensions will associated with the interpreter.
workerPath Worker file. This file will be generated with gulp buildWorkers command.
editorMode The mode of ACE Editor.
includes The scripts will be concatenated with your worker.
parsingErrors To keep apart the syntax errors and internal errors of interpreter.

Now we can build our new interpreter.

$ gulp buildWorkers

Using gulpfile ~/projects/fil/gulpfile.js
Starting 'buildWorkers'...
Finished 'buildWorkers' after 29 ms

That's it.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.