Skip to content
This repository has been archived by the owner on Sep 12, 2024. It is now read-only.

Commit

Permalink
Merge branch 'main' into enhancements/persistent-v2
Browse files Browse the repository at this point in the history
  • Loading branch information
marsninja committed Aug 13, 2024
2 parents e24caf0 + 23517e9 commit 235c9cc
Show file tree
Hide file tree
Showing 7 changed files with 75 additions and 23 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

[Jac Website] | [Getting started] | [Learn] | [Documentation] | [Contributing]

[![PyPI version](https://img.shields.io/pypi/v/jaclang.svg)](https://pypi.org/project/jaclang/) [![Tests](https://github.com/chandralegend/jaclang/actions/workflows/run_pytest.yml/badge.svg?branch=main)](https://github.com/chandralegend/jaclang/actions/workflows/run_pytest.yml) [![codecov](https://codecov.io/github/chandralegend/jaclang/graph/badge.svg?token=OAX26B0FE4)](https://codecov.io/github/chandralegend/jaclang)
[![PyPI version](https://img.shields.io/pypi/v/jaclang.svg)](https://pypi.org/project/jaclang/) [![Tests](https://github.com/Jaseci-Labs/jaclang/actions/workflows/run_pytest.yml/badge.svg)](https://github.com/Jaseci-Labs/jaclang/actions/workflows/run_pytest.yml) [![codecov](https://codecov.io/github/chandralegend/jaclang/graph/badge.svg?token=OAX26B0FE4)](https://codecov.io/github/chandralegend/jaclang)
</div>

This is the main source code repository for the [Jac] programming language. It contains the compiler, language server, and documentation.
Expand Down Expand Up @@ -77,4 +77,4 @@ Third-party logos may be subject to third-party copyrights and trademarks. See [

[jaseci]: https://jaseci.org/
[media-guide]: https://jaseci.org/policies/logo-policy-and-media-guide/
[policies-licenses]: https://www.jaseci.org/policies/licenses
[policies-licenses]: https://www.jaseci.org/policies/licenses
4 changes: 3 additions & 1 deletion jaclang/compiler/passes/main/registry_pass.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,9 @@ def exit_has_var(self, node: ast.HasVar) -> None:

def exit_ability(self, node: ast.Ability) -> None:
"""Save ability information."""
scope = get_sem_scope(node.parent) # type: ignore[arg-type]
scope = get_sem_scope(node.parent) if node.parent else None
if not scope:
raise self.ice("Ability has no parent. Impossible")
seminfo = SemInfo(
node.name_ref.sym_name,
"Ability",
Expand Down
24 changes: 15 additions & 9 deletions jaclang/compiler/passes/tool/jac_formatter_pass.py
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,8 @@ def exit_sub_node_list(self, node: ast.SubNodeList) -> None:
self.emit(node, f"{stmt.value} ")
elif stmt.value == "=":
self.emit(node, f" {stmt.value} ")
elif prev_token and prev_token.gen.jac.strip() == "@":
self.emit_ln(node, stmt.value)
else:
self.emit(node, f"{stmt.gen.jac}")
prev_token = stmt
Expand Down Expand Up @@ -2418,7 +2420,7 @@ def exit_name(self, node: ast.Name) -> None:
"""
self.emit(node, f"<>{node.value}" if node.is_kwesc else node.value)

def enter_float(self, node: ast.Float) -> None:
def exit_float(self, node: ast.Float) -> None:
"""Sub objects.
name: str,
Expand All @@ -2431,7 +2433,7 @@ def enter_float(self, node: ast.Float) -> None:
"""
self.emit(node, node.value)

def enter_int(self, node: ast.Int) -> None:
def exit_int(self, node: ast.Int) -> None:
"""Sub objects.
name: str,
Expand All @@ -2444,7 +2446,7 @@ def enter_int(self, node: ast.Int) -> None:
"""
self.emit(node, node.value)

def enter_string(self, node: ast.String) -> None:
def exit_string(self, node: ast.String) -> None:
"""Sub objects.
name: str,
Expand All @@ -2456,7 +2458,11 @@ def enter_string(self, node: ast.String) -> None:
pos_end: int,
"""
# if string is in docstring format and spans multiple lines turn into the multiple single quoted strings
if "\n" in node.value and node.parent and isinstance(node.parent, ast.Expr):
if "\n" in node.value and (
node.parent
and isinstance(node.parent, ast.Expr)
and not isinstance(node.parent, ast.MultiString)
):
string_type = node.value[0:3]
pure_string = node.value[3:-3]
lines = pure_string.split("\n")
Expand All @@ -2474,14 +2480,14 @@ def enter_string(self, node: ast.String) -> None:
string_type = node.value[0:3]
pure_string = node.value[3:-3]
lines = pure_string.split("\n")
self.emit(node, string_type)
for line in lines[:-1]:
self.emit_ln(node, line)
self.emit_ln(node, f"{lines[-1]}{string_type}")
self.emit_ln(node, f"{string_type}{lines[0].lstrip()}")
for line in lines[1:-1]:
self.emit_ln(node, line.lstrip())
self.emit(node, f"{lines[-1].lstrip()}{string_type}")
else:
self.emit(node, node.value)

def enter_bool(self, node: ast.Bool) -> None:
def exit_bool(self, node: ast.Bool) -> None:
"""Sub objects.
name: str,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
can star(func: Any) {
can inner(x: Any) {
print(("*" * 30));
func(x);
print(("*" * 30));
}
return inner;
}

can percent(func: Any) {
can inner(y: Any) {
print(("%" * 30));
func(y);
print(("%" * 30));
}
return inner;
}

can percent2(func: Any) {
can inner(y: Any) {
print(("-" * 30));
func(y);
print(("+" * 30));
}
return inner;
}

@star
@percent
@percent2
can printer(msg: Any) {
print(msg);
}

with entry {
printer("Hello");
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
with entry {
triple_quoted_string = """This is a triple quoted string.
It can span multiple lines.
It can contain any number of quotes or apostrophes.
""";
}
21 changes: 11 additions & 10 deletions jaclang/tests/fixtures/chandra_bugs2.jac
Original file line number Diff line number Diff line change
@@ -1,26 +1,27 @@
import:py re;

glob a: int=5;
glob a: int = 5;

with entry {
arguments = {x:None for x in re.findall(r'\{([A-Za-z0-9_]+)\}', "Apple {apple} pineapple {pineapple}")};
a: int=5;
arguments = {x: None for x in re.findall(
r'\{([A-Za-z0-9_]+)\}',
"Apple {apple} pineapple {pineapple}"
)};
a: int = 5;
if False {
with open(f"Apple{apple}.txt") as f { # Fix syntax highlighting

print(f.read());
}
}
print(arguments);
print(
"""This is a long
line of code."""
);
print("""This is a long
line of code.""");
}

with entry{
a={"a":"apple", "b":"ball", "c":"cat"};
y={**a, "d":"dog", "e":"elephant"};
with entry {
a = {"a": "apple", "b": "ball", "c": "cat"};
y = {**a, "d": "dog", "e": "elephant"};
print(y);
}
# Use before def error would be nice
2 changes: 1 addition & 1 deletion jaclang/tests/test_language.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ def test_chandra_bugs2(self) -> None:
stdout_value,
"{'apple': None, 'pineapple': None}\n"
"This is a long\n"
" line of code.\n"
" line of code.\n"
"{'a': 'apple', 'b': 'ball', 'c': 'cat', 'd': 'dog', 'e': 'elephant'}\n",
)

Expand Down

0 comments on commit 235c9cc

Please sign in to comment.