GithubHelp home page GithubHelp logo

atahanyorganci / alloy Goto Github PK

View Code? Open in Web Editor NEW
6.0 6.0 0.0 269 KB

Alloy is dynamically typed scripting language implemented in Rust

License: BSD 3-Clause "New" or "Revised" License

Rust 100.00%
interpreter language programming-language rust

alloy's People

Contributors

atahanyorganci avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

alloy's Issues

CST and AST

Concrete Syntax Tree (CST) and Abstract Syntax Tree (AST) are closely related structures and having different parser that produce either one but not the other is wasted effort.

Since CST includes info such as delimiters and whitespace characters used a CST can be cast down to AST.

Extra info present in CST can be used to format source files (i.e. cargo fmt) or programatically produce documents from source files.

Binary Expression

Alloy has following binary operators in decreasing precedence order

  • Power, left associative
  • Multiply, Divide, Module, left associative
  • Add, Subtract, left associative
  • Comparison (<, <=, >, >=), left associative
  • Equals, Not Equal, left associative
  • Logical And, Logical Or, Logical Xor, left associative

Handle Generic Arguments for CSTs

CSTs can be generic structs and some generic arguments can be redundant after some fields are dropped. See example below

#[derive(AST)]
pub struct SumCST<'a> {
    lhs: Spanned<i64>,
    #[space]
    lw: Spanned<&'a str>,
    #[space]
    rw: Spanned<&'a str>,
    rhs: Spanned<i64>,
}

Lifetime argument 'a becomes redundant in generated AST.

Parse `Value::String`

String literals are sequence of regular characters and escape sequences delimited by double quotes.

Reference Document

Reference document should be fleshed out and describe current implementation status.

Parse `Identifier`

Identifiers in Alloy start with alphabetic or '_' character and is followed by any number of alphanumeric or '_' characters which in total is not a keyword.

Parse `Value::Float`

Rational numbers such as 0.5 are parsed as floating point numbers. Floating point values can either omit whole part of the rational number, for instance one half can be written as .5 or fractional part of rational number can be omitted 1. which is floating point one.

Map simple fields such as `Spanned<T>` into `T`

Main feature of CST in Alloy that is different from current AST is the span information. This is achieved by using Spanned<T> where T is the underlying AST so Spanned<T> should be transformed into T.

`Parse` trait

Currently Parse<'a> trait requires the implementer to provide a method for constructing Self from Rule. This has to be changed since nom will replace pest as parsing library.

Unary Expression

Parse unary expressions that are logical not, unary minus (i.e. -a) and unary plus (i.e. +a).

Fuzz Testing Parser

Add fuzz suite for testing parser. Current integration tests use procedural macros to convert Rust syntax into Alloy AST. This limits the surface area covered by testing.

Proper ParserError

Implement a proper ParserError struct that can be returned from parse_* functions implemented using nom.

Parse `Value::Integer`

Integer literals in Alloy can be regular decimal numbers, integers with bases other than 10 can be written by prefixing the literal with appropriate prefix. Other supported radix are

  • Binary prefixed with 0b
  • Octal prefixed with 0o
  • Hexadecimal with 0x

Reimplement Parser in `nom`

Crate nom is a parser combinator library focusing on safety and speed. Writing a custom parser will make syntax error reporting more rigorous. Since, nom can be used for parsing binary data same crate can be used for parsing bytecode and compiled files.

Parser rules for AST nodes have to be re-implemented and modify Parse trait.

`#[derive(AST)]` for CST Enums

Current AST implementation in Alloy includes enums such as Expression that is discriminated union of BinaryExpression, UnaryExpression etc.

// src/ast/expression/mod.rs:21
pub enum Expression {
    Value(Value),
    Binary(BinaryExpression),
    Unary(UnaryExpression),
    Identifier(IdentifierExpression),
}

This AST enum has to be derived from CST one candidate CST that can be used to generate Expression AST is provided below.

#[derive(AST)]
pub enum ExpressionCST {
    Value(Spanned<Value>),
    Binary(BinaryExpressionCST),
    Unary(UnaryExpressionCST),
    Identifier(IdentifierExpressionCST),
}

Originally posted by @atahanyorganci in #24 (comment)

Create a new identifier for AST

AST identifiers are generated by stripping trailing 'CST' suffix if it exists otherwise adding 'AST' to original identifier.

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.