Code Monkey home page Code Monkey logo

resw's Introduction

RESW

An experimental crate for writing JS from an AST provided by the RESSA crate.

Since RESSA's primary purpose is to enable developers to write their JS dev tools in Rust, this is an important part of that eco system. The experimental status of this project is due to the current instability in both RESS and RESSA, when pinned to the versions listed in this crate's Cargo.toml the behavior should be sound.

Basic Usage

Here is a trivial example of how you might use this crate.

// example.js
function thing() {
    return 'stuff'
}

Using the above example, we can create a program that will just parrot out the input.

use resw::Writer;
use ressa::Parser;
use srd::fs::{read_to_string, File);

fn main() {
    let js = read_to_string("example.js").expect("failed to read example.js");
    let p = Parser::new(&js).expect("failed to create parser);
    let f = Filem:create("example.out.js");
    let mut w = Writer::new(f);
    for part in p {
        w.write_part(part).expect(&format!("failed to write part {:?}", part));
    }
}

If we were to run the above, assuming that example.js exists, it would write the following in example.out.js.

// example.js
function thing() {
    return 'stuff';
}

not super exciting but I did say the example would be trivial. Check out the examples directory for a few more, slightly less trivial examples.

Notes

Running the Examples

cargo run --example snippet_writer will expect a script unless you pass an argument "module" like this cargo run --example snippet_writer -- module

That's Like Your Opinion... Man

Currently I have made some personal style choices for the generated output. My ultimate vision for this crate is to allow for configuring a large number of these decisions but until RESSA has a chance to add some needed features they will not be configurable. Here are a few things I can think of right now.

  • comments are never included in the output
  • empty function bodies are two braces on the same line seperated by a single space
  • empty if, try, and loop bodies are two braces seperated by an empty new line
  • new lines are always \n
  • function or function identifiers are writted with no space before (
  • function parameter lists are not surrounded with empty space
  • arry and object literals have trailing commas
  • object literals are always one property per line

Building on unstable foundation

I have some ambitous things in store for RESS/RESSA for the next year, changes there will ultimatly break what this crate can do but with time, those changes will greatly enhance this crates features. Some notible things in the works:

RESS

  • a new allocation free version of the Scanner has been implemented but needs testing
  • I would like to add Typescript support

RESSA

  • Work has started to include the location of all node items
    • this will allow RESW to increase the fedility of the generated JS

Contributing

If you are interested in helping, it woud be appreciayed. At this point I would encourage you to look at improving RESS or RESSA before trying to find a way to contribut here. If you have a contribution I ask that you please open an issue before digging too deep into it so we can both be on the same page.

Some places that would be great to see some help

  • examples
    • My imagination is only so big, even just ideas for dev tools that might need a writer (that aren't a bable clone or js minifier) would be amazing
    • If you wanted to build a JS minifier I would be truely flattered
      • Though currently there is no mechanizism not include new line characters

resw's People

Contributors

freemasen avatar

Watchers

 avatar  avatar

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.