Typhon-Language 0.1.1__py3-none-any.whl → 0.1.3__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- Typhon/Driver/translate.py +2 -1
- Typhon/Grammar/_typhon_parser.py +1638 -1649
- Typhon/Grammar/syntax_errors.py +11 -0
- Typhon/Grammar/typhon_ast.py +405 -55
- Typhon/Grammar/unparse_custom.py +25 -0
- Typhon/SourceMap/datatype.py +264 -264
- Typhon/Transform/const_member_to_final.py +1 -1
- Typhon/Transform/extended_patterns.py +139 -0
- Typhon/Transform/forbidden_statements.py +24 -0
- Typhon/Transform/if_while_let.py +122 -11
- Typhon/Transform/inline_statement_block_capture.py +22 -15
- Typhon/Transform/placeholder_to_function.py +0 -1
- Typhon/Transform/record_to_dataclass.py +22 -238
- Typhon/Transform/scope_check_rename.py +65 -11
- Typhon/Transform/transform.py +16 -12
- Typhon/Transform/type_abbrev_desugar.py +1 -1
- Typhon/Transform/utils/__init__.py +0 -0
- Typhon/Transform/utils/imports.py +48 -0
- Typhon/Transform/{utils.py → utils/jump_away.py} +2 -38
- Typhon/Transform/utils/make_class.py +140 -0
- Typhon/Typing/pyright.py +143 -144
- Typhon/Typing/result_diagnostic.py +1 -1
- {typhon_language-0.1.1.dist-info → typhon_language-0.1.3.dist-info}/METADATA +51 -6
- typhon_language-0.1.3.dist-info/RECORD +53 -0
- typhon_language-0.1.1.dist-info/RECORD +0 -48
- {typhon_language-0.1.1.dist-info → typhon_language-0.1.3.dist-info}/WHEEL +0 -0
- {typhon_language-0.1.1.dist-info → typhon_language-0.1.3.dist-info}/entry_points.txt +0 -0
- {typhon_language-0.1.1.dist-info → typhon_language-0.1.3.dist-info}/licenses/LICENSE +0 -0
- {typhon_language-0.1.1.dist-info → typhon_language-0.1.3.dist-info}/top_level.txt +0 -0
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
from ...Grammar.typhon_ast import (
|
|
2
|
+
get_pos_attributes,
|
|
3
|
+
pos_attribute_to_range,
|
|
4
|
+
set_is_var,
|
|
5
|
+
PosAttributes,
|
|
6
|
+
)
|
|
7
|
+
import ast
|
|
8
|
+
from typing import Protocol, Iterable, Final
|
|
9
|
+
from .imports import (
|
|
10
|
+
add_import_for_dataclass,
|
|
11
|
+
add_import_for_protocol,
|
|
12
|
+
add_import_for_runtime_checkable,
|
|
13
|
+
add_import_for_final,
|
|
14
|
+
)
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
class NameAndAnnotation(Protocol):
|
|
18
|
+
name: Final[ast.Name]
|
|
19
|
+
annotation: Final[ast.expr]
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
def _class_contents_for_fields(
|
|
23
|
+
fields: Iterable[NameAndAnnotation],
|
|
24
|
+
final_imported_name: str,
|
|
25
|
+
) -> list[ast.stmt]:
|
|
26
|
+
result: list[ast.stmt] = []
|
|
27
|
+
for field in fields:
|
|
28
|
+
name = field.name
|
|
29
|
+
if field.annotation:
|
|
30
|
+
# Currently annotation is always Final[...] for record fields.
|
|
31
|
+
annotation = ast.Subscript(
|
|
32
|
+
value=ast.Name(
|
|
33
|
+
id=final_imported_name, ctx=ast.Load(), **get_pos_attributes(name)
|
|
34
|
+
),
|
|
35
|
+
slice=field.annotation,
|
|
36
|
+
ctx=ast.Load(),
|
|
37
|
+
**get_pos_attributes(name),
|
|
38
|
+
)
|
|
39
|
+
else:
|
|
40
|
+
annotation = ast.Name(
|
|
41
|
+
id=final_imported_name, ctx=ast.Load(), **get_pos_attributes(name)
|
|
42
|
+
)
|
|
43
|
+
ann_assign = ast.AnnAssign(
|
|
44
|
+
target=ast.Name(id=name.id, ctx=ast.Store(), **get_pos_attributes(name)),
|
|
45
|
+
annotation=annotation,
|
|
46
|
+
value=None,
|
|
47
|
+
simple=1,
|
|
48
|
+
**get_pos_attributes(name),
|
|
49
|
+
)
|
|
50
|
+
# "var" because dataclass is frozen, "Final" is not required.
|
|
51
|
+
set_is_var(ann_assign)
|
|
52
|
+
result.append(ann_assign)
|
|
53
|
+
return result
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
def _type_vars_for_fields(
|
|
57
|
+
pos: PosAttributes, type_variables: list[str]
|
|
58
|
+
) -> list[ast.type_param]:
|
|
59
|
+
type_params: list[ast.type_param] = []
|
|
60
|
+
for tv in type_variables:
|
|
61
|
+
type_params.append(ast.TypeVar(name=tv, **pos_attribute_to_range(pos)))
|
|
62
|
+
return type_params
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
def make_protocol_definition(
|
|
66
|
+
mod: ast.Module,
|
|
67
|
+
class_name: str,
|
|
68
|
+
type_variables: list[str],
|
|
69
|
+
fields: Iterable[NameAndAnnotation],
|
|
70
|
+
pos: PosAttributes,
|
|
71
|
+
) -> ast.ClassDef:
|
|
72
|
+
protocol_imported_name: str = add_import_for_protocol(mod)
|
|
73
|
+
runtime_checkable_imported_name: str = add_import_for_runtime_checkable(mod)
|
|
74
|
+
final_imported_name: str = add_import_for_final(mod)
|
|
75
|
+
result = ast.ClassDef(
|
|
76
|
+
name=class_name,
|
|
77
|
+
type_params=_type_vars_for_fields(pos, type_variables),
|
|
78
|
+
bases=[ast.Name(id=protocol_imported_name, ctx=ast.Load(), **pos)],
|
|
79
|
+
keywords=[],
|
|
80
|
+
# Currently all fields are Final.
|
|
81
|
+
body=_class_contents_for_fields(fields, final_imported_name),
|
|
82
|
+
decorator_list=[
|
|
83
|
+
ast.Name(id=runtime_checkable_imported_name, ctx=ast.Load(), **pos)
|
|
84
|
+
],
|
|
85
|
+
**pos,
|
|
86
|
+
)
|
|
87
|
+
return result
|
|
88
|
+
|
|
89
|
+
|
|
90
|
+
def _dataclass_decorator(
|
|
91
|
+
dataclass_imported_name: str, repr: bool, pos: PosAttributes
|
|
92
|
+
) -> ast.expr:
|
|
93
|
+
return ast.Call(
|
|
94
|
+
func=ast.Name(id=dataclass_imported_name, ctx=ast.Load(), **pos),
|
|
95
|
+
args=[],
|
|
96
|
+
keywords=[
|
|
97
|
+
ast.keyword(arg="frozen", value=ast.Constant(value=True)),
|
|
98
|
+
ast.keyword(arg="repr", value=ast.Constant(value=repr)),
|
|
99
|
+
ast.keyword(arg="unsafe_hash", value=ast.Constant(value=True)),
|
|
100
|
+
ast.keyword(arg="kw_only", value=ast.Constant(value=True)),
|
|
101
|
+
],
|
|
102
|
+
)
|
|
103
|
+
|
|
104
|
+
|
|
105
|
+
def make_dataclass_definition(
|
|
106
|
+
mod: ast.Module,
|
|
107
|
+
class_name: str,
|
|
108
|
+
type_variables: list[str],
|
|
109
|
+
fields: Iterable[NameAndAnnotation],
|
|
110
|
+
pos: PosAttributes,
|
|
111
|
+
) -> ast.ClassDef:
|
|
112
|
+
dataclass_imported_name: str = add_import_for_dataclass(mod)
|
|
113
|
+
final_imported_name: str = add_import_for_final(mod)
|
|
114
|
+
result = ast.ClassDef(
|
|
115
|
+
name=class_name,
|
|
116
|
+
type_params=_type_vars_for_fields(pos, type_variables),
|
|
117
|
+
bases=[],
|
|
118
|
+
keywords=[],
|
|
119
|
+
body=_class_contents_for_fields(fields, final_imported_name),
|
|
120
|
+
decorator_list=[
|
|
121
|
+
_dataclass_decorator(dataclass_imported_name, repr=False, pos=pos)
|
|
122
|
+
],
|
|
123
|
+
**pos,
|
|
124
|
+
)
|
|
125
|
+
return result
|
|
126
|
+
|
|
127
|
+
|
|
128
|
+
def make_dataclass_protocol_definition(
|
|
129
|
+
mod: ast.Module,
|
|
130
|
+
class_name: str,
|
|
131
|
+
type_variables: list[str],
|
|
132
|
+
fields: Iterable[NameAndAnnotation],
|
|
133
|
+
pos: PosAttributes,
|
|
134
|
+
) -> ast.ClassDef:
|
|
135
|
+
dataclass_imported_name: str = add_import_for_dataclass(mod)
|
|
136
|
+
result = make_protocol_definition(mod, class_name, type_variables, fields, pos)
|
|
137
|
+
result.decorator_list.append(
|
|
138
|
+
_dataclass_decorator(dataclass_imported_name, repr=True, pos=pos)
|
|
139
|
+
)
|
|
140
|
+
return result
|
Typhon/Typing/pyright.py
CHANGED
|
@@ -1,144 +1,143 @@
|
|
|
1
|
-
import sys
|
|
2
|
-
from pathlib import Path
|
|
3
|
-
import subprocess
|
|
4
|
-
from ..Driver.debugging import debug_print
|
|
5
|
-
from typing import Literal, cast, Any
|
|
6
|
-
import json
|
|
7
|
-
from .result_diagnostic import Severity, Diagnostic, TypeCheckResult
|
|
8
|
-
from ..SourceMap.datatype import Range, Pos
|
|
9
|
-
|
|
10
|
-
# https://docs.basedpyright.com/dev/configuration/config-files/
|
|
11
|
-
type TypeCheckLevel = Literal[
|
|
12
|
-
"off",
|
|
13
|
-
"basic",
|
|
14
|
-
"strict",
|
|
15
|
-
"all",
|
|
16
|
-
"translate", # Default for Typhon translation
|
|
17
|
-
"script", # Default for Typhon scripts
|
|
18
|
-
]
|
|
19
|
-
translate_config = {
|
|
20
|
-
"typeCheckingMode": "strict",
|
|
21
|
-
"reportUnusedExpression": "warning",
|
|
22
|
-
"reportUnusedClass": "warning",
|
|
23
|
-
"reportUnusedImport": "warning",
|
|
24
|
-
"reportUnusedFunction": "warning",
|
|
25
|
-
"reportUnusedVariable": "warning",
|
|
26
|
-
"reportUnusedCallResult": "warning",
|
|
27
|
-
"reportUnnecessaryIsInstance": "warning",
|
|
28
|
-
"reportUnnecessaryCast": "warning",
|
|
29
|
-
"reportUnnecessaryComparison": "warning",
|
|
30
|
-
"reportUnnecessaryContains": "warning",
|
|
31
|
-
"
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
"
|
|
36
|
-
"
|
|
37
|
-
"
|
|
38
|
-
"
|
|
39
|
-
"
|
|
40
|
-
"
|
|
41
|
-
"
|
|
42
|
-
"
|
|
43
|
-
"
|
|
44
|
-
"
|
|
45
|
-
"
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
"
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
config.update(
|
|
61
|
-
elif level == "
|
|
62
|
-
config
|
|
63
|
-
elif level == "
|
|
64
|
-
config["typeCheckingMode"] = "
|
|
65
|
-
elif level == "
|
|
66
|
-
config["typeCheckingMode"] = "
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
"
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
return result
|
|
1
|
+
import sys
|
|
2
|
+
from pathlib import Path
|
|
3
|
+
import subprocess
|
|
4
|
+
from ..Driver.debugging import debug_print
|
|
5
|
+
from typing import Literal, cast, Any
|
|
6
|
+
import json
|
|
7
|
+
from .result_diagnostic import Severity, Diagnostic, TypeCheckResult
|
|
8
|
+
from ..SourceMap.datatype import Range, Pos
|
|
9
|
+
|
|
10
|
+
# https://docs.basedpyright.com/dev/configuration/config-files/
|
|
11
|
+
type TypeCheckLevel = Literal[
|
|
12
|
+
"off",
|
|
13
|
+
"basic",
|
|
14
|
+
"strict",
|
|
15
|
+
"all",
|
|
16
|
+
"translate", # Default for Typhon translation
|
|
17
|
+
"script", # Default for Typhon scripts
|
|
18
|
+
]
|
|
19
|
+
translate_config = {
|
|
20
|
+
"typeCheckingMode": "strict",
|
|
21
|
+
"reportUnusedExpression": "warning",
|
|
22
|
+
"reportUnusedClass": "warning",
|
|
23
|
+
"reportUnusedImport": "warning",
|
|
24
|
+
"reportUnusedFunction": "warning",
|
|
25
|
+
"reportUnusedVariable": "warning",
|
|
26
|
+
"reportUnusedCallResult": "warning",
|
|
27
|
+
"reportUnnecessaryIsInstance": "warning",
|
|
28
|
+
"reportUnnecessaryCast": "warning",
|
|
29
|
+
# "reportUnnecessaryComparison": "warning", # To check type of patterns
|
|
30
|
+
"reportUnnecessaryContains": "warning",
|
|
31
|
+
"reportDeprecated": "warning",
|
|
32
|
+
}
|
|
33
|
+
script_config = {
|
|
34
|
+
"typeCheckingMode": "strict",
|
|
35
|
+
"reportUnusedExpression": "none",
|
|
36
|
+
"reportUnusedClass": "none",
|
|
37
|
+
"reportUnusedImport": "none",
|
|
38
|
+
"reportUnusedFunction": "none",
|
|
39
|
+
"reportUnusedVariable": "none",
|
|
40
|
+
"reportUnusedCallResult": "none",
|
|
41
|
+
"reportUnnecessaryIsInstance": "none",
|
|
42
|
+
"reportUnnecessaryCast": "none",
|
|
43
|
+
# "reportUnnecessaryComparison": "none", # To check type of patterns
|
|
44
|
+
"reportUnnecessaryContains": "none",
|
|
45
|
+
"reportDeprecated": "none",
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
def write_pyright_config(
|
|
50
|
+
output_dir: Path, level: TypeCheckLevel = "translate", overwrite: bool = False
|
|
51
|
+
) -> str:
|
|
52
|
+
config = {
|
|
53
|
+
"include": ["**/*.py"],
|
|
54
|
+
"exclude": ["**/__pycache__"],
|
|
55
|
+
"typeCheckingMode": "off",
|
|
56
|
+
}
|
|
57
|
+
if level == "translate":
|
|
58
|
+
config.update(translate_config)
|
|
59
|
+
elif level == "script":
|
|
60
|
+
config.update(script_config)
|
|
61
|
+
elif level == "basic":
|
|
62
|
+
config["typeCheckingMode"] = "basic"
|
|
63
|
+
elif level == "strict":
|
|
64
|
+
config["typeCheckingMode"] = "strict"
|
|
65
|
+
elif level == "all":
|
|
66
|
+
config["typeCheckingMode"] = "all"
|
|
67
|
+
else:
|
|
68
|
+
raise ValueError(f"Unknown type check level: {level}")
|
|
69
|
+
config_path = output_dir / "pyrightconfig.json"
|
|
70
|
+
if not overwrite and config_path.exists():
|
|
71
|
+
debug_print(
|
|
72
|
+
f"Config file already exists at {config_path}. Use overwrite=True to replace."
|
|
73
|
+
)
|
|
74
|
+
return str(config_path)
|
|
75
|
+
with open(config_path, "w") as f:
|
|
76
|
+
json.dump(config, f, indent=4)
|
|
77
|
+
debug_print(f"Generated pyright config at {config_path}")
|
|
78
|
+
return str(config_path)
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
def _try_read_attr[T](d: Any, attr: str, default: T) -> T:
|
|
82
|
+
result = d.get(attr, default)
|
|
83
|
+
return cast(T, result)
|
|
84
|
+
|
|
85
|
+
|
|
86
|
+
def _parse_pos_range(pos: Any) -> Range:
|
|
87
|
+
start = _try_read_attr(pos, "start", {})
|
|
88
|
+
end = _try_read_attr(pos, "end", {})
|
|
89
|
+
# All lines and columns are 0-based, convert to 1-based.
|
|
90
|
+
return Range(
|
|
91
|
+
start=Pos(line=start.get("line", 0) + 1, column=start.get("character", 0) + 1),
|
|
92
|
+
end=Pos(line=end.get("line", 0) + 1, column=end.get("character", 0) + 1),
|
|
93
|
+
)
|
|
94
|
+
|
|
95
|
+
|
|
96
|
+
def _parse_diagnostic(diag: Any) -> Diagnostic:
|
|
97
|
+
return Diagnostic(
|
|
98
|
+
file_path=_try_read_attr(diag, "file", ""),
|
|
99
|
+
severity=Severity[_try_read_attr(diag, "severity", "INFO").upper()],
|
|
100
|
+
message=_try_read_attr(diag, "message", ""),
|
|
101
|
+
pos=_parse_pos_range(diag["range"]),
|
|
102
|
+
rule=_try_read_attr(diag, "rule", ""),
|
|
103
|
+
)
|
|
104
|
+
|
|
105
|
+
|
|
106
|
+
def parse_json_output(output: str, returncode: int, stderr: str) -> TypeCheckResult:
|
|
107
|
+
data = json.loads(output)
|
|
108
|
+
diagnostics = [
|
|
109
|
+
_parse_diagnostic(diag) for diag in data.get("generalDiagnostics", [])
|
|
110
|
+
]
|
|
111
|
+
summary = _try_read_attr(data, "summary", {})
|
|
112
|
+
return TypeCheckResult(
|
|
113
|
+
returncode=returncode,
|
|
114
|
+
stderr=stderr,
|
|
115
|
+
files_analyzed=_try_read_attr(summary, "filesAnalyzed", 0),
|
|
116
|
+
num_errors=_try_read_attr(summary, "errorCount", 0),
|
|
117
|
+
num_warnings=_try_read_attr(summary, "warningCount", 0),
|
|
118
|
+
num_info=_try_read_attr(summary, "informationCount", 0),
|
|
119
|
+
time_in_sec=_try_read_attr(summary, "timeInSec", 0.0),
|
|
120
|
+
diagnostics=diagnostics,
|
|
121
|
+
)
|
|
122
|
+
|
|
123
|
+
|
|
124
|
+
def run_pyright(
|
|
125
|
+
py_file_or_dir: Path, level: TypeCheckLevel = "translate"
|
|
126
|
+
) -> TypeCheckResult:
|
|
127
|
+
output = subprocess.run(
|
|
128
|
+
[
|
|
129
|
+
sys.executable,
|
|
130
|
+
"-m",
|
|
131
|
+
"basedpyright",
|
|
132
|
+
str(py_file_or_dir),
|
|
133
|
+
"--outputjson",
|
|
134
|
+
],
|
|
135
|
+
stdout=subprocess.PIPE,
|
|
136
|
+
stderr=subprocess.PIPE,
|
|
137
|
+
shell=False,
|
|
138
|
+
)
|
|
139
|
+
print(output.stdout.decode())
|
|
140
|
+
result = parse_json_output(
|
|
141
|
+
output.stdout.decode(), output.returncode, output.stderr.decode()
|
|
142
|
+
)
|
|
143
|
+
return result
|
|
@@ -67,7 +67,7 @@ class TypeCheckResult:
|
|
|
67
67
|
output_error: bool = True,
|
|
68
68
|
output_warning: bool = True,
|
|
69
69
|
output_info: bool = True,
|
|
70
|
-
output_summary_even_no_diag: bool =
|
|
70
|
+
output_summary_even_no_diag: bool = False,
|
|
71
71
|
source_maps: dict[str, SourceMap | None] = {},
|
|
72
72
|
) -> str:
|
|
73
73
|
diags: list[str] = []
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: Typhon-Language
|
|
3
|
-
Version: 0.1.
|
|
3
|
+
Version: 0.1.3
|
|
4
4
|
Summary: Typhon programming language
|
|
5
5
|
Requires-Python: >=3.12
|
|
6
6
|
Description-Content-Type: text/markdown
|
|
@@ -17,17 +17,58 @@ Dynamic: license-file
|
|
|
17
17
|
|
|
18
18
|
Typhon is a modernized syntax sugar for Python, designed to improve developer experience with features like static typing, brace-based scoping, and expressive functional programming capabilities.
|
|
19
19
|
|
|
20
|
-
GitHub repository: [Typhon](https://github.com/hnakamura5/Typhon)
|
|
21
|
-
PyPI package: [Typhon-Language](https://pypi.org/project/Typhon-Language/)
|
|
20
|
+
- GitHub repository: [Typhon](https://github.com/hnakamura5/Typhon)
|
|
21
|
+
- PyPI package: [Typhon-Language](https://pypi.org/project/Typhon-Language/)
|
|
22
|
+
- VSCode extension: [Typhon Language Support](https://marketplace.visualstudio.com/items?itemName=hnakamura5.typhon-language-support) from [GitHub Repository](https://github.com/hnakamura5/typhon-language-support)
|
|
23
|
+
|
|
24
|
+
## Getting Started
|
|
25
|
+
|
|
26
|
+
Install Typhon via pip:
|
|
27
|
+
|
|
28
|
+
```bash
|
|
29
|
+
pip install typhon-language
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
Run Typhon from the command line:
|
|
33
|
+
|
|
34
|
+
```bash
|
|
35
|
+
typhon --help
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
Create a simple Typhon program in `hello.typh`:
|
|
39
|
+
|
|
40
|
+
```typhon
|
|
41
|
+
def main() {
|
|
42
|
+
print("Hello, Typhon!")
|
|
43
|
+
}
|
|
44
|
+
main()
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
Run the program:
|
|
48
|
+
|
|
49
|
+
```bash
|
|
50
|
+
typhon run hello.typh
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
Or run directly using uvx:
|
|
54
|
+
|
|
55
|
+
```bash
|
|
56
|
+
uvx --from typhon-language typhon run hello.typh
|
|
57
|
+
```
|
|
22
58
|
|
|
23
59
|
## Design Concepts
|
|
24
60
|
|
|
25
61
|
Typhon is built on three core pillars:
|
|
26
62
|
|
|
27
|
-
1. **Safety**: As expected
|
|
63
|
+
1. **Safety**: As expected in modern programming languages, Typhon enforces safety through static typing, lexical scopes, immutable-by-default variables (`let`), and null safety features (`?.`, `??`, `?()`, `?[]`).
|
|
28
64
|
2. **Expressiveness**: Expression-oriented design with functional programming features. Control comprehension forms for `if`, `match`, `try`, and so on enable concise, value-returning expressions. Function literals, placeholders and pipe operators facilitate clean and readable code.
|
|
29
65
|
3. **Python Interoperability**: Typhon compiles directly to Python, allowing you to use the vast ecosystem of Python libraries seamlessly while enjoying a modern syntax.
|
|
30
66
|
|
|
67
|
+
### How it looks like
|
|
68
|
+
|
|
69
|
+
You can see small code snippets in the test directory: [Typhon Tests](test/execute/RunFileTest/).
|
|
70
|
+
|
|
71
|
+
|
|
31
72
|
## Documentation
|
|
32
73
|
|
|
33
74
|
For a complete guide to the language, please visit the **[Typhon Reference Manual](doc/reference/README.md)**.
|
|
@@ -48,8 +89,8 @@ Typhon retains most of Python's semantics but introduces significant syntax chan
|
|
|
48
89
|
|
|
49
90
|
### Main Changes
|
|
50
91
|
|
|
51
|
-
- **Brace Scoping**: Typhon uses `{ ... }` for blocks, replacing indentation-based scoping. Both `;` and line breaks can also act as delimiters. See [Lexical Structure](doc/reference/lexical_structure.md).
|
|
52
|
-
- **Static Typing**: Type checking is enforced at compile time.
|
|
92
|
+
- **Brace Scoping**: Typhon uses `{ ... }` for blocks, replacing indentation-based scoping. Both `;` and line breaks can also act as delimiters. See [Lexical Structure](doc/reference/lexical_structure.md) for more details.
|
|
93
|
+
- **Static Typing**: Type checking is enforced at compile time. Currently powered by [basedpyright](https://docs.basedpyright.com/latest/) type checker.
|
|
53
94
|
- **Declarations**: Variables must be declared with `let` (immutable) or `var` (mutable). See [Variables](doc/reference/variables.md).
|
|
54
95
|
|
|
55
96
|
### Syntax Extensions
|
|
@@ -83,6 +124,10 @@ Some Python features are removed to enforce safety and clarity. See [Removed Fea
|
|
|
83
124
|
|
|
84
125
|
Typhon can be run directly or translated to Python.
|
|
85
126
|
|
|
127
|
+
`.typh` files are Typhon source files. In directory mode, all `.typh` files are processed.
|
|
128
|
+
|
|
129
|
+
Note Typhon uses `.typhon` directory in source paths to place translated Python files and caches.
|
|
130
|
+
|
|
86
131
|
### Run
|
|
87
132
|
|
|
88
133
|
Run a Typhon source file or directory.
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
Typhon/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
2
|
+
Typhon/__main__.py,sha256=9vd3zChySHgfQmXqLaBYBXerUATC0m_BgI1clg3HRf4,1053
|
|
3
|
+
Typhon/Driver/debugging.py,sha256=O2cYsu4Y4xmFfgmYm8NQoyrqqXgqzzLrAWZJFxxIoUM,892
|
|
4
|
+
Typhon/Driver/diagnostic.py,sha256=gB3byTB3EOrVfCWVAH2_nrxtF2-Tgzb_9WZIcNwzoNE,1256
|
|
5
|
+
Typhon/Driver/run.py,sha256=xQLcBaI0vzYTPMQtYVQrukP0o7Fk6I59--fRl0Z2M8A,4553
|
|
6
|
+
Typhon/Driver/translate.py,sha256=a6zLwHbMV2iyXFETUVvtB5uy_AGyZqtZzHEPuGGEMqk,6754
|
|
7
|
+
Typhon/Driver/type_check.py,sha256=9PDKsmAPcpdtQqZAE7LDjM8ynjKz02rNZwXDG2Kb3LE,1516
|
|
8
|
+
Typhon/Driver/utils.py,sha256=ATckYbYYwo3NTlLKAWJqAjjNAZ_n9IGMFyqONSKP1rk,1506
|
|
9
|
+
Typhon/Grammar/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
10
|
+
Typhon/Grammar/_typhon_parser.py,sha256=swZkt_dunZGcmOe-Wi7IgjFUytEzEE59B6WxbZM6wA4,444756
|
|
11
|
+
Typhon/Grammar/line_break.py,sha256=lH2is1yAubG1fhXw5SbQUvlfmeLH7h3PbOEiVrAfRA0,2712
|
|
12
|
+
Typhon/Grammar/parser.py,sha256=AIWQzSYOjXkH6kwDf2kRatwKxUqRkTVNoeYJhhVtL0U,1434
|
|
13
|
+
Typhon/Grammar/parser_helper.py,sha256=i0CkjhXF4W9SPrYRB785weiaaO7LaoY2xBNXHZlAsnc,17989
|
|
14
|
+
Typhon/Grammar/syntax_errors.py,sha256=_n92-ceDUlaqwJ1fTvPzU64BG5ULDw5MJ0Xg5VSHWK4,5051
|
|
15
|
+
Typhon/Grammar/token_factory_custom.py,sha256=qA2LJ_vriEu3eNpWCqFCdp363j5npJP3PbkN-e3oHow,20620
|
|
16
|
+
Typhon/Grammar/tokenizer_custom.py,sha256=51WkJ0AxDwOBfo5bdtRtSary-uXlIs9sG9l-UWCE2uY,9657
|
|
17
|
+
Typhon/Grammar/typhon_ast.py,sha256=7ACeC-VFf7er76FNFnE31DT_zwedCpqoO7pOGDVs3YQ,59932
|
|
18
|
+
Typhon/Grammar/unparse_custom.py,sha256=97mjjp7TxEJY94BLprn6ULG401JPhTvy4-nkbXlJG0Y,778
|
|
19
|
+
Typhon/SourceMap/__init__.py,sha256=t56lq7YFlqhEfpW9_xHyIs2n_hhYuycMNRpyV9vjMI4,599
|
|
20
|
+
Typhon/SourceMap/ast_match_based_map.py,sha256=UiGOoinEt6nk17dl58UHZXwauAQMXP74H5zlD8w_bkQ,6382
|
|
21
|
+
Typhon/SourceMap/ast_matching.py,sha256=4-6awc4vosMoiSwuGFA82bPAsYbLDQQr7SKJ9Rl33lM,3328
|
|
22
|
+
Typhon/SourceMap/datatype.py,sha256=a9CD1WFNpcJPAJowY-4FxxxtBguhDyTASLcJ38pnuSo,9872
|
|
23
|
+
Typhon/Transform/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
24
|
+
Typhon/Transform/comprehension_to_function.py,sha256=PmZ8gTzlp028Ge_YAMMWngqvTcRex5URIkICOIaS1PM,2721
|
|
25
|
+
Typhon/Transform/const_member_to_final.py,sha256=9fCrCsGCeDmWplyWaXM8Z_a8FTSLBFx-sPTdBV_a_w4,2566
|
|
26
|
+
Typhon/Transform/extended_patterns.py,sha256=eylsTJKShw2ev4wQyUPgMLRGY0sg-AxIyDmmZRVTH_s,4553
|
|
27
|
+
Typhon/Transform/forbidden_statements.py,sha256=NanYtUBrCGWgYGkrozTMZvT4hb6tSMJZQXSsEXYKupY,4491
|
|
28
|
+
Typhon/Transform/func_literal_to_def.py,sha256=SxI6lpktyeYFSmoVPqcDmKZ5CQcVXEmkg5sy1AtMPy0,2675
|
|
29
|
+
Typhon/Transform/if_while_let.py,sha256=pt7pfVZS2jhBHkRaIADTahWIWWjeUXpvUhincI3Koy0,10322
|
|
30
|
+
Typhon/Transform/inline_statement_block_capture.py,sha256=0mrgJBh1r48JaFIC6rZbsLBs0gHrgKcWW0a79snPlmM,8518
|
|
31
|
+
Typhon/Transform/insert_self_to_method.py,sha256=O9dOFx9wtYWwN0wR7D5PmX51REy1VKEzvVNt7lIVRRU,1593
|
|
32
|
+
Typhon/Transform/name_generator.py,sha256=_mAmG7ynGQEP4qBqp2rIpY3qMWC95UGbXTwHXBTYYPU,5906
|
|
33
|
+
Typhon/Transform/optional_operators_to_checked.py,sha256=Fb01bQddcEHzgzUb19-VG3UT0G0LuANhtgcSXR1RWbo,6733
|
|
34
|
+
Typhon/Transform/placeholder_to_function.py,sha256=xmeQUpFqpEiDuarDmvljsLZ9dvWYuHl7au-qGpgcFRI,5069
|
|
35
|
+
Typhon/Transform/record_to_dataclass.py,sha256=aAcqOIxYlQvJitorqkU3m_AEtI7NnB8YPvnnMWj-3-8,8579
|
|
36
|
+
Typhon/Transform/scope_check_rename.py,sha256=z1YIiDSWmS1vftTFhz_ateeZLGYlZCR8Y6Q_dDulz0c,32952
|
|
37
|
+
Typhon/Transform/transform.py,sha256=wHVOlG5ZzclDOB2kiPRWmmWCNeO5XCEiIw3OT-29mN0,2548
|
|
38
|
+
Typhon/Transform/type_abbrev_desugar.py,sha256=9-MMCbU9yevVsumse0mk87GojI1pbO9eSR4C7lZm9q8,6733
|
|
39
|
+
Typhon/Transform/type_annotation_check_expand.py,sha256=wXjVEC91lJptRwMGgu4kpcEGJBINBtovPGNtVgZkYcA,10461
|
|
40
|
+
Typhon/Transform/visitor.py,sha256=PrBI-QFYFILpFLK2EmfoH6wx3Qa9fVVs72Jiw2Qz3cg,11777
|
|
41
|
+
Typhon/Transform/utils/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
42
|
+
Typhon/Transform/utils/imports.py,sha256=PH9h8kjZ9AJnmEZ0zD3WQ5zzjn7GUqu4Qgm-d5EpVSM,1279
|
|
43
|
+
Typhon/Transform/utils/jump_away.py,sha256=8iGakrHaCQp9Te9_XYZ5-mGFUWmNKCBABnDKg1T2HVg,2998
|
|
44
|
+
Typhon/Transform/utils/make_class.py,sha256=pi1Oamkr__pg_eU6YCJ9LTGRrFrUzqbMyVlXJReaVLM,4464
|
|
45
|
+
Typhon/Typing/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
46
|
+
Typhon/Typing/pyright.py,sha256=IUSQOpVjSd-vMvQCMko053l3UyiXqmV-72vYiTWwTcY,4735
|
|
47
|
+
Typhon/Typing/result_diagnostic.py,sha256=kZYyzCvbXIxqIcvsMgJq7hxrwSZ4PB4IgD2Yt_VT93Q,3680
|
|
48
|
+
typhon_language-0.1.3.dist-info/licenses/LICENSE,sha256=k1dBJysU0_U_eCiP1Nt6MhoHmhhOaaXgDHeagjORZs0,1074
|
|
49
|
+
typhon_language-0.1.3.dist-info/METADATA,sha256=802Djmd-J6omyuuNBZESNhEuXigbOoQy8rJATBiq-co,6332
|
|
50
|
+
typhon_language-0.1.3.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
|
51
|
+
typhon_language-0.1.3.dist-info/entry_points.txt,sha256=a_tTwpYswStM7ViRyF0j7qn9jV3lN0TpGiYG8TQEjMw,48
|
|
52
|
+
typhon_language-0.1.3.dist-info/top_level.txt,sha256=H83GWRaycF_6jk0COdUlzXliigwTNM00Svnlp_k9F5Y,7
|
|
53
|
+
typhon_language-0.1.3.dist-info/RECORD,,
|
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
Typhon/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
2
|
-
Typhon/__main__.py,sha256=9vd3zChySHgfQmXqLaBYBXerUATC0m_BgI1clg3HRf4,1053
|
|
3
|
-
Typhon/Driver/debugging.py,sha256=O2cYsu4Y4xmFfgmYm8NQoyrqqXgqzzLrAWZJFxxIoUM,892
|
|
4
|
-
Typhon/Driver/diagnostic.py,sha256=gB3byTB3EOrVfCWVAH2_nrxtF2-Tgzb_9WZIcNwzoNE,1256
|
|
5
|
-
Typhon/Driver/run.py,sha256=xQLcBaI0vzYTPMQtYVQrukP0o7Fk6I59--fRl0Z2M8A,4553
|
|
6
|
-
Typhon/Driver/translate.py,sha256=KsKDO1Rnj3g5FlS6wgEQOh1_NRGVwXHlFlWb56Nq7uY,6699
|
|
7
|
-
Typhon/Driver/type_check.py,sha256=9PDKsmAPcpdtQqZAE7LDjM8ynjKz02rNZwXDG2Kb3LE,1516
|
|
8
|
-
Typhon/Driver/utils.py,sha256=ATckYbYYwo3NTlLKAWJqAjjNAZ_n9IGMFyqONSKP1rk,1506
|
|
9
|
-
Typhon/Grammar/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
10
|
-
Typhon/Grammar/_typhon_parser.py,sha256=ZIHhHtfgxZH8DDiBLUwQFLW-p-Wch_tQjzZE5gD400g,447024
|
|
11
|
-
Typhon/Grammar/line_break.py,sha256=lH2is1yAubG1fhXw5SbQUvlfmeLH7h3PbOEiVrAfRA0,2712
|
|
12
|
-
Typhon/Grammar/parser.py,sha256=AIWQzSYOjXkH6kwDf2kRatwKxUqRkTVNoeYJhhVtL0U,1434
|
|
13
|
-
Typhon/Grammar/parser_helper.py,sha256=i0CkjhXF4W9SPrYRB785weiaaO7LaoY2xBNXHZlAsnc,17989
|
|
14
|
-
Typhon/Grammar/syntax_errors.py,sha256=Bmpw_CyzUcHnXjzWV8Gac_UlwfAyUiDF9vnvQLsACUc,4857
|
|
15
|
-
Typhon/Grammar/token_factory_custom.py,sha256=qA2LJ_vriEu3eNpWCqFCdp363j5npJP3PbkN-e3oHow,20620
|
|
16
|
-
Typhon/Grammar/tokenizer_custom.py,sha256=51WkJ0AxDwOBfo5bdtRtSary-uXlIs9sG9l-UWCE2uY,9657
|
|
17
|
-
Typhon/Grammar/typhon_ast.py,sha256=_IOB8LVvOWV1axUIjT4b6M9AkmP4YE-vLncCKwTuCFQ,49765
|
|
18
|
-
Typhon/SourceMap/__init__.py,sha256=t56lq7YFlqhEfpW9_xHyIs2n_hhYuycMNRpyV9vjMI4,599
|
|
19
|
-
Typhon/SourceMap/ast_match_based_map.py,sha256=UiGOoinEt6nk17dl58UHZXwauAQMXP74H5zlD8w_bkQ,6382
|
|
20
|
-
Typhon/SourceMap/ast_matching.py,sha256=4-6awc4vosMoiSwuGFA82bPAsYbLDQQr7SKJ9Rl33lM,3328
|
|
21
|
-
Typhon/SourceMap/datatype.py,sha256=Xa7KSt69MDRCtiu2NjtQyITM4GLSR7rXJsxKhOyXIcg,10108
|
|
22
|
-
Typhon/Transform/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
23
|
-
Typhon/Transform/comprehension_to_function.py,sha256=PmZ8gTzlp028Ge_YAMMWngqvTcRex5URIkICOIaS1PM,2721
|
|
24
|
-
Typhon/Transform/const_member_to_final.py,sha256=eo1aM_PlMrEJXdIelZ9RtxMl3HMpNg_isj3SfsQFGkA,2558
|
|
25
|
-
Typhon/Transform/forbidden_statements.py,sha256=wG2tfKJPA-xi-ju_EIM58WkCt4YEc8osZaLY3ov9W1k,3604
|
|
26
|
-
Typhon/Transform/func_literal_to_def.py,sha256=SxI6lpktyeYFSmoVPqcDmKZ5CQcVXEmkg5sy1AtMPy0,2675
|
|
27
|
-
Typhon/Transform/if_while_let.py,sha256=36xeCGFp0x2TBEGtZ7rDuRmp9EmBm-ygCBhw2ngECyI,6389
|
|
28
|
-
Typhon/Transform/inline_statement_block_capture.py,sha256=1TsU0wk38qhLkkvo72DociZz6ifOwKS2-JoQ62hYhGA,8236
|
|
29
|
-
Typhon/Transform/insert_self_to_method.py,sha256=O9dOFx9wtYWwN0wR7D5PmX51REy1VKEzvVNt7lIVRRU,1593
|
|
30
|
-
Typhon/Transform/name_generator.py,sha256=_mAmG7ynGQEP4qBqp2rIpY3qMWC95UGbXTwHXBTYYPU,5906
|
|
31
|
-
Typhon/Transform/optional_operators_to_checked.py,sha256=Fb01bQddcEHzgzUb19-VG3UT0G0LuANhtgcSXR1RWbo,6733
|
|
32
|
-
Typhon/Transform/placeholder_to_function.py,sha256=pnkT9jpAqr1TB00yjVr6uaAQd7I2di_IZJ1OsnJ4KL4,5152
|
|
33
|
-
Typhon/Transform/record_to_dataclass.py,sha256=2oc6oxQoiIDCuCySVyMeBEsHcgFrLDuog3PbKJPVreo,15898
|
|
34
|
-
Typhon/Transform/scope_check_rename.py,sha256=bQ0n6BfftewRl8z5XfZR0277tZXKIzBUEbCHDWbNodw,30682
|
|
35
|
-
Typhon/Transform/transform.py,sha256=fi1Mk4Xp4riSPXJp_eK0nOyLDNGPG-4KSc4PB7i-wzo,2306
|
|
36
|
-
Typhon/Transform/type_abbrev_desugar.py,sha256=K13ZYY1gCRH6UCqaalL3QuZel5OG4s55wMnn5Z7Fc6Q,6725
|
|
37
|
-
Typhon/Transform/type_annotation_check_expand.py,sha256=wXjVEC91lJptRwMGgu4kpcEGJBINBtovPGNtVgZkYcA,10461
|
|
38
|
-
Typhon/Transform/utils.py,sha256=NCaqs7jdhg8MqzSOp2lwBE8FR4q3_fIPeBrm4KKh-r4,3937
|
|
39
|
-
Typhon/Transform/visitor.py,sha256=PrBI-QFYFILpFLK2EmfoH6wx3Qa9fVVs72Jiw2Qz3cg,11777
|
|
40
|
-
Typhon/Typing/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
41
|
-
Typhon/Typing/pyright.py,sha256=ScJOZ9uMsIovj_4xcZmPJ2ggDqI3Ju17n6dfkLku7jI,4867
|
|
42
|
-
Typhon/Typing/result_diagnostic.py,sha256=rXHlqoWPl6yQbYamJPRO08Xo4D5CXxUxSfLnix06mAs,3679
|
|
43
|
-
typhon_language-0.1.1.dist-info/licenses/LICENSE,sha256=k1dBJysU0_U_eCiP1Nt6MhoHmhhOaaXgDHeagjORZs0,1074
|
|
44
|
-
typhon_language-0.1.1.dist-info/METADATA,sha256=HNITksFf84wH_HU4M4ba_ftqR396ZXZBxLyWWlWaG7s,5232
|
|
45
|
-
typhon_language-0.1.1.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
|
46
|
-
typhon_language-0.1.1.dist-info/entry_points.txt,sha256=a_tTwpYswStM7ViRyF0j7qn9jV3lN0TpGiYG8TQEjMw,48
|
|
47
|
-
typhon_language-0.1.1.dist-info/top_level.txt,sha256=H83GWRaycF_6jk0COdUlzXliigwTNM00Svnlp_k9F5Y,7
|
|
48
|
-
typhon_language-0.1.1.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|