nova-pl 1.0.0__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.
Files changed (57) hide show
  1. nova/__init__.py +6 -0
  2. nova/api.py +41 -0
  3. nova/ast/__init__.py +101 -0
  4. nova/ast/base.py +26 -0
  5. nova/ast/expressions.py +148 -0
  6. nova/ast/literals.py +106 -0
  7. nova/ast/statements.py +411 -0
  8. nova/ast/types.py +56 -0
  9. nova/cli.py +124 -0
  10. nova/errors/__init__.py +91 -0
  11. nova/errors/base.py +24 -0
  12. nova/errors/lexer_errors.py +21 -0
  13. nova/errors/parser_errors.py +20 -0
  14. nova/errors/runtime_errors.py +75 -0
  15. nova/errors/type_errors.py +25 -0
  16. nova/interpreter/__init__.py +5 -0
  17. nova/interpreter/base.py +297 -0
  18. nova/interpreter/builtins/__init__.py +0 -0
  19. nova/interpreter/builtins/arrays.py +288 -0
  20. nova/interpreter/builtins/conversion.py +107 -0
  21. nova/interpreter/builtins/input.py +40 -0
  22. nova/interpreter/builtins/intrinsic_array.py +168 -0
  23. nova/interpreter/builtins/intrinsic_math.py +265 -0
  24. nova/interpreter/builtins/intrinsic_random.py +153 -0
  25. nova/interpreter/builtins/intrinsic_stats.py +169 -0
  26. nova/interpreter/builtins/intrinsic_time.py +93 -0
  27. nova/interpreter/builtins/registry.py +129 -0
  28. nova/interpreter/builtins/strings.py +239 -0
  29. nova/interpreter/collections.py +348 -0
  30. nova/interpreter/environment.py +506 -0
  31. nova/interpreter/expressions.py +502 -0
  32. nova/interpreter/interpreter.py +5 -0
  33. nova/interpreter/loop_signals.py +10 -0
  34. nova/interpreter/runtime_values.py +96 -0
  35. nova/interpreter/statements.py +398 -0
  36. nova/interpreter/type_resolver.py +302 -0
  37. nova/lexer/__init__.py +0 -0
  38. nova/lexer/lexer.py +427 -0
  39. nova/lexer/token.py +25 -0
  40. nova/lexer/token_types.py +82 -0
  41. nova/modules/__init__.py +0 -0
  42. nova/modules/loader.py +39 -0
  43. nova/modules/resolver.py +90 -0
  44. nova/parser/__init__.py +0 -0
  45. nova/parser/parser.py +1695 -0
  46. nova/pipeline.py +28 -0
  47. nova/stdlibs/array.nova +19 -0
  48. nova/stdlibs/math.nova +33 -0
  49. nova/stdlibs/random.nova +19 -0
  50. nova/stdlibs/stats.nova +19 -0
  51. nova/stdlibs/time.nova +15 -0
  52. nova_pl-1.0.0.dist-info/METADATA +426 -0
  53. nova_pl-1.0.0.dist-info/RECORD +57 -0
  54. nova_pl-1.0.0.dist-info/WHEEL +5 -0
  55. nova_pl-1.0.0.dist-info/entry_points.txt +2 -0
  56. nova_pl-1.0.0.dist-info/licenses/LICENSE +21 -0
  57. nova_pl-1.0.0.dist-info/top_level.txt +1 -0
nova/__init__.py ADDED
@@ -0,0 +1,6 @@
1
+ from importlib.metadata import PackageNotFoundError, version
2
+
3
+ try:
4
+ __version__ = version("nova-lang")
5
+ except PackageNotFoundError:
6
+ __version__ = "1.0.0"
nova/api.py ADDED
@@ -0,0 +1,41 @@
1
+ from nova.modules.resolver import ModuleResolver
2
+ from nova.pipeline import create_interpreter
3
+
4
+
5
+ def run_source(
6
+ source: str,
7
+ input_provider=None,
8
+ project_root=None,
9
+ output_callback=None,
10
+ ):
11
+ resolver = ModuleResolver(
12
+ project_root=project_root,
13
+ )
14
+
15
+ interpreter = create_interpreter(
16
+ source,
17
+ input_provider=input_provider,
18
+ resolver=resolver,
19
+ output_callback=output_callback,
20
+ )
21
+
22
+ return interpreter.output
23
+
24
+
25
+ def run_file(
26
+ path: str,
27
+ input_provider=None,
28
+ project_root=None,
29
+ output_callback=None,
30
+ ):
31
+ with open(path, "r", encoding="utf-8") as file:
32
+ source = file.read()
33
+
34
+ output = run_source(
35
+ source,
36
+ input_provider=input_provider,
37
+ project_root=project_root,
38
+ output_callback=output_callback,
39
+ )
40
+
41
+ return source, output
nova/ast/__init__.py ADDED
@@ -0,0 +1,101 @@
1
+ from .base import (
2
+ Node,
3
+ Statement,
4
+ Expression,
5
+ )
6
+
7
+ from .statements import (
8
+ Program,
9
+ VariableDeclaration,
10
+ ConstantDeclaration,
11
+ FunctionDeclaration,
12
+ Parameter,
13
+ Assignment,
14
+ ArrayAssignment,
15
+ SchemaDeclaration,
16
+ PropertyAssignment,
17
+ ReturnStatement,
18
+ PrintStatement,
19
+ BlockStatement,
20
+ IfStatement,
21
+ WhileStatement,
22
+ ForRangeStatement,
23
+ ForEachStatement,
24
+ BreakStatement,
25
+ ContinueStatement,
26
+ ImportStatement,
27
+ ImportItem,
28
+ )
29
+
30
+ from .expressions import (
31
+ Identifier,
32
+ ArrayAccess,
33
+ PropertyAccess,
34
+ BinaryExpression,
35
+ UnaryExpression,
36
+ TernaryExpression,
37
+ FunctionCall,
38
+ )
39
+
40
+ from .literals import (
41
+ NumberLiteral,
42
+ StringLiteral,
43
+ BooleanLiteral,
44
+ NullLiteral,
45
+ ArrayLiteral,
46
+ MapEntry,
47
+ MapLiteral,
48
+ )
49
+
50
+ from .types import (
51
+ ArrayType,
52
+ SchemaField,
53
+ SchemaType,
54
+ )
55
+
56
+ __all__ = [
57
+ "Node",
58
+ "Statement",
59
+ "Expression",
60
+ # Statements
61
+ "Program",
62
+ "VariableDeclaration",
63
+ "ConstantDeclaration",
64
+ "FunctionDeclaration",
65
+ "Parameter",
66
+ "Assignment",
67
+ "ArrayAssignment",
68
+ "SchemaDeclaration",
69
+ "PropertyAssignment",
70
+ "ReturnStatement",
71
+ "PrintStatement",
72
+ "BlockStatement",
73
+ "IfStatement",
74
+ "WhileStatement",
75
+ "ForRangeStatement",
76
+ "ForEachStatement",
77
+ "BreakStatement",
78
+ "ContinueStatement",
79
+ "ImportStatement",
80
+ "ImportItem",
81
+ # Expressions
82
+ "Identifier",
83
+ "ArrayAccess",
84
+ "PropertyAccess",
85
+ "BinaryExpression",
86
+ "UnaryExpression",
87
+ "TernaryExpression",
88
+ "FunctionCall",
89
+ # Literals
90
+ "NumberLiteral",
91
+ "StringLiteral",
92
+ "BooleanLiteral",
93
+ "NullLiteral",
94
+ "ArrayLiteral",
95
+ "MapEntry",
96
+ "MapLiteral",
97
+ # Types
98
+ "ArrayType",
99
+ "SchemaField",
100
+ "SchemaType",
101
+ ]
nova/ast/base.py ADDED
@@ -0,0 +1,26 @@
1
+ class Node:
2
+ def __init__(
3
+ self,
4
+ line=None,
5
+ column=None,
6
+ ):
7
+ self.line = line
8
+ self.column = column
9
+
10
+
11
+ class Statement(Node):
12
+ def __init__(
13
+ self,
14
+ line=None,
15
+ column=None,
16
+ ):
17
+ super().__init__(line, column)
18
+
19
+
20
+ class Expression(Node):
21
+ def __init__(
22
+ self,
23
+ line=None,
24
+ column=None,
25
+ ):
26
+ super().__init__(line, column)
@@ -0,0 +1,148 @@
1
+ from nova.ast.base import Expression
2
+
3
+
4
+ class Identifier(Expression):
5
+ def __init__(
6
+ self,
7
+ name,
8
+ line=None,
9
+ column=None,
10
+ ):
11
+ super().__init__(line, column)
12
+
13
+ self.name = name
14
+
15
+ def __repr__(self):
16
+ return f"Identifier({self.name!r})"
17
+
18
+
19
+ class ArrayAccess(Expression):
20
+ def __init__(
21
+ self,
22
+ array,
23
+ index,
24
+ line=None,
25
+ column=None,
26
+ ):
27
+ super().__init__(line, column)
28
+
29
+ self.array = array
30
+ self.index = index
31
+
32
+ def __repr__(self):
33
+ return f"ArrayAccess(" f"array={self.array}, " f"index={self.index}" f")"
34
+
35
+
36
+ class PropertyAccess(Expression):
37
+ def __init__(
38
+ self,
39
+ target,
40
+ property_name,
41
+ line=None,
42
+ column=None,
43
+ ):
44
+ super().__init__(line, column)
45
+
46
+ self.target = target
47
+ self.property_name = property_name
48
+
49
+ def __repr__(self):
50
+ return (
51
+ f"PropertyAccess("
52
+ f"target={self.target}, "
53
+ f"property_name={self.property_name!r}"
54
+ f")"
55
+ )
56
+
57
+
58
+ class BinaryExpression(Expression):
59
+ def __init__(
60
+ self,
61
+ left,
62
+ operator,
63
+ right,
64
+ line=None,
65
+ column=None,
66
+ ):
67
+ super().__init__(line, column)
68
+
69
+ self.left = left
70
+ self.operator = operator
71
+ self.right = right
72
+
73
+ def __repr__(self):
74
+ return (
75
+ f"BinaryExpression("
76
+ f"left={self.left}, "
77
+ f"operator={self.operator!r}, "
78
+ f"right={self.right}"
79
+ f")"
80
+ )
81
+
82
+
83
+ class UnaryExpression(Expression):
84
+ def __init__(
85
+ self,
86
+ operator,
87
+ operand,
88
+ line=None,
89
+ column=None,
90
+ ):
91
+ super().__init__(line, column)
92
+
93
+ self.operator = operator
94
+ self.operand = operand
95
+
96
+ def __repr__(self):
97
+ return (
98
+ f"UnaryExpression("
99
+ f"operator={self.operator!r}, "
100
+ f"operand={self.operand}"
101
+ f")"
102
+ )
103
+
104
+
105
+ class TernaryExpression(Expression):
106
+ def __init__(
107
+ self,
108
+ condition,
109
+ true_expression,
110
+ false_expression,
111
+ line=None,
112
+ column=None,
113
+ ):
114
+ super().__init__(line, column)
115
+
116
+ self.condition = condition
117
+ self.true_expression = true_expression
118
+ self.false_expression = false_expression
119
+
120
+ def __repr__(self):
121
+ return (
122
+ f"TernaryExpression("
123
+ f"condition={self.condition}, "
124
+ f"true_expression={self.true_expression}, "
125
+ f"false_expression={self.false_expression}"
126
+ f")"
127
+ )
128
+
129
+ class FunctionCall(Expression):
130
+ def __init__(
131
+ self,
132
+ callee,
133
+ arguments,
134
+ line=None,
135
+ column=None,
136
+ ):
137
+ super().__init__(line, column)
138
+
139
+ self.callee = callee
140
+ self.arguments = arguments
141
+
142
+ def __repr__(self):
143
+ return (
144
+ f"FunctionCall("
145
+ f"callee={self.callee}, "
146
+ f"arguments={self.arguments}"
147
+ f")"
148
+ )
nova/ast/literals.py ADDED
@@ -0,0 +1,106 @@
1
+ from nova.ast.base import Expression
2
+ from nova.ast.base import Node
3
+
4
+
5
+ class NumberLiteral(Expression):
6
+ def __init__(
7
+ self,
8
+ value,
9
+ line=None,
10
+ column=None,
11
+ ):
12
+ super().__init__(line, column)
13
+
14
+ self.value = value
15
+
16
+ def __repr__(self):
17
+ return f"NumberLiteral({self.value})"
18
+
19
+
20
+ class StringLiteral(Expression):
21
+ def __init__(
22
+ self,
23
+ value,
24
+ line=None,
25
+ column=None,
26
+ ):
27
+ super().__init__(line, column)
28
+
29
+ self.value = value
30
+
31
+ def __repr__(self):
32
+ return f"StringLiteral({self.value!r})"
33
+
34
+
35
+ class BooleanLiteral(Expression):
36
+ def __init__(
37
+ self,
38
+ value,
39
+ line=None,
40
+ column=None,
41
+ ):
42
+ super().__init__(line, column)
43
+
44
+ self.value = value
45
+
46
+ def __repr__(self):
47
+ return f"BooleanLiteral({self.value})"
48
+
49
+
50
+ class NullLiteral(Expression):
51
+ def __init__(
52
+ self,
53
+ line=None,
54
+ column=None,
55
+ ):
56
+ super().__init__(line, column)
57
+
58
+ def __repr__(self):
59
+ return "NullLiteral()"
60
+
61
+
62
+ class ArrayLiteral(Expression):
63
+ def __init__(
64
+ self,
65
+ elements,
66
+ line=None,
67
+ column=None,
68
+ ):
69
+ super().__init__(line, column)
70
+
71
+ self.elements = elements
72
+
73
+ def __repr__(self):
74
+ return f"ArrayLiteral({self.elements})"
75
+
76
+
77
+ class MapEntry(Node):
78
+ def __init__(
79
+ self,
80
+ key,
81
+ value,
82
+ line=None,
83
+ column=None,
84
+ ):
85
+ super().__init__(line, column)
86
+
87
+ self.key = key
88
+ self.value = value
89
+
90
+ def __repr__(self):
91
+ return f"MapEntry(" f"key={self.key!r}, " f"value={self.value}" f")"
92
+
93
+
94
+ class MapLiteral(Expression):
95
+ def __init__(
96
+ self,
97
+ entries,
98
+ line=None,
99
+ column=None,
100
+ ):
101
+ super().__init__(line, column)
102
+
103
+ self.entries = entries
104
+
105
+ def __repr__(self):
106
+ return f"MapLiteral({self.entries})"