A fault-tolerant, recursive-descent parser for Ara Programming Language 🌲

Related tags

Parsing parser
Overview

Ara Parser

Actions Status Crates.io Docs

A fault-tolerant, recursive-descent parser for Ara Programming Language 🌲

Note: This project is a hard-fork of php-rust-tools/parser

Special thanks to the original authors for their work.


Usage

Add ara_parser to your Cargo.toml, and you're good to go!

[dependencies]
ara_parser = "0.6.3"

Example

use ara_parser::parser;
use ara_reporting::builder::CharSet;
use ara_reporting::builder::ColorChoice;
use ara_reporting::builder::ReportBuilder;
use ara_reporting::error::Error;
use ara_source::loader::load_directories;

fn main() -> Result<(), Error> {
   let source_map = load_directories("/path/to/project", vec!["src/"]).unwrap();

   match parser::parse_map(&source_map) {
      Ok(tree_map) => tree_map.trees.iter().for_each(|tree| {
         println!("{:#?}", tree.definitions);
      }),
      Err(report) => {
         ReportBuilder::new(&source_map)
                 .with_charset(CharSet::Unicode)
                 .with_colors(ColorChoice::Always)
                 .print(report.as_ref())?;
      }
   }

   Ok(())
}

Documentation

See the documentation for more information.

License

Licensed under either of

at your option.

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

Credits

Comments
  • add reverse spread operator

    add reverse spread operator

    Hey hi !

    Following our discussion on Mastodon, I'm opening this issue to discuss a new feature.

    The idea would be to have a spread operator, but in reverse direction.

    Just like we have the spread operator which spread from the left to the right:

    $a = range(0, 3);
    var_dump(...$a); // Print 0, 1, 2, 3
    

    We could have:

    $a = range(0, 3);
    var_dump($a...); // Print 3, 2, 1, 0
    

    This reverse operator would spread an iterable from the right to the left.

    Let me know what you think about this idea, this is something that would be very cool to have !

    Thanks!

    opened by drupol 5
  • remove `fn` type, and support spreading types.

    remove `fn` type, and support spreading types.

    currently, to refer to a Closure, you can use fn type, such as:

    function foo(
      (fn(int): string) $fun
    ): void {}
    

    this is okay, but there's a problem: what about Closure?

    Closure is the actual type behind fn, all of these are instances of Closure:

    $a = fn(int $a): int => $a;
    $c = foo(...);
    $b = $foo(...);
    $f = $foo->bar(...);
    $b = $bar::foo(...);
    

    so let's just use Closure instead of introducing fn type!

    but! there's another problem, Closure is not generic, the __invoke method of a closure has a signature along the lines of:

    public function __invoke(mixed ...$args): mixed { .. }
    

    tho, not really, because it is kinda magically created for every instance of a Closure, to match the parameter count, type, ..etc.

    so how can we make Closure generic?

    well, like this!

    final class Closure<I as (), O> {
      public function __invoke(...I $arguments): O {}
    }
    

    note: ...I is not supported by Ara currently, so we need to add support for it, but only in definition sources, Ara code shouldn't be written like that.

    so you can type the same code above as:

    function foo(
      Closure<(int), string> $fun
    ): void {}
    

    $fun here is an instance of Closure where I = (int) and O = string, i.e:

    final class Closure {
      public function __invoke(int $arguments): string {}
    }
    
    opened by azjezz 2
  • allow all modifiers everywhere

    allow all modifiers everywhere

    we currently group modifiers differently depending on their use case, which makes it so that this is an error:

    final public static class Bar {}
    

    while it is a compile error, we shouldn't error for this in the parser.

    this will be handled by the analyzer, which allows us to analyze more issues at once.

    opened by azjezz 1
  • add ranges

    add ranges

    $a = ..;
    $a = 1..;
    $a = ..100;
    $a = ..=100;
    $a = 1..100;
    $a = 1..=100;
    

    ref: https://doc.rust-lang.org/reference/expressions/range-expr.html ref: https://github.com/azjezz/psl/pull/378 ref: https://github.com/azjezz/psl/pull/380

    opened by azjezz 1
  • chore: extract some common logics on class definition

    chore: extract some common logics on class definition

    The definitions of ClassDefinitionBody, ClassDefinitionExtends and ClassDefinitionImplements were duplicated in two different places. This change just extracted those logics into new functions, to be used in both places. Nothing functional was changed.

    opened by KennedyTedesco 0
  • implement `Debug` for nodes.

    implement `Debug` for nodes.

    Debug should be implemented manually for all nodes.

    blocks should always be replaced with { /* ... */ }

    final class Foo extends Bar implements Baz { /* ... */ }
    
    abstract class Bar { /* ... */ }
    
    function foo(string $bar): int { /* ... */ }
    
    concurrently { /* ... */ }
    
    if $foo { /* ... */ }
    
    match $bar { /* ... */ }
    
    async $bar;
    
    await $baz;
    
    foo::<T>($something);
    
    opened by azjezz 0
Releases(0.6.3)
  • 0.6.3(Jan 26, 2023)

  • 0.6.2(Jan 26, 2023)

    What's Changed

    • fix: preserve original case for the keyword value by @KennedyTedesco in https://github.com/ara-lang/parser/pull/35
    • chore: Node get_description() tweaks by @KennedyTedesco in https://github.com/ara-lang/parser/pull/36
    • chore: code style by @KennedyTedesco in https://github.com/ara-lang/parser/pull/37
    • new: add pipe operator support by @KennedyTedesco in https://github.com/ara-lang/parser/pull/38
    • chore: stop allowing multiple constant entries by @KennedyTedesco in https://github.com/ara-lang/parser/pull/39
    • new: requiring constants to be typed by @KennedyTedesco in https://github.com/ara-lang/parser/pull/40
    • chore: merge all method definitions into one by @azjezz in https://github.com/ara-lang/parser/pull/42
    • chore: extract some common logics on class definition by @KennedyTedesco in https://github.com/ara-lang/parser/pull/46
    • new: allow foreach to have else by @KennedyTedesco in https://github.com/ara-lang/parser/pull/43
    • chore: update readme and examples by @KennedyTedesco in https://github.com/ara-lang/parser/pull/41
    • new: add functional expression operation by @KennedyTedesco in https://github.com/ara-lang/parser/pull/45
    • chore: validate union members in type_definition.is_scalar() by @KennedyTedesco in https://github.com/ara-lang/parser/pull/48
    • chore: make generic_group() returns an Option by @KennedyTedesco in https://github.com/ara-lang/parser/pull/47

    Full Changelog: https://github.com/ara-lang/parser/compare/0.6.1...0.6.2

    Source code(tar.gz)
    Source code(zip)
  • 0.6.1(Jan 18, 2023)

    What's Changed

    • new: add new types for int and float by @KennedyTedesco in https://github.com/ara-lang/parser/pull/34

    Full Changelog: https://github.com/ara-lang/parser/compare/0.6.0...0.6.1

    Source code(tar.gz)
    Source code(zip)
  • 0.6.0(Jan 17, 2023)

    What's Changed

    • new: add code of conduct by @KennedyTedesco in https://github.com/ara-lang/parser/pull/24
    • new: add is_writable() and is_readable() to Expression by @KennedyTedesco in https://github.com/ara-lang/parser/pull/25
    • chore: update parser to use reporting 0.6.0 by @KennedyTedesco in https://github.com/ara-lang/parser/pull/27
    • new: add get_description() to Node by @KennedyTedesco in https://github.com/ara-lang/parser/pull/26
    • chore: replace unreachable!() with a bug report by @KennedyTedesco in https://github.com/ara-lang/parser/pull/28
    • chore: make the parser more lenient with errors by @KennedyTedesco in https://github.com/ara-lang/parser/pull/30
    • new: add Statement::Empty by @KennedyTedesco in https://github.com/ara-lang/parser/pull/31
    • new: parse short match correctly by @KennedyTedesco in https://github.com/ara-lang/parser/pull/32
    • new: allow default values to have any kind of expression by @KennedyTedesco in https://github.com/ara-lang/parser/pull/33

    Full Changelog: https://github.com/ara-lang/parser/compare/0.5.3...0.6.0

    Source code(tar.gz)
    Source code(zip)
  • 0.5.3(Jan 10, 2023)

    What's Changed

    • chore: derive Hash in nodes by @KennedyTedesco in https://github.com/ara-lang/parser/pull/21

    Full Changelog: https://github.com/ara-lang/parser/compare/0.5.2...0.5.3

    Source code(tar.gz)
    Source code(zip)
  • 0.5.2(Jan 8, 2023)

  • 0.5.1(Jan 7, 2023)

    What's Changed

    • chore: new parser report for intersection by @KennedyTedesco in https://github.com/ara-lang/parser/pull/20

    Full Changelog: https://github.com/ara-lang/parser/compare/0.5.0...0.5.1

    Source code(tar.gz)
    Source code(zip)
  • 0.5.0(Jan 5, 2023)

    What's Changed

    • Remove dump command by @KennedyTedesco in https://github.com/ara-lang/parser/pull/16
    • chore: add literal types support by @KennedyTedesco in https://github.com/ara-lang/parser/pull/19

    New Contributors

    • @KennedyTedesco made their first contribution in https://github.com/ara-lang/parser/pull/16

    Full Changelog: https://github.com/ara-lang/parser/compare/0.4.0...0.5.0

    Source code(tar.gz)
    Source code(zip)
  • 0.4.0(Jan 1, 2023)

  • 0.3.0(Jan 1, 2023)

  • 0.2.0(Dec 31, 2022)

    What's Changed

    • fix: link to contributors in README by @ryangjchandler in https://github.com/ara-lang/parser/pull/1
    • chore: remove Span, and use usize position instead by @azjezz in https://github.com/ara-lang/parser/pull/2
    • chore: mark async, await, and concurrently as soft reserved by @azjezz in https://github.com/ara-lang/parser/pull/3

    New Contributors

    • @ryangjchandler made their first contribution in https://github.com/ara-lang/parser/pull/1
    • @azjezz made their first contribution in https://github.com/ara-lang/parser/pull/2

    Full Changelog: https://github.com/ara-lang/parser/compare/0.1.0...0.2.0

    Source code(tar.gz)
    Source code(zip)
  • 0.1.0(Dec 31, 2022)

Owner
Ara Programming Language
Ara Programming Language
Yet Another Parser library for Rust. A lightweight, dependency free, parser combinator inspired set of utility methods to help with parsing strings and slices.

Yap: Yet another (rust) parsing library A lightweight, dependency free, parser combinator inspired set of utility methods to help with parsing input.

James Wilson 117 Dec 14, 2022
Website for Microformats Rust parser (using 'microformats-parser'/'mf2')

Website for Microformats Rust parser (using 'microformats-parser'/'mf2')

Microformats 5 Jul 19, 2022
Generic parser for competitive programming

This is a generic parser for competitive programming, it can be used to read structured data line-by-line or though derive macro in a higher level fashion.

Rémi Dupré 1 Nov 15, 2021
xml-rs is an XML library for Rust programming language

xml-rs, an XML library for Rust Documentation xml-rs is an XML library for Rust programming language. It is heavily inspired by Java Streaming API for

Vladimir Matveev 417 Jan 3, 2023
A native Rust port of Google's robots.txt parser and matcher C++ library.

robotstxt A native Rust port of Google's robots.txt parser and matcher C++ library. Native Rust port, no third-part crate dependency Zero unsafe code

Folyd 72 Dec 11, 2022
Rust parser combinator framework

nom, eating data byte by byte nom is a parser combinators library written in Rust. Its goal is to provide tools to build safe parsers without compromi

Geoffroy Couprie 7.6k Jan 7, 2023
url parameter parser for rest filter inquiry

inquerest Inquerest can parse complex url query into a SQL abstract syntax tree. Example this url: /person?age=lt.42&(student=eq.true|gender=eq.'M')&

Jovansonlee Cesar 25 Nov 2, 2020
Parsing Expression Grammar (PEG) parser generator for Rust

Parsing Expression Grammars in Rust Documentation | Release Notes rust-peg is a simple yet flexible parser generator that makes it easy to write robus

Kevin Mehall 1.2k Dec 30, 2022
A fast monadic-style parser combinator designed to work on stable Rust.

Chomp Chomp is a fast monadic-style parser combinator library designed to work on stable Rust. It was written as the culmination of the experiments de

Martin Wernstål 228 Oct 31, 2022
A parser combinator library for Rust

combine An implementation of parser combinators for Rust, inspired by the Haskell library Parsec. As in Parsec the parsers are LL(1) by default but th

Markus Westerlind 1.1k Dec 28, 2022
LR(1) parser generator for Rust

LALRPOP LALRPOP is a Rust parser generator framework with usability as its primary goal. You should be able to write compact, DRY, readable grammars.

null 2.4k Jan 7, 2023
The Elegant Parser

pest. The Elegant Parser pest is a general purpose parser written in Rust with a focus on accessibility, correctness, and performance. It uses parsing

pest 3.5k Jan 8, 2023
A typed parser generator embedded in Rust code for Parsing Expression Grammars

Oak Compiled on the nightly channel of Rust. Use rustup for managing compiler channels. You can download and set up the exact same version of the comp

Pierre Talbot 138 Nov 25, 2022
Rust query string parser with nesting support

What is Queryst? This is a fork of the original, with serde and serde_json updated to 0.9 A query string parsing library for Rust inspired by https://

Stanislav Panferov 67 Nov 16, 2022
A fast, extensible, command-line arguments parser

parkour A fast, extensible, command-line arguments parser. Introduction ?? The most popular argument parser, clap, allows you list all the possible ar

Ludwig Stecher 18 Apr 19, 2021
Soon to be AsciiDoc parser implemented in rust!

pagliascii "But ASCII Doc, I am Pagliascii" Soon to be AsciiDoc parser implemented in rust! This project is the current implementation of the requeste

Lukas Wirth 49 Dec 11, 2022
An LR parser generator, implemented as a proc macro

parsegen parsegen is an LR parser generator, similar to happy, ocamlyacc, and lalrpop. It currently generates canonical LR(1) parsers, but LALR(1) and

Ömer Sinan Ağacan 5 Feb 28, 2022
A rusty, dual-wielding Quake and Half-Life texture WAD parser.

Ogre   A rusty, dual-wielding Quake and Half-Life texture WAD parser ogre is a rust representation and nom parser for Quake and Half-Life WAD files. I

Josh Palmer 16 Dec 5, 2022
A modern dialogue executor and tree parser using YAML.

A modern dialogue executor and tree parser using YAML. This crate is for building(ex), importing/exporting(ex), and walking(ex) dialogue trees. convo

Spencer Imbleau 27 Aug 3, 2022