All Projects → harpocrates → language-rust

harpocrates / language-rust

Licence: BSD-3-Clause license
Parser and pretty-printer for the Rust language

Programming Languages

haskell
3896 projects
Yacc
648 projects
Logos
282 projects
rust
11053 projects

Projects that are alternatives of or similar to language-rust

gogrep
Syntax-aware Go code search, based on the mvdan/gogrep
Stars: ✭ 25 (-67.95%)
Mutual labels:  syntax, ast
php-ast-reverter
Reverts the php-ast AST back into (somewhat) PSR-compliant code
Stars: ✭ 49 (-37.18%)
Mutual labels:  ast, pretty-printer
coAST
Universal and language-independent abstract syntax tree
Stars: ✭ 30 (-61.54%)
Mutual labels:  syntax, ast
asty
Abstract Syntax Tree (AST) Data Structure
Stars: ✭ 28 (-64.1%)
Mutual labels:  syntax, ast
Modiscript
Acche din aa gaye
Stars: ✭ 888 (+1038.46%)
Mutual labels:  syntax, ast
React Ast
render abstract syntax trees with react
Stars: ✭ 160 (+105.13%)
Mutual labels:  syntax, ast
Astq
Abstract Syntax Tree (AST) Query Engine
Stars: ✭ 89 (+14.1%)
Mutual labels:  syntax, ast
Phpgrep
Syntax-aware grep for PHP code.
Stars: ✭ 185 (+137.18%)
Mutual labels:  syntax, ast
rehype-dom
HTML processor to parse and compile with browser APIs, powered by plugins
Stars: ✭ 20 (-74.36%)
Mutual labels:  ast
cheatsheet-python-A4
📖 Advanced Python Syntax In A4
Stars: ✭ 96 (+23.08%)
Mutual labels:  syntax
csscomplete.vim
Update the bult-in CSS complete function to latest CSS standard.
Stars: ✭ 61 (-21.79%)
Mutual labels:  syntax
colocat
Fegeya Colocat, Colorized 'cat' implementation. Written in C++17.
Stars: ✭ 14 (-82.05%)
Mutual labels:  syntax
subpy
Python subsets
Stars: ✭ 41 (-47.44%)
Mutual labels:  ast
explain-rs
A library which finds language features in rust code and provides resources on them.
Stars: ✭ 38 (-51.28%)
Mutual labels:  syntax
calamity-atom
A purple dark theme with medium to high contrast for the Atom editor ⚛️
Stars: ✭ 12 (-84.62%)
Mutual labels:  syntax
gox
JSX for Go
Stars: ✭ 165 (+111.54%)
Mutual labels:  ast
venusscript
A dynamic, interpreted, scripting language written in Java.
Stars: ✭ 17 (-78.21%)
Mutual labels:  ast
lilt
LILT: noun, A characteristic rising and falling of the voice when speaking; a pleasant gentle accent.
Stars: ✭ 18 (-76.92%)
Mutual labels:  ast
chestnut.vim
Minimal syntax highlighting for 16-color terminals.
Stars: ✭ 31 (-60.26%)
Mutual labels:  syntax
macro-visit
A macro-based generic visitor generator
Stars: ✭ 23 (-70.51%)
Mutual labels:  ast

Parser and pretty printer for Rust Build Status Windows build status Hackage Version

language-rust aspires to efficiently and accurately parse and pretty print the Rust language. The underlying AST structures are also intended to be as similar as possible to the libsyntax AST that rustc itself uses.

A typical use looks like:

>>> :set -XTypeApplications +t
>>> import Language.Rust.Syntax

>>> -- Sample use of the parser
>>> import Language.Rust.Parser
>>> let inp = inputStreamFromString "fn main () { println!(\"Hello world!\"); }"
inp :: InputStream
>>> let sourceFile = parse' @(SourceFile Span) inp
sourceFile :: SourceFile Span

>>> -- Sample use of the pretty printer
>>> import Language.Rust.Pretty
>>> pretty' sourceFile
fn main() {
  println!("Hello world!");
}
it :: Doc b

Building

Cabal

With Cabal and GHC, run

cabal install happy --constraint 'happy >= 1.19.8'
cabal install alex
cabal configure
cabal build

Stack

With the Stack tool installed, run

stack init
stack build

The second command is responsible for pulling in all of the dependencies (including executable tools like Alex, Happy, and GHC itself) and then compiling everything. If Stack complains about the version of Happy installed, you can explicitly install a recent one with stack install happy-1.19.8.

Evolution of Rust

As Rust evolves, so will language-rust. A best effort will be made to support unstable features from nightly as they come out, but only compatibility with stable is guaranteed. The last component of the version number indicates the nightly Rust compiler version against which tests were run. For example, 0.1.0.26 is tested against rustc 1.26.0-nightly.

Bugs

Please report any bugs to the github issue tracker.

Parser

Any difference between what is accepted by the rustc parser and the language-rust parser indicates one of

  • a bug in language-rust (this is almost always the case)
  • a bug in rustc
  • that there is a newer version of rustc which made a breaking change to this syntax

If the AST/parser of rustc changes, the rustc-tests test suite should start failing - it compares the JSON AST debug output of rustc to our parsed AST.

Pretty printer

For the pretty printer, bugs are a bit tougher to list exhaustively. Suggestions for better layout algorithms are most welcome! The fmt-rfcs repo is loosely used as the reference for "correct" pretty printing.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].