Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
3434234
Intermediate state of transition the parser to nom. Broken code.
namibj Feb 4, 2020
ba495bd
Merge branch 'master' of github.com:playXE/jlight
namibj Feb 4, 2020
ea217ad
Remove erraneous `#[derive(Default)]` on `enum ExprKind`.
namibj Feb 4, 2020
638b8a7
Create rust.yml
namibj Feb 4, 2020
c2a063e
Implement parse_nil
namibj Feb 5, 2020
5c44977
Implement parse_bool_literal
namibj Feb 5, 2020
230707c
Remove parse_import
namibj Feb 5, 2020
22b983a
Implement parse_let
namibj Feb 5, 2020
5ad2e44
Implement parse_return
namibj Feb 5, 2020
ee538a6
Fix unused variable warnings
namibj Feb 5, 2020
f4f420e
Merge branch 'master' of github.com:namibj/jlight
namibj Feb 5, 2020
91f2320
Implement parse_while
namibj Feb 5, 2020
79fb4d3
Refactor parse_return
namibj Feb 5, 2020
6d22193
Implement parse_expression
namibj Feb 5, 2020
d5cbe4d
Formatting/cleanup (cosmetic)
namibj Feb 5, 2020
88310f9
Implement parse_lambda. Close #7
namibj Feb 6, 2020
3178be3
Implement parse_if. Close #2
namibj Feb 6, 2020
82e29b7
Implement parse_block. Close #3
namibj Feb 6, 2020
b79c922
Implement parse_call. Close #5
namibj Feb 6, 2020
97771e9
Add creates: nom_locate, nom_recursive
namibj Feb 8, 2020
3646fb1
Change to using nom_locate Span instead of &str to prepare for nom_re…
namibj Feb 8, 2020
c40624d
Implement parse_binary. Close #4
namibj Feb 13, 2020
257a23e
Implemented parse_primary. Close #6
namibj Feb 17, 2020
f7ad397
Added Checkout Submodules step to fix CI.
namibj Feb 18, 2020
77ca7d1
Switched build from --frozen to --locked to fix CI
namibj Feb 18, 2020
6567ce6
Fix the syntax accepted by expect_identifier to prepare for #8
namibj Mar 11, 2020
4704859
Change ExprKind::Function and ExprKind::Lambda to Ident. Part of #8
namibj Mar 12, 2020
49a9163
Change ExprKind::Var to Ident. Part of #8
namibj Mar 12, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
name: Rust

on: [push]

jobs:
build:

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- name: Checkout submodules
shell: bash
run: |
# If your submodules are configured to use SSH instead of HTTPS please uncomment the following line
# git config --global url."https://github.com/".insteadOf "git@github.com:"
auth_header="$(git config --local --get http.https://github.com/.extraheader)"
git submodule sync --recursive
git -c "http.extraheader=$auth_header" -c protocol.version=2 submodule update --init --force --recursive --depth=1
- name: Build
run: cargo build --locked --verbose
- name: Run tests
run: cargo test --locked --verbose
162 changes: 162 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,10 @@ hmap = "0.1"
jlight-vm = {path = "jlight-vm"}
regalloc = {path = "jlight-vm/regalloc.rs/lib"}
hashlink = "0.4"
nom_locate = "1.0.0"
nom-recursive = "0.1.1"
nom-packrat = "0.3.0"

[dependencies.nom]
version = "5.1.0"
features = ["regexp_macros"]
44 changes: 37 additions & 7 deletions src/ast.rs
Original file line number Diff line number Diff line change
@@ -1,21 +1,45 @@
use crate::token::Position;
use core::ops::Deref;
use std::borrow::Borrow;

#[derive(Clone, PartialEq)]
#[derive(Clone, PartialEq, Default)]
pub struct Expr {
pub pos: Position,
pub expr: ExprKind,
}

#[derive(Clone, Debug, PartialEq)]
pub struct Ident(pub String);

impl From<Ident> for String {
fn from(ident: Ident) -> Self {
ident.0
}
}

impl Deref for Ident {
type Target = String;
fn deref(&self) -> &String {
&self.0
}
}

impl Borrow<String> for Ident {
fn borrow(&self) -> &String {
&self.0
}
}

#[derive(Clone, Debug, PartialEq)]
pub enum ExprKind {
Assign(Box<Expr>, Box<Expr>),
BinOp(Box<Expr>, String, Box<Expr>),
Unop(String, Box<Expr>),
Access(Box<Expr>, String),
Ident(String),
Function(Option<String>, Vec<String>, Box<Expr>),
Access(Box<Expr>, Ident),
Ident(Ident),
Function(Option<Ident>, Vec<Ident>, Box<Expr>),
Class(String, Box<Expr>, Option<Box<Expr>>),
Lambda(Vec<String>, Box<Expr>),
Lambda(Vec<Ident>, Box<Expr>),
Match(Box<Expr>, Vec<(Box<Expr>, Box<Expr>)>, Option<Box<Expr>>),
If(Box<Expr>, Box<Expr>, Option<Box<Expr>>),
ConstInt(i64),
Expand All @@ -24,21 +48,27 @@ pub enum ExprKind {
New(Box<Expr>),
ConstFloat(f64),
Object(Vec<(Box<Expr>, Box<Expr>)>),
Var(bool, String, Option<Box<Expr>>),
Var(bool, Ident, Option<Box<Expr>>),
While(Box<Expr>, Box<Expr>),
Block(Vec<Box<Expr>>),
Return(Option<Box<Expr>>),
Call(Box<Expr>, Vec<Box<Expr>>),
Nil,
Break,
Continue,
Throw(String),
Throw(Box<Expr>),
ConstBool(bool),
Array(Vec<Box<Expr>>),
ArrayIndex(Box<Expr>, Box<Expr>),
This,
}

impl Default for ExprKind {
fn default() -> Self {
ExprKind::Nil
}
}

use std::fmt;

impl Expr {
Expand Down
Loading