Code Monkey home page Code Monkey logo

astyle.js's Introduction

AStyle.js

Astyle Code Formatter & Beautifier for C++ within just one js.


Installation

  1. Download the javascript file from the release page. The js file is optimized, about 732KB in size (190KB gzipped) and can format about 20000 lines of C++ code per second. Small impacts on memory usage.
  2. Include the file in the web page where you want to use AStyle to format codes. For Example:
<script language="javascript" src="AStyle_v1.0.js"></script>
  1. Call the formatter somewhere else in your js code.

Usage

High Level API:

/**
 * @param code - Source code, string
 * @param style - allman / bsd / break / java / attach / kr
 *                / stroustrup / whitesmith / vtk / ratliff / gnu / linux
 *                / horstmann / 1tbs / google / mozilla / pico / lisp
 *                @see http://astyle.sourceforge.net/astyle.html#_Basic_Brace_Styles
 * @param indent - count of a layer of indent, between 2 and 20.
 * @param lang - 0 for C/CPP/Objective-C, 1 for C#, 2 for Java
 * @returns Formatted Code.
 *
 * Supports: C, C++, Java, C#, Objective-C
 */
function beautify(code, style, indent, lang);

Low Level API:

astyle_instance.ccall("process", "string", ["string", "string", "string", "string"], [param1, param2, param3, param4])

Where param1..4 are command-line parameters. Accepts the same as those in AStyle itself.

Working with Source

Work on the AStyle Core is not discussed here.
The modified part and also the export logic is at the very bottom of astyle_main.cpp, where you can preprocess the parameters you want to pass from javascript code according to Emscripten and AStyle specifications.
Building the code is quite easy. Just get Emscripten ready and run this command (params can be changed to your flavor):

<path to python2 executable> <path to emcc.py> --emscripten-cxx ASFormatter.cpp ASLocalizer.cpp ASResource.cpp astyle_main.cpp ASBeautifier.cpp ASEnhancer.cpp -std=c++11 -O3 -s INLINING_LIMIT=1 --memory-init-file 0 -s MODULARIZE=1 -s EXPORT_NAME='AStyle'

The release is built under windows with clang as the frontend.

astyle.js's People

Contributors

eliphatfs avatar

Stargazers

Makico 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.