Skip to content

Commit

Permalink
V0.1.0 (#4)
Browse files Browse the repository at this point in the history
* Test improvements (#3)

* Improve tests slightly

Add a slightly longer example

* Continue writing tests

* Fix formatting

* Add try, except, finally to Python mapping

* Add Java tests

* Fix python mapping

* Bump version to v0.1.0
  • Loading branch information
Moosems authored Jul 25, 2024
1 parent 80250df commit 48410d8
Show file tree
Hide file tree
Showing 11 changed files with 994 additions and 3 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<h1 align="center">Albero v0.0.3</h1>
<h1 align="center">Albero v0.1.0</h1>

A tool that makes it much easier to use Tree Sitter for your code editors

Expand Down
6 changes: 6 additions & 0 deletions albero/languages/python.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,15 @@
"comment": "Comment",
"_": "Keyword",
"as": "Keyword",
"assert": "Keyword",
"break": "Keyword",
"case": "Keyword",
"class": "Keyword",
"continue": "Keyword",
"def": "Keyword",
"elif": "Keyword",
"else": "Keyword",
"except": "Keyword",
"false": "Keyword",
"for": "Keyword",
"from": "Keyword",
Expand All @@ -27,16 +29,20 @@
"pass": "Keyword",
"raise": "Keyword",
"return": "Keyword",
"try": "Keyword",
"true": "Keyword",
"while": "Keyword",
"with": "Keyword",
"@": "Name",
"identifier": "Name",
"float": "Number",
"finally": "Number",
"integer": "Number",
"!=": "Operator",
"*": "Operator",
"**": "Operator",
"*=": "Operator",
"**=": "Operator",
"+": "Operator",
"+=": "Operator",
"-": "Operator",
Expand Down
2 changes: 1 addition & 1 deletion docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
project = "Albero"
copyright = "2024, Moosems"
author = "Moosems"
release = "v0.0.3"
release = "v0.1.0"

# -- General configuration ---------------------------------------------------
# https://www.sphinx-doc.org/en/master/usage/configuration.html#general-configuration
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

setup(
name="albero",
version="0.0.3",
version="0.1.0",
description="Albero is a tool that makes it much easier to use Tree Sitter for your code editors",
author="Moosems",
author_email="[email protected]",
Expand Down
3 changes: 3 additions & 0 deletions tests/test-languages/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# tests/test-langauges

This folder aims to test that the mappings work the for the languages that have mappings
107 changes: 107 additions & 0 deletions tests/test-languages/java_test_file.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
package com.example;

import java.util.*; // Import statement

/**
* This is a block comment
*/

public class Test {

public static void main(String[] args) {
// Line comment
int a = 5; // decimal_integer_literal
double b = 5.5; // decimal_floating_point_literal
boolean isTrue = true; // boolean and true keyword
boolean isFalse = false; // boolean and false keyword
String str = "Hello, World!"; // String
char c = 'A'; // character_literal
char esc = '\n'; // escape_sequence

a += 1; // += operator
a -= 1; // -= operator
a *= 2; // *= operator
a /= 2; // /= operator
a %= 2; // % operator
a++; // ++ operator
a--; // -- operator

if (a == 5) { // if and == operator
System.out.println("Equal to 5"); // Method call
} else if (a != 5) { // else if and != operator
System.out.println("Not equal to 5");
} else { // else keyword
System.out.println("Something else");
}

while (a < 10) { // while and < operator
a++; // Increment
}

for (int i = 0; i < 10; i++) { // for loop and < operator
System.out.println(i); // Method call
}

try { // try keyword
throw new Exception("Error!"); // throw and new keyword
} catch (Exception e) { // catch keyword
e.printStackTrace(); // Method call
} finally { // finally keyword
System.out.println("Finally block");
}

assert a == 10; // assert keyword and == operator

switch (a) {
case 10: // case keyword
System.out.println("Case 10");
break; // break keyword
default:
System.out.println("Default case");
break;
}

boolean condition = a > 5 && a < 15; // && and <, > operators
boolean orCondition = a > 5 || a < 15; // || operator

Test test = new Test();
test.exampleMethod();
}

public void exampleMethod() {
super.toString(); // super keyword
this.toString(); // this keyword
}

public interface ExampleInterface { // interface keyword
void example(); // Method in interface
}

public abstract class ExampleAbstractClass { // abstract class
public abstract void example(); // abstract method
}

public class ExampleClass extends ExampleAbstractClass implements ExampleInterface { // class, extends, implements keywords
@Override
public void example() { // @Override annotation
// Method implementation
}
}

private final int privateFinalVar = 1; // private, final keywords
protected static int protectedStaticVar = 2; // protected, static keywords
public int publicVar = 3; // public keyword

public void returnVoid() {
return; // return keyword
}

public int returnInt() {
return 1; // return keyword with value
}

boolean notCondition = !isTrue; // ! operator
boolean ternaryCondition = (a == 10) ? true : false; // ternary operator ? :

int[] array = new int[]{1, 2, 3}; // array and new keyword
}
89 changes: 89 additions & 0 deletions tests/test-languages/python_test_file.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
from typing import Any

from xyz import abc as efg # noqa: F401

# Example comment

# Variables and literals
u = {"x": "y\f"} # String with escape sequence
v = 5.5 # float
w = [] # list
x = 5 # integer
y = int("5") # integer from string
z = lambda: print # lambda function # noqa: E731

# Control structures
if x == 5: # if statement
x += 5 + x # Addition and compound assignment
x -= 5 - x # Subtraction and compound assignment
x *= 2 * x # Multiplication and compound assignment
x /= 2 / x # Division and compound assignment
x **= 2**x # Exponentiation and compound assignment
if x is not None: # is not
pass # pass statement
elif x is None: # elif and is
pass
else: # else
pass

# match-case statement
match x:
case 5: # case
print("Nice")
case _: # case _
print("Woah")

# while loop and break statement
while 2 in w: # in operator
break
if 2 not in w: # not in operator
pass


# Function with decorator
def decorator(arg) -> Any: # Function definition and type hint
def wrapper(): # Nested function
return arg() # return statement

return wrapper


@decorator
def example():
if x > y: # Greater than
pass
if x >= y: # Greater than or equal
pass
if x < y: # Less than
pass
if x <= y: # Less than or equal
pass
...
if x or y: # Logical OR
pass
with open("xyz.foo") as l: # with statement and as # noqa: F841, E741
assert False == False # assert statement and equality # noqa: E712
assert True == True # noqa: E712
pass


# Class with method
class Foo:
def break_func(self):
raise Exception("NO") # raise statement


# for loop and continue statement
for i in range(x):
continue

# Dictionary merging (Python 3.9+)
q = {} | {} # Dictionary merge operator

# try-except-finally block
try:
pass
except: # bare except # noqa: E722
pass
finally: # finally
pass
Loading

0 comments on commit 48410d8

Please sign in to comment.