Skip to content

Commit 1ae4d16

Browse files
authored
Merge pull request #156 from JSAbrahams/type-checker
First version of the type checker
2 parents f901d9f + c861aa1 commit 1ae4d16

217 files changed

Lines changed: 8935 additions & 3391 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.appveyor.yml

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,6 @@ branches:
99

1010
environment:
1111
matrix:
12-
# Stable 64-bit MSVC
13-
- channel: stable
14-
PYTHON: "C:\\Python37"
15-
target: x86_64-pc-windows-msvc
1612
# Nightly 64-bit MSVC
1713
- channel: nightly
1814
PYTHON: "C:\\Python37"
@@ -27,8 +23,9 @@ install:
2723

2824
- if %channel% == "nightly" rustup install nightly
2925

30-
- if %channel% == "nightly" rustup component add rustfmt --toolchain nightly
26+
- if %channel% == "nightly" rustup component add rustfmt --toolchain nightly
3127
- if %channel% == "stable" rustup component add clippy
28+
- if %channel% == "nightly" rustup component add clippy --toolchain nightly
3229

3330
- rustc -vV
3431
- cargo -vV
@@ -38,6 +35,7 @@ build: false
3835
test_script:
3936
- if %channel% == "nightly" cargo +nightly fmt --all -- --check
4037
- if %channel% == "stable" cargo clippy -- -D warnings
38+
- if %channel% == "nightly" cargo +nightly clippy -- -D warnings
4139

4240
- cargo test --verbose
4341

.codacy.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
exclude_paths:
2-
- 'tests/resources/**'
2+
- '**/*.py'

.travis.yml

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,11 @@ os:
44

55
language: rust
66
rust:
7-
- stable
87
- nightly
98

109
dist: xenial
1110
python:
12-
- "3.7"
11+
- "3.8"
1312

1413
# cache dependencies
1514
before_cache:
@@ -20,8 +19,6 @@ cache:
2019
- if [ $TRAVIS_OS_NAME = 'osx' ]; then $HOME/Library/Caches/Homebrew; fi
2120

2221
sudo: true
23-
before_install:
24-
- sudo apt-get update
2522

2623
addons:
2724
apt:
@@ -38,14 +35,24 @@ branches:
3835
- master
3936

4037
before_script:
41-
# Python
42-
- if [ $TRAVIS_OS_NAME = 'linux' ]; then sudo apt-get install python3; fi
43-
4438
# Cargo components
4539
- if [ $TRAVIS_RUST_VERSION = 'nightly' AND $TRAVIS_OS_NAME = 'linux' ]; then rustup component add rustfmt --toolchain nightly; fi
4640
- if [ $TRAVIS_RUST_VERSION = 'stable' AND $TRAVIS_OS_NAME = 'linux' ]; then rustup component add clippy; fi
41+
- if [ $TRAVIS_RUST_VERSION = 'nightly' AND $TRAVIS_OS_NAME = 'linux' ]; then rustup component add clippy --toolchain nightly; fi
4742

4843
before_install:
44+
# Python
45+
- python3 --version
46+
- |
47+
if [ $TRAVIS_OS_NAME = 'linux' ]; then
48+
sudo apt update;
49+
sudo apt install software-properties-common;
50+
sudo add-apt-repository -y ppa:deadsnakes/ppa;
51+
sudo apt-get update;
52+
sudo apt-get install python3.8;
53+
fi
54+
- python3 --version
55+
4956
# grcov
5057
- curl -L https://github.com/mozilla/grcov/releases/download/v0.4.1/grcov-linux-x86_64.tar.bz2 | tar jxf -
5158

@@ -55,6 +62,7 @@ after_success:
5562

5663
script:
5764
- if [ $TRAVIS_RUST_VERSION = 'stable' AND $TRAVIS_OS_NAME = 'linux' ]; then cargo clippy -- -D warnings; fi
65+
- if [ $TRAVIS_RUST_VERSION = 'nightly' AND $TRAVIS_OS_NAME = 'linux' ]; then cargo +nightly clippy -- -D warnings; fi
5866
- if [ $TRAVIS_RUST_VERSION = 'nightly' AND $TRAVIS_OS_NAME = 'linux' ]; then cargo +nightly fmt --all -- --check; fi
5967

6068
- cargo build

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
[package]
22
name = "mamba"
3-
version = "0.1.0"
3+
version = "0.2.0"
44
authors = ["Joel Abrahams <abrahamsjo@gmail.com>"]
55
description = "A transpiler which translates Mamba to Python 3 files"
66
edition = "2018"
7-
license = "MIT"
87
license-file = "LICENSE"
98

109
readme = "README.md"

src/common/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
pub mod position;

src/common/position.rs

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
use std::cmp::{max, min};
2+
3+
#[derive(Clone, Debug, PartialEq, Eq, Hash)]
4+
/// A position represents a rectangle in the source code.
5+
pub struct Position {
6+
pub start: CaretPos,
7+
pub end: CaretPos
8+
}
9+
10+
#[derive(Clone, Debug, PartialEq, Eq, Hash)]
11+
/// An endpoint represents either the top left or bottom right points of a
12+
/// [Position] rectangle.
13+
///
14+
/// Line's and position's are 1-indexed.
15+
pub struct CaretPos {
16+
pub line: i32,
17+
pub pos: i32
18+
}
19+
20+
impl Position {
21+
pub fn new(start: &CaretPos, end: &CaretPos) -> Position {
22+
Position { start: start.clone(), end: end.clone() }
23+
}
24+
25+
/// Get the absolute width of a position, which represents a rectangle in
26+
/// the source code.
27+
///
28+
/// Width is always 1 or greater.
29+
pub fn get_width(&self) -> i32 {
30+
max(1, max(self.end.pos - self.start.pos, self.start.pos - self.end.pos))
31+
}
32+
33+
pub fn union(&self, other: &Position) -> Position {
34+
Position {
35+
start: CaretPos {
36+
line: min(self.start.line, other.start.line),
37+
pos: min(self.start.pos, other.start.pos)
38+
},
39+
end: CaretPos {
40+
line: max(self.end.line, other.end.line),
41+
pos: max(self.end.pos, other.end.pos)
42+
}
43+
}
44+
}
45+
}
46+
47+
impl CaretPos {
48+
/// Create new endpoint with given line and position.
49+
pub fn new(line: i32, pos: i32) -> CaretPos { CaretPos { line, pos } }
50+
51+
/// Create new [EndPoint] which is offset in the vertical direction by the
52+
/// given amount.
53+
pub fn offset_line(self, offset: i32) -> CaretPos {
54+
CaretPos { line: self.line + offset, pos: self.pos }
55+
}
56+
57+
/// Create new [EndPoint] which is offset in the horizontal direction by the
58+
/// given amount.
59+
pub fn offset_pos(self, offset: i32) -> CaretPos {
60+
CaretPos { line: self.line, pos: self.pos + offset }
61+
}
62+
63+
pub fn newline(self) -> CaretPos { CaretPos { line: self.line + 1, pos: 1 } }
64+
}
65+
66+
impl Default for Position {
67+
fn default() -> Self { Position { start: CaretPos::default(), end: CaretPos::default() } }
68+
}
69+
70+
impl Default for CaretPos {
71+
fn default() -> Self { CaretPos { line: 1, pos: 1 } }
72+
}

0 commit comments

Comments
 (0)