eigrel 0.1.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.
- eigrel/__init__.py +3 -0
- eigrel/__main__.py +5 -0
- eigrel/cli.py +143 -0
- eigrel/compiler/__init__.py +7 -0
- eigrel/compiler/ast.py +158 -0
- eigrel/compiler/errors.py +33 -0
- eigrel/compiler/lexer.py +126 -0
- eigrel/compiler/parser.py +261 -0
- eigrel/compiler/tokens.py +102 -0
- eigrel-0.1.0.dist-info/METADATA +135 -0
- eigrel-0.1.0.dist-info/RECORD +15 -0
- eigrel-0.1.0.dist-info/WHEEL +5 -0
- eigrel-0.1.0.dist-info/entry_points.txt +2 -0
- eigrel-0.1.0.dist-info/licenses/LICENSE +202 -0
- eigrel-0.1.0.dist-info/top_level.txt +1 -0
eigrel/__init__.py
ADDED
eigrel/__main__.py
ADDED
eigrel/cli.py
ADDED
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
import argparse
|
|
2
|
+
import json
|
|
3
|
+
import sys
|
|
4
|
+
from pathlib import Path
|
|
5
|
+
|
|
6
|
+
from eigrel import __version__
|
|
7
|
+
from eigrel.compiler import EigrelError, parse, tokenize
|
|
8
|
+
from eigrel.compiler.ast import Program, to_dict
|
|
9
|
+
|
|
10
|
+
STARTER_PROGRAM = """\
|
|
11
|
+
# A first Eigrel pipeline: load data, pick features, train and evaluate a model.
|
|
12
|
+
|
|
13
|
+
dataset customers from csv("data/customers.csv")
|
|
14
|
+
|
|
15
|
+
transform customers {
|
|
16
|
+
filter age >= 18
|
|
17
|
+
select age, income, purchases, churned
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
features customers {
|
|
21
|
+
age
|
|
22
|
+
income
|
|
23
|
+
purchases
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
model churn = random_forest {
|
|
27
|
+
trees = 100
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
train churn {
|
|
31
|
+
target = churned
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
evaluate churn {
|
|
35
|
+
metrics = [accuracy, precision, recall, f1]
|
|
36
|
+
}
|
|
37
|
+
"""
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
def _load(path: str) -> tuple[str, str] | None:
|
|
41
|
+
try:
|
|
42
|
+
return Path(path).read_text(encoding='utf-8'), path
|
|
43
|
+
except OSError as exc:
|
|
44
|
+
print(f'error: cannot read {path}: {exc.strerror}', file=sys.stderr)
|
|
45
|
+
return None
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
def _parse_file(path: str) -> Program | None:
|
|
49
|
+
loaded = _load(path)
|
|
50
|
+
if loaded is None:
|
|
51
|
+
return None
|
|
52
|
+
source, filename = loaded
|
|
53
|
+
try:
|
|
54
|
+
return parse(source)
|
|
55
|
+
except EigrelError as exc:
|
|
56
|
+
print(exc.render(source, filename), file=sys.stderr)
|
|
57
|
+
return None
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
def cmd_check(args: argparse.Namespace) -> int:
|
|
61
|
+
failed = 0
|
|
62
|
+
for path in args.files:
|
|
63
|
+
program = _parse_file(path)
|
|
64
|
+
if program is None:
|
|
65
|
+
failed += 1
|
|
66
|
+
else:
|
|
67
|
+
count = len(program.statements)
|
|
68
|
+
noun = 'statement' if count == 1 else 'statements'
|
|
69
|
+
print(f'ok: {path} ({count} {noun})')
|
|
70
|
+
return 1 if failed else 0
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
def cmd_ast(args: argparse.Namespace) -> int:
|
|
74
|
+
program = _parse_file(args.file)
|
|
75
|
+
if program is None:
|
|
76
|
+
return 1
|
|
77
|
+
print(json.dumps(to_dict(program), indent=2))
|
|
78
|
+
return 0
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
def cmd_tokens(args: argparse.Namespace) -> int:
|
|
82
|
+
loaded = _load(args.file)
|
|
83
|
+
if loaded is None:
|
|
84
|
+
return 1
|
|
85
|
+
source, filename = loaded
|
|
86
|
+
try:
|
|
87
|
+
tokens = tokenize(source)
|
|
88
|
+
except EigrelError as exc:
|
|
89
|
+
print(exc.render(source, filename), file=sys.stderr)
|
|
90
|
+
return 1
|
|
91
|
+
for token in tokens:
|
|
92
|
+
print(f'{token.loc.line}:{token.loc.column}\t{token.kind.name}\t{token.text}')
|
|
93
|
+
return 0
|
|
94
|
+
|
|
95
|
+
|
|
96
|
+
def cmd_init(args: argparse.Namespace) -> int:
|
|
97
|
+
root = Path(args.name)
|
|
98
|
+
if root.exists():
|
|
99
|
+
print(f'error: {root} already exists', file=sys.stderr)
|
|
100
|
+
return 1
|
|
101
|
+
(root / 'data').mkdir(parents=True)
|
|
102
|
+
(root / 'main.eig').write_text(STARTER_PROGRAM, encoding='utf-8')
|
|
103
|
+
print(f'created {root}/main.eig')
|
|
104
|
+
print(f'next: eigrel check {root}/main.eig')
|
|
105
|
+
return 0
|
|
106
|
+
|
|
107
|
+
|
|
108
|
+
def build_parser() -> argparse.ArgumentParser:
|
|
109
|
+
parser = argparse.ArgumentParser(
|
|
110
|
+
prog='eigrel',
|
|
111
|
+
description='Eigrel: a programming language for Data, Machine Learning and AI.',
|
|
112
|
+
)
|
|
113
|
+
parser.add_argument('--version', action='version', version=f'eigrel {__version__}')
|
|
114
|
+
commands = parser.add_subparsers(dest='command', required=True)
|
|
115
|
+
|
|
116
|
+
check = commands.add_parser('check', help='parse files and report syntax errors')
|
|
117
|
+
check.add_argument('files', nargs='+', metavar='FILE')
|
|
118
|
+
check.set_defaults(handler=cmd_check)
|
|
119
|
+
|
|
120
|
+
ast_cmd = commands.add_parser('ast', help='print the syntax tree of a file as JSON')
|
|
121
|
+
ast_cmd.add_argument('file', metavar='FILE')
|
|
122
|
+
ast_cmd.set_defaults(handler=cmd_ast)
|
|
123
|
+
|
|
124
|
+
tokens = commands.add_parser('tokens', help='print the tokens of a file')
|
|
125
|
+
tokens.add_argument('file', metavar='FILE')
|
|
126
|
+
tokens.set_defaults(handler=cmd_tokens)
|
|
127
|
+
|
|
128
|
+
init = commands.add_parser('init', help='create a new Eigrel project')
|
|
129
|
+
init.add_argument('name', metavar='NAME')
|
|
130
|
+
init.set_defaults(handler=cmd_init)
|
|
131
|
+
|
|
132
|
+
return parser
|
|
133
|
+
|
|
134
|
+
|
|
135
|
+
def main(argv: list[str] | None = None) -> int:
|
|
136
|
+
args = build_parser().parse_args(argv)
|
|
137
|
+
handler = args.handler
|
|
138
|
+
result: int = handler(args)
|
|
139
|
+
return result
|
|
140
|
+
|
|
141
|
+
|
|
142
|
+
if __name__ == '__main__':
|
|
143
|
+
sys.exit(main())
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
"""Front end of the Eigrel compiler: lexer, parser and AST."""
|
|
2
|
+
|
|
3
|
+
from eigrel.compiler.errors import EigrelError, LexError, ParseError
|
|
4
|
+
from eigrel.compiler.lexer import tokenize
|
|
5
|
+
from eigrel.compiler.parser import parse
|
|
6
|
+
|
|
7
|
+
__all__ = ['EigrelError', 'LexError', 'ParseError', 'parse', 'tokenize']
|
eigrel/compiler/ast.py
ADDED
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
from dataclasses import dataclass, field, fields
|
|
2
|
+
from typing import Any
|
|
3
|
+
|
|
4
|
+
from eigrel.compiler.tokens import Location
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
@dataclass(frozen=True)
|
|
8
|
+
class Node:
|
|
9
|
+
loc: Location = field(compare=False, kw_only=True)
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
# Expressions
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
@dataclass(frozen=True)
|
|
16
|
+
class Name(Node):
|
|
17
|
+
value: str
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
@dataclass(frozen=True)
|
|
21
|
+
class IntLiteral(Node):
|
|
22
|
+
value: int
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
@dataclass(frozen=True)
|
|
26
|
+
class FloatLiteral(Node):
|
|
27
|
+
value: float
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
@dataclass(frozen=True)
|
|
31
|
+
class StringLiteral(Node):
|
|
32
|
+
value: str
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
@dataclass(frozen=True)
|
|
36
|
+
class BoolLiteral(Node):
|
|
37
|
+
value: bool
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
@dataclass(frozen=True)
|
|
41
|
+
class ListExpr(Node):
|
|
42
|
+
items: tuple['Expr', ...]
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
@dataclass(frozen=True)
|
|
46
|
+
class Call(Node):
|
|
47
|
+
func: str
|
|
48
|
+
args: tuple['Expr', ...]
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
@dataclass(frozen=True)
|
|
52
|
+
class Unary(Node):
|
|
53
|
+
op: str
|
|
54
|
+
operand: 'Expr'
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
@dataclass(frozen=True)
|
|
58
|
+
class Binary(Node):
|
|
59
|
+
op: str
|
|
60
|
+
left: 'Expr'
|
|
61
|
+
right: 'Expr'
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
Expr = (
|
|
65
|
+
Name
|
|
66
|
+
| IntLiteral
|
|
67
|
+
| FloatLiteral
|
|
68
|
+
| StringLiteral
|
|
69
|
+
| BoolLiteral
|
|
70
|
+
| ListExpr
|
|
71
|
+
| Call
|
|
72
|
+
| Unary
|
|
73
|
+
| Binary
|
|
74
|
+
)
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
# Block contents
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
@dataclass(frozen=True)
|
|
81
|
+
class Param(Node):
|
|
82
|
+
name: str
|
|
83
|
+
value: Expr
|
|
84
|
+
|
|
85
|
+
|
|
86
|
+
@dataclass(frozen=True)
|
|
87
|
+
class FilterOp(Node):
|
|
88
|
+
condition: Expr
|
|
89
|
+
|
|
90
|
+
|
|
91
|
+
@dataclass(frozen=True)
|
|
92
|
+
class SelectOp(Node):
|
|
93
|
+
columns: tuple[Name, ...]
|
|
94
|
+
|
|
95
|
+
|
|
96
|
+
TransformOp = FilterOp | SelectOp
|
|
97
|
+
|
|
98
|
+
|
|
99
|
+
# Statements
|
|
100
|
+
|
|
101
|
+
|
|
102
|
+
@dataclass(frozen=True)
|
|
103
|
+
class DatasetDecl(Node):
|
|
104
|
+
name: str
|
|
105
|
+
source: Call
|
|
106
|
+
|
|
107
|
+
|
|
108
|
+
@dataclass(frozen=True)
|
|
109
|
+
class TransformDecl(Node):
|
|
110
|
+
dataset: str
|
|
111
|
+
ops: tuple[TransformOp, ...]
|
|
112
|
+
|
|
113
|
+
|
|
114
|
+
@dataclass(frozen=True)
|
|
115
|
+
class FeaturesDecl(Node):
|
|
116
|
+
dataset: str
|
|
117
|
+
columns: tuple[Name, ...]
|
|
118
|
+
|
|
119
|
+
|
|
120
|
+
@dataclass(frozen=True)
|
|
121
|
+
class ModelDecl(Node):
|
|
122
|
+
name: str
|
|
123
|
+
algorithm: str
|
|
124
|
+
params: tuple[Param, ...]
|
|
125
|
+
|
|
126
|
+
|
|
127
|
+
@dataclass(frozen=True)
|
|
128
|
+
class TrainStmt(Node):
|
|
129
|
+
model: str
|
|
130
|
+
params: tuple[Param, ...]
|
|
131
|
+
|
|
132
|
+
|
|
133
|
+
@dataclass(frozen=True)
|
|
134
|
+
class EvaluateStmt(Node):
|
|
135
|
+
model: str
|
|
136
|
+
params: tuple[Param, ...]
|
|
137
|
+
|
|
138
|
+
|
|
139
|
+
Statement = DatasetDecl | TransformDecl | FeaturesDecl | ModelDecl | TrainStmt | EvaluateStmt
|
|
140
|
+
|
|
141
|
+
|
|
142
|
+
@dataclass(frozen=True)
|
|
143
|
+
class Program(Node):
|
|
144
|
+
statements: tuple[Statement, ...]
|
|
145
|
+
|
|
146
|
+
|
|
147
|
+
def to_dict(value: Any) -> Any:
|
|
148
|
+
"""Convert an AST into plain JSON-serializable data."""
|
|
149
|
+
if isinstance(value, Node):
|
|
150
|
+
data: dict[str, Any] = {'node': type(value).__name__}
|
|
151
|
+
for f in fields(value):
|
|
152
|
+
if f.name != 'loc':
|
|
153
|
+
data[f.name] = to_dict(getattr(value, f.name))
|
|
154
|
+
data['loc'] = {'line': value.loc.line, 'column': value.loc.column}
|
|
155
|
+
return data
|
|
156
|
+
if isinstance(value, tuple):
|
|
157
|
+
return [to_dict(item) for item in value]
|
|
158
|
+
return value
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
from eigrel.compiler.tokens import Location
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
class EigrelError(Exception):
|
|
5
|
+
"""A compile-time error tied to a position in the source file."""
|
|
6
|
+
|
|
7
|
+
def __init__(self, message: str, loc: Location) -> None:
|
|
8
|
+
super().__init__(message)
|
|
9
|
+
self.message = message
|
|
10
|
+
self.loc = loc
|
|
11
|
+
|
|
12
|
+
def render(self, source: str, filename: str) -> str:
|
|
13
|
+
"""Format the error with the offending line and a caret under the column."""
|
|
14
|
+
lines = source.splitlines()
|
|
15
|
+
text = lines[self.loc.line - 1] if 0 < self.loc.line <= len(lines) else ''
|
|
16
|
+
gutter = ' ' * len(str(self.loc.line))
|
|
17
|
+
return '\n'.join(
|
|
18
|
+
[
|
|
19
|
+
f'error: {self.message}',
|
|
20
|
+
f'{gutter}--> {filename}:{self.loc.line}:{self.loc.column}',
|
|
21
|
+
f'{gutter} |',
|
|
22
|
+
f'{self.loc.line} | {text}',
|
|
23
|
+
f'{gutter} | {" " * (self.loc.column - 1)}^',
|
|
24
|
+
]
|
|
25
|
+
)
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
class LexError(EigrelError):
|
|
29
|
+
pass
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
class ParseError(EigrelError):
|
|
33
|
+
pass
|
eigrel/compiler/lexer.py
ADDED
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
from eigrel.compiler.errors import LexError
|
|
2
|
+
from eigrel.compiler.tokens import KEYWORDS, OPERATORS, Location, Token, TokenKind
|
|
3
|
+
|
|
4
|
+
ESCAPES = {'n': '\n', 't': '\t', '\\': '\\', '"': '"', "'": "'"}
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
class Lexer:
|
|
8
|
+
def __init__(self, source: str) -> None:
|
|
9
|
+
self.source = source
|
|
10
|
+
self.pos = 0
|
|
11
|
+
self.line = 1
|
|
12
|
+
self.column = 1
|
|
13
|
+
|
|
14
|
+
def tokenize(self) -> list[Token]:
|
|
15
|
+
tokens: list[Token] = []
|
|
16
|
+
while True:
|
|
17
|
+
self._skip_trivia()
|
|
18
|
+
if self._at_end():
|
|
19
|
+
tokens.append(Token(TokenKind.EOF, '', self._loc()))
|
|
20
|
+
return tokens
|
|
21
|
+
tokens.append(self._next_token())
|
|
22
|
+
|
|
23
|
+
def _next_token(self) -> Token:
|
|
24
|
+
char = self._peek()
|
|
25
|
+
if char.isalpha() or char == '_':
|
|
26
|
+
return self._identifier()
|
|
27
|
+
if char.isdigit():
|
|
28
|
+
return self._number()
|
|
29
|
+
if char in ('"', "'"):
|
|
30
|
+
return self._string()
|
|
31
|
+
for text, kind in OPERATORS:
|
|
32
|
+
if self.source.startswith(text, self.pos):
|
|
33
|
+
loc = self._loc()
|
|
34
|
+
self._advance(len(text))
|
|
35
|
+
return Token(kind, text, loc)
|
|
36
|
+
raise LexError(f'unexpected character {char!r}', self._loc())
|
|
37
|
+
|
|
38
|
+
def _identifier(self) -> Token:
|
|
39
|
+
loc = self._loc()
|
|
40
|
+
start = self.pos
|
|
41
|
+
while not self._at_end() and (self._peek().isalnum() or self._peek() == '_'):
|
|
42
|
+
self._advance()
|
|
43
|
+
text = self.source[start : self.pos]
|
|
44
|
+
kind = TokenKind.KEYWORD if text in KEYWORDS else TokenKind.IDENT
|
|
45
|
+
return Token(kind, text, loc)
|
|
46
|
+
|
|
47
|
+
def _number(self) -> Token:
|
|
48
|
+
loc = self._loc()
|
|
49
|
+
start = self.pos
|
|
50
|
+
kind = TokenKind.INT
|
|
51
|
+
self._digits()
|
|
52
|
+
if self._peek() == '.' and self._peek(1).isdigit():
|
|
53
|
+
kind = TokenKind.FLOAT
|
|
54
|
+
self._advance()
|
|
55
|
+
self._digits()
|
|
56
|
+
if self._peek() in ('e', 'E'):
|
|
57
|
+
offset = 2 if self._peek(1) in ('+', '-') else 1
|
|
58
|
+
if self._peek(offset).isdigit():
|
|
59
|
+
kind = TokenKind.FLOAT
|
|
60
|
+
self._advance(offset)
|
|
61
|
+
self._digits()
|
|
62
|
+
if self._peek().isalpha() or self._peek() == '_':
|
|
63
|
+
raise LexError(f'invalid character {self._peek()!r} in number', self._loc())
|
|
64
|
+
return Token(kind, self.source[start : self.pos].replace('_', ''), loc)
|
|
65
|
+
|
|
66
|
+
def _digits(self) -> None:
|
|
67
|
+
while self._peek().isdigit() or (self._peek() == '_' and self._peek(1).isdigit()):
|
|
68
|
+
self._advance()
|
|
69
|
+
|
|
70
|
+
def _string(self) -> Token:
|
|
71
|
+
loc = self._loc()
|
|
72
|
+
quote = self._peek()
|
|
73
|
+
self._advance()
|
|
74
|
+
chars: list[str] = []
|
|
75
|
+
while True:
|
|
76
|
+
if self._at_end() or self._peek() == '\n':
|
|
77
|
+
raise LexError('unterminated string', loc)
|
|
78
|
+
char = self._peek()
|
|
79
|
+
if char == quote:
|
|
80
|
+
self._advance()
|
|
81
|
+
return Token(TokenKind.STRING, ''.join(chars), loc)
|
|
82
|
+
if char == '\\':
|
|
83
|
+
escape_loc = self._loc()
|
|
84
|
+
self._advance()
|
|
85
|
+
escaped = self._peek()
|
|
86
|
+
if escaped not in ESCAPES:
|
|
87
|
+
raise LexError(f'unknown escape sequence \\{escaped}', escape_loc)
|
|
88
|
+
chars.append(ESCAPES[escaped])
|
|
89
|
+
self._advance()
|
|
90
|
+
continue
|
|
91
|
+
chars.append(char)
|
|
92
|
+
self._advance()
|
|
93
|
+
|
|
94
|
+
def _skip_trivia(self) -> None:
|
|
95
|
+
while not self._at_end():
|
|
96
|
+
char = self._peek()
|
|
97
|
+
if char == '#':
|
|
98
|
+
while not self._at_end() and self._peek() != '\n':
|
|
99
|
+
self._advance()
|
|
100
|
+
elif char.isspace():
|
|
101
|
+
self._advance()
|
|
102
|
+
else:
|
|
103
|
+
return
|
|
104
|
+
|
|
105
|
+
def _peek(self, offset: int = 0) -> str:
|
|
106
|
+
index = self.pos + offset
|
|
107
|
+
return self.source[index] if index < len(self.source) else ''
|
|
108
|
+
|
|
109
|
+
def _advance(self, count: int = 1) -> None:
|
|
110
|
+
for _ in range(count):
|
|
111
|
+
if self.source[self.pos] == '\n':
|
|
112
|
+
self.line += 1
|
|
113
|
+
self.column = 1
|
|
114
|
+
else:
|
|
115
|
+
self.column += 1
|
|
116
|
+
self.pos += 1
|
|
117
|
+
|
|
118
|
+
def _at_end(self) -> bool:
|
|
119
|
+
return self.pos >= len(self.source)
|
|
120
|
+
|
|
121
|
+
def _loc(self) -> Location:
|
|
122
|
+
return Location(self.line, self.column)
|
|
123
|
+
|
|
124
|
+
|
|
125
|
+
def tokenize(source: str) -> list[Token]:
|
|
126
|
+
return Lexer(source).tokenize()
|
|
@@ -0,0 +1,261 @@
|
|
|
1
|
+
from collections.abc import Callable
|
|
2
|
+
|
|
3
|
+
from eigrel.compiler import ast
|
|
4
|
+
from eigrel.compiler.errors import ParseError
|
|
5
|
+
from eigrel.compiler.lexer import tokenize
|
|
6
|
+
from eigrel.compiler.tokens import Token, TokenKind
|
|
7
|
+
|
|
8
|
+
COMPARISON_OPS = {
|
|
9
|
+
TokenKind.EQ,
|
|
10
|
+
TokenKind.NE,
|
|
11
|
+
TokenKind.LT,
|
|
12
|
+
TokenKind.LE,
|
|
13
|
+
TokenKind.GT,
|
|
14
|
+
TokenKind.GE,
|
|
15
|
+
}
|
|
16
|
+
ADDITIVE_OPS = {TokenKind.PLUS, TokenKind.MINUS}
|
|
17
|
+
MULTIPLICATIVE_OPS = {TokenKind.STAR, TokenKind.SLASH, TokenKind.PERCENT}
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
class Parser:
|
|
21
|
+
def __init__(self, tokens: list[Token]) -> None:
|
|
22
|
+
self.tokens = tokens
|
|
23
|
+
self.pos = 0
|
|
24
|
+
self.statement_parsers: dict[str, Callable[[], ast.Statement]] = {
|
|
25
|
+
'dataset': self._dataset,
|
|
26
|
+
'transform': self._transform,
|
|
27
|
+
'features': self._features,
|
|
28
|
+
'model': self._model,
|
|
29
|
+
'train': self._train,
|
|
30
|
+
'evaluate': self._evaluate,
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
def parse_program(self) -> ast.Program:
|
|
34
|
+
loc = self._peek().loc
|
|
35
|
+
statements: list[ast.Statement] = []
|
|
36
|
+
while self._peek().kind is not TokenKind.EOF:
|
|
37
|
+
statements.append(self._statement())
|
|
38
|
+
return ast.Program(tuple(statements), loc=loc)
|
|
39
|
+
|
|
40
|
+
# Statements
|
|
41
|
+
|
|
42
|
+
def _statement(self) -> ast.Statement:
|
|
43
|
+
token = self._peek()
|
|
44
|
+
if token.kind is TokenKind.KEYWORD and token.text in self.statement_parsers:
|
|
45
|
+
return self.statement_parsers[token.text]()
|
|
46
|
+
expected = ', '.join(f"'{word}'" for word in self.statement_parsers)
|
|
47
|
+
raise ParseError(f'expected a statement ({expected}), found {token.describe()}', token.loc)
|
|
48
|
+
|
|
49
|
+
def _dataset(self) -> ast.DatasetDecl:
|
|
50
|
+
loc = self._expect_keyword('dataset').loc
|
|
51
|
+
name = self._expect(TokenKind.IDENT, 'a dataset name').text
|
|
52
|
+
self._expect_keyword('from')
|
|
53
|
+
source = self._primary()
|
|
54
|
+
if not isinstance(source, ast.Call):
|
|
55
|
+
raise ParseError(
|
|
56
|
+
'expected a source call after \'from\', like csv("file.csv")', source.loc
|
|
57
|
+
)
|
|
58
|
+
return ast.DatasetDecl(name, source, loc=loc)
|
|
59
|
+
|
|
60
|
+
def _transform(self) -> ast.TransformDecl:
|
|
61
|
+
loc = self._expect_keyword('transform').loc
|
|
62
|
+
dataset = self._expect(TokenKind.IDENT, 'a dataset name').text
|
|
63
|
+
self._expect(TokenKind.LBRACE, "'{'")
|
|
64
|
+
ops: list[ast.TransformOp] = []
|
|
65
|
+
while not self._match(TokenKind.RBRACE):
|
|
66
|
+
ops.append(self._transform_op())
|
|
67
|
+
return ast.TransformDecl(dataset, tuple(ops), loc=loc)
|
|
68
|
+
|
|
69
|
+
def _transform_op(self) -> ast.TransformOp:
|
|
70
|
+
token = self._peek()
|
|
71
|
+
if token.is_keyword('filter'):
|
|
72
|
+
self._advance()
|
|
73
|
+
return ast.FilterOp(self._expression(), loc=token.loc)
|
|
74
|
+
if token.is_keyword('select'):
|
|
75
|
+
self._advance()
|
|
76
|
+
columns = [self._column()]
|
|
77
|
+
while self._match(TokenKind.COMMA):
|
|
78
|
+
columns.append(self._column())
|
|
79
|
+
return ast.SelectOp(tuple(columns), loc=token.loc)
|
|
80
|
+
raise ParseError(
|
|
81
|
+
f"expected 'filter', 'select' or '}}', found {token.describe()}", token.loc
|
|
82
|
+
)
|
|
83
|
+
|
|
84
|
+
def _features(self) -> ast.FeaturesDecl:
|
|
85
|
+
loc = self._expect_keyword('features').loc
|
|
86
|
+
dataset = self._expect(TokenKind.IDENT, 'a dataset name').text
|
|
87
|
+
self._expect(TokenKind.LBRACE, "'{'")
|
|
88
|
+
columns: list[ast.Name] = []
|
|
89
|
+
while not self._match(TokenKind.RBRACE):
|
|
90
|
+
columns.append(self._column())
|
|
91
|
+
self._match(TokenKind.COMMA)
|
|
92
|
+
return ast.FeaturesDecl(dataset, tuple(columns), loc=loc)
|
|
93
|
+
|
|
94
|
+
def _model(self) -> ast.ModelDecl:
|
|
95
|
+
loc = self._expect_keyword('model').loc
|
|
96
|
+
name = self._expect(TokenKind.IDENT, 'a model name').text
|
|
97
|
+
self._expect(TokenKind.ASSIGN, "'='")
|
|
98
|
+
algorithm = self._expect(TokenKind.IDENT, 'an algorithm name').text
|
|
99
|
+
params = self._param_block() if self._check(TokenKind.LBRACE) else ()
|
|
100
|
+
return ast.ModelDecl(name, algorithm, params, loc=loc)
|
|
101
|
+
|
|
102
|
+
def _train(self) -> ast.TrainStmt:
|
|
103
|
+
loc = self._expect_keyword('train').loc
|
|
104
|
+
model = self._expect(TokenKind.IDENT, 'a model name').text
|
|
105
|
+
return ast.TrainStmt(model, self._param_block(), loc=loc)
|
|
106
|
+
|
|
107
|
+
def _evaluate(self) -> ast.EvaluateStmt:
|
|
108
|
+
loc = self._expect_keyword('evaluate').loc
|
|
109
|
+
model = self._expect(TokenKind.IDENT, 'a model name').text
|
|
110
|
+
return ast.EvaluateStmt(model, self._param_block(), loc=loc)
|
|
111
|
+
|
|
112
|
+
def _param_block(self) -> tuple[ast.Param, ...]:
|
|
113
|
+
self._expect(TokenKind.LBRACE, "'{'")
|
|
114
|
+
params: list[ast.Param] = []
|
|
115
|
+
seen: set[str] = set()
|
|
116
|
+
while not self._match(TokenKind.RBRACE):
|
|
117
|
+
key = self._peek()
|
|
118
|
+
# Keywords are allowed as keys so blocks can grow (e.g. `model = "llm"`).
|
|
119
|
+
if key.kind not in (TokenKind.IDENT, TokenKind.KEYWORD):
|
|
120
|
+
raise ParseError(
|
|
121
|
+
f"expected a parameter name or '}}', found {key.describe()}", key.loc
|
|
122
|
+
)
|
|
123
|
+
if key.text in seen:
|
|
124
|
+
raise ParseError(f"duplicate parameter '{key.text}'", key.loc)
|
|
125
|
+
seen.add(key.text)
|
|
126
|
+
self._advance()
|
|
127
|
+
self._expect(TokenKind.ASSIGN, f"'=' after '{key.text}'")
|
|
128
|
+
params.append(ast.Param(key.text, self._expression(), loc=key.loc))
|
|
129
|
+
self._match(TokenKind.COMMA)
|
|
130
|
+
return tuple(params)
|
|
131
|
+
|
|
132
|
+
def _column(self) -> ast.Name:
|
|
133
|
+
token = self._expect(TokenKind.IDENT, 'a column name')
|
|
134
|
+
return ast.Name(token.text, loc=token.loc)
|
|
135
|
+
|
|
136
|
+
# Expressions, lowest precedence first
|
|
137
|
+
|
|
138
|
+
def _expression(self) -> ast.Expr:
|
|
139
|
+
return self._or()
|
|
140
|
+
|
|
141
|
+
def _or(self) -> ast.Expr:
|
|
142
|
+
left = self._and()
|
|
143
|
+
while self._peek().is_keyword('or'):
|
|
144
|
+
op = self._advance()
|
|
145
|
+
left = ast.Binary('or', left, self._and(), loc=op.loc)
|
|
146
|
+
return left
|
|
147
|
+
|
|
148
|
+
def _and(self) -> ast.Expr:
|
|
149
|
+
left = self._not()
|
|
150
|
+
while self._peek().is_keyword('and'):
|
|
151
|
+
op = self._advance()
|
|
152
|
+
left = ast.Binary('and', left, self._not(), loc=op.loc)
|
|
153
|
+
return left
|
|
154
|
+
|
|
155
|
+
def _not(self) -> ast.Expr:
|
|
156
|
+
if self._peek().is_keyword('not'):
|
|
157
|
+
op = self._advance()
|
|
158
|
+
return ast.Unary('not', self._not(), loc=op.loc)
|
|
159
|
+
return self._comparison()
|
|
160
|
+
|
|
161
|
+
def _comparison(self) -> ast.Expr:
|
|
162
|
+
left = self._additive()
|
|
163
|
+
if self._peek().kind in COMPARISON_OPS:
|
|
164
|
+
op = self._advance()
|
|
165
|
+
left = ast.Binary(op.text, left, self._additive(), loc=op.loc)
|
|
166
|
+
if self._peek().kind in COMPARISON_OPS:
|
|
167
|
+
raise ParseError(
|
|
168
|
+
"comparisons cannot be chained; combine them with 'and'",
|
|
169
|
+
self._peek().loc,
|
|
170
|
+
)
|
|
171
|
+
return left
|
|
172
|
+
|
|
173
|
+
def _additive(self) -> ast.Expr:
|
|
174
|
+
left = self._multiplicative()
|
|
175
|
+
while self._peek().kind in ADDITIVE_OPS:
|
|
176
|
+
op = self._advance()
|
|
177
|
+
left = ast.Binary(op.text, left, self._multiplicative(), loc=op.loc)
|
|
178
|
+
return left
|
|
179
|
+
|
|
180
|
+
def _multiplicative(self) -> ast.Expr:
|
|
181
|
+
left = self._unary()
|
|
182
|
+
while self._peek().kind in MULTIPLICATIVE_OPS:
|
|
183
|
+
op = self._advance()
|
|
184
|
+
left = ast.Binary(op.text, left, self._unary(), loc=op.loc)
|
|
185
|
+
return left
|
|
186
|
+
|
|
187
|
+
def _unary(self) -> ast.Expr:
|
|
188
|
+
if self._check(TokenKind.MINUS):
|
|
189
|
+
op = self._advance()
|
|
190
|
+
return ast.Unary('-', self._unary(), loc=op.loc)
|
|
191
|
+
return self._primary()
|
|
192
|
+
|
|
193
|
+
def _primary(self) -> ast.Expr:
|
|
194
|
+
token = self._advance()
|
|
195
|
+
match token.kind:
|
|
196
|
+
case TokenKind.INT:
|
|
197
|
+
return ast.IntLiteral(int(token.text), loc=token.loc)
|
|
198
|
+
case TokenKind.FLOAT:
|
|
199
|
+
return ast.FloatLiteral(float(token.text), loc=token.loc)
|
|
200
|
+
case TokenKind.STRING:
|
|
201
|
+
return ast.StringLiteral(token.text, loc=token.loc)
|
|
202
|
+
case TokenKind.KEYWORD if token.text in ('true', 'false'):
|
|
203
|
+
return ast.BoolLiteral(token.text == 'true', loc=token.loc)
|
|
204
|
+
case TokenKind.LBRACKET:
|
|
205
|
+
return ast.ListExpr(self._sequence(TokenKind.RBRACKET, "']'"), loc=token.loc)
|
|
206
|
+
case TokenKind.LPAREN:
|
|
207
|
+
inner = self._expression()
|
|
208
|
+
self._expect(TokenKind.RPAREN, "')'")
|
|
209
|
+
return inner
|
|
210
|
+
case TokenKind.IDENT:
|
|
211
|
+
if self._match(TokenKind.LPAREN):
|
|
212
|
+
args = self._sequence(TokenKind.RPAREN, "')'")
|
|
213
|
+
return ast.Call(token.text, args, loc=token.loc)
|
|
214
|
+
return ast.Name(token.text, loc=token.loc)
|
|
215
|
+
raise ParseError(f'expected an expression, found {token.describe()}', token.loc)
|
|
216
|
+
|
|
217
|
+
def _sequence(self, closing: TokenKind, closing_text: str) -> tuple[ast.Expr, ...]:
|
|
218
|
+
"""Comma-separated expressions up to `closing`, allowing a trailing comma."""
|
|
219
|
+
items: list[ast.Expr] = []
|
|
220
|
+
while not self._match(closing):
|
|
221
|
+
items.append(self._expression())
|
|
222
|
+
if not self._match(TokenKind.COMMA):
|
|
223
|
+
self._expect(closing, f"',' or {closing_text}")
|
|
224
|
+
break
|
|
225
|
+
return tuple(items)
|
|
226
|
+
|
|
227
|
+
# Token helpers
|
|
228
|
+
|
|
229
|
+
def _peek(self) -> Token:
|
|
230
|
+
return self.tokens[self.pos]
|
|
231
|
+
|
|
232
|
+
def _advance(self) -> Token:
|
|
233
|
+
token = self.tokens[self.pos]
|
|
234
|
+
if token.kind is not TokenKind.EOF:
|
|
235
|
+
self.pos += 1
|
|
236
|
+
return token
|
|
237
|
+
|
|
238
|
+
def _check(self, kind: TokenKind) -> bool:
|
|
239
|
+
return self._peek().kind is kind
|
|
240
|
+
|
|
241
|
+
def _match(self, kind: TokenKind) -> bool:
|
|
242
|
+
if self._check(kind):
|
|
243
|
+
self._advance()
|
|
244
|
+
return True
|
|
245
|
+
return False
|
|
246
|
+
|
|
247
|
+
def _expect(self, kind: TokenKind, what: str) -> Token:
|
|
248
|
+
token = self._peek()
|
|
249
|
+
if token.kind is not kind:
|
|
250
|
+
raise ParseError(f'expected {what}, found {token.describe()}', token.loc)
|
|
251
|
+
return self._advance()
|
|
252
|
+
|
|
253
|
+
def _expect_keyword(self, word: str) -> Token:
|
|
254
|
+
token = self._peek()
|
|
255
|
+
if not token.is_keyword(word):
|
|
256
|
+
raise ParseError(f"expected '{word}', found {token.describe()}", token.loc)
|
|
257
|
+
return self._advance()
|
|
258
|
+
|
|
259
|
+
|
|
260
|
+
def parse(source: str) -> ast.Program:
|
|
261
|
+
return Parser(tokenize(source)).parse_program()
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
from dataclasses import dataclass
|
|
2
|
+
from enum import Enum
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
class TokenKind(Enum):
|
|
6
|
+
IDENT = 'identifier'
|
|
7
|
+
KEYWORD = 'keyword'
|
|
8
|
+
INT = 'integer'
|
|
9
|
+
FLOAT = 'float'
|
|
10
|
+
STRING = 'string'
|
|
11
|
+
|
|
12
|
+
LBRACE = '{'
|
|
13
|
+
RBRACE = '}'
|
|
14
|
+
LPAREN = '('
|
|
15
|
+
RPAREN = ')'
|
|
16
|
+
LBRACKET = '['
|
|
17
|
+
RBRACKET = ']'
|
|
18
|
+
COMMA = ','
|
|
19
|
+
ASSIGN = '='
|
|
20
|
+
|
|
21
|
+
EQ = '=='
|
|
22
|
+
NE = '!='
|
|
23
|
+
LT = '<'
|
|
24
|
+
LE = '<='
|
|
25
|
+
GT = '>'
|
|
26
|
+
GE = '>='
|
|
27
|
+
|
|
28
|
+
PLUS = '+'
|
|
29
|
+
MINUS = '-'
|
|
30
|
+
STAR = '*'
|
|
31
|
+
SLASH = '/'
|
|
32
|
+
PERCENT = '%'
|
|
33
|
+
|
|
34
|
+
EOF = 'end of file'
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
KEYWORDS = frozenset(
|
|
38
|
+
{
|
|
39
|
+
'dataset',
|
|
40
|
+
'from',
|
|
41
|
+
'transform',
|
|
42
|
+
'filter',
|
|
43
|
+
'select',
|
|
44
|
+
'features',
|
|
45
|
+
'model',
|
|
46
|
+
'train',
|
|
47
|
+
'evaluate',
|
|
48
|
+
'and',
|
|
49
|
+
'or',
|
|
50
|
+
'not',
|
|
51
|
+
'true',
|
|
52
|
+
'false',
|
|
53
|
+
}
|
|
54
|
+
)
|
|
55
|
+
|
|
56
|
+
# Longest match first, so '<=' wins over '<'.
|
|
57
|
+
OPERATORS: tuple[tuple[str, TokenKind], ...] = (
|
|
58
|
+
('==', TokenKind.EQ),
|
|
59
|
+
('!=', TokenKind.NE),
|
|
60
|
+
('<=', TokenKind.LE),
|
|
61
|
+
('>=', TokenKind.GE),
|
|
62
|
+
('<', TokenKind.LT),
|
|
63
|
+
('>', TokenKind.GT),
|
|
64
|
+
('=', TokenKind.ASSIGN),
|
|
65
|
+
('{', TokenKind.LBRACE),
|
|
66
|
+
('}', TokenKind.RBRACE),
|
|
67
|
+
('(', TokenKind.LPAREN),
|
|
68
|
+
(')', TokenKind.RPAREN),
|
|
69
|
+
('[', TokenKind.LBRACKET),
|
|
70
|
+
(']', TokenKind.RBRACKET),
|
|
71
|
+
(',', TokenKind.COMMA),
|
|
72
|
+
('+', TokenKind.PLUS),
|
|
73
|
+
('-', TokenKind.MINUS),
|
|
74
|
+
('*', TokenKind.STAR),
|
|
75
|
+
('/', TokenKind.SLASH),
|
|
76
|
+
('%', TokenKind.PERCENT),
|
|
77
|
+
)
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
@dataclass(frozen=True)
|
|
81
|
+
class Location:
|
|
82
|
+
line: int
|
|
83
|
+
column: int
|
|
84
|
+
|
|
85
|
+
|
|
86
|
+
@dataclass(frozen=True)
|
|
87
|
+
class Token:
|
|
88
|
+
kind: TokenKind
|
|
89
|
+
text: str
|
|
90
|
+
loc: Location
|
|
91
|
+
|
|
92
|
+
def is_keyword(self, word: str) -> bool:
|
|
93
|
+
return self.kind is TokenKind.KEYWORD and self.text == word
|
|
94
|
+
|
|
95
|
+
def describe(self) -> str:
|
|
96
|
+
if self.kind is TokenKind.EOF:
|
|
97
|
+
return 'end of file'
|
|
98
|
+
if self.kind in (TokenKind.IDENT, TokenKind.KEYWORD):
|
|
99
|
+
return f"{self.kind.value} '{self.text}'"
|
|
100
|
+
if self.kind in (TokenKind.INT, TokenKind.FLOAT, TokenKind.STRING):
|
|
101
|
+
return f'{self.kind.value} {self.text}'
|
|
102
|
+
return f"'{self.text}'"
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: eigrel
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: A programming language for Data, Machine Learning and AI.
|
|
5
|
+
Author: Nathan Souza
|
|
6
|
+
License-Expression: Apache-2.0
|
|
7
|
+
Requires-Python: >=3.13
|
|
8
|
+
Description-Content-Type: text/markdown
|
|
9
|
+
License-File: LICENSE
|
|
10
|
+
Dynamic: license-file
|
|
11
|
+
|
|
12
|
+
# Eigrel
|
|
13
|
+
|
|
14
|
+
**A programming language for Data, Machine Learning and AI.**
|
|
15
|
+
|
|
16
|
+
> Write what you want. Let the compiler decide how to run it.
|
|
17
|
+
|
|
18
|
+
🇧🇷 [Leia em português](README.pt-br.md)
|
|
19
|
+
|
|
20
|
+
Eigrel is a declarative language for data engineering, machine learning and GenAI. You describe
|
|
21
|
+
datasets, transformations, features and models in one language; the compiler decides whether each
|
|
22
|
+
step becomes Python, SQL, Spark or something else.
|
|
23
|
+
|
|
24
|
+
```eigrel
|
|
25
|
+
dataset customers from csv("data/customers.csv")
|
|
26
|
+
|
|
27
|
+
transform customers {
|
|
28
|
+
filter age >= 18
|
|
29
|
+
select age, income, purchases, churned
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
features customers {
|
|
33
|
+
age
|
|
34
|
+
income
|
|
35
|
+
purchases
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
model churn = random_forest {
|
|
39
|
+
trees = 100
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
train churn {
|
|
43
|
+
target = churned
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
evaluate churn {
|
|
47
|
+
metrics = [accuracy, precision, recall, f1]
|
|
48
|
+
}
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
## Status
|
|
52
|
+
|
|
53
|
+
Eigrel is at **v0.1 — Language**: the lexer, parser and syntax tree are done, and the CLI can
|
|
54
|
+
check files and print their tokens or AST. Nothing executes yet; the compiler, IR and Python backend
|
|
55
|
+
come in v0.2. See the [roadmap](docs/ROADMAP.md).
|
|
56
|
+
|
|
57
|
+
## Getting started
|
|
58
|
+
|
|
59
|
+
Install from PyPI (Python 3.13+):
|
|
60
|
+
|
|
61
|
+
```bash
|
|
62
|
+
pip install eigrel
|
|
63
|
+
eigrel init churn
|
|
64
|
+
eigrel check churn/main.eig
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
### From source
|
|
68
|
+
|
|
69
|
+
Requires [uv](https://docs.astral.sh/uv/).
|
|
70
|
+
|
|
71
|
+
```bash
|
|
72
|
+
make install # creates .venv and installs eigrel in editable mode
|
|
73
|
+
.venv/bin/eigrel init churn # creates churn/main.eig
|
|
74
|
+
.venv/bin/eigrel check churn/main.eig
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
### CLI
|
|
78
|
+
|
|
79
|
+
| Command | What it does |
|
|
80
|
+
|---|---|
|
|
81
|
+
| `eigrel check FILE...` | Parses each file and reports syntax errors with line and column |
|
|
82
|
+
| `eigrel ast FILE` | Prints the syntax tree as JSON |
|
|
83
|
+
| `eigrel tokens FILE` | Prints the token stream |
|
|
84
|
+
| `eigrel init NAME` | Creates a project with a starter `main.eig` |
|
|
85
|
+
|
|
86
|
+
Errors point at the exact spot:
|
|
87
|
+
|
|
88
|
+
```text
|
|
89
|
+
error: comparisons cannot be chained; combine them with 'and'
|
|
90
|
+
--> pipeline.eig:4:21
|
|
91
|
+
|
|
|
92
|
+
4 | filter age > 18 < 30
|
|
93
|
+
| ^
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
### Docker
|
|
97
|
+
|
|
98
|
+
```bash
|
|
99
|
+
make docker-build
|
|
100
|
+
make docker-run # runs `eigrel check` on examples/ml.eig inside the container
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
## Language
|
|
104
|
+
|
|
105
|
+
The full syntax is in [docs/LANGUAGE.md](docs/LANGUAGE.md). Examples live in [`examples/`](examples).
|
|
106
|
+
|
|
107
|
+
## Project layout
|
|
108
|
+
|
|
109
|
+
```text
|
|
110
|
+
src/eigrel/
|
|
111
|
+
├── compiler/
|
|
112
|
+
│ ├── tokens.py token kinds, keywords, source locations
|
|
113
|
+
│ ├── lexer.py source text → tokens
|
|
114
|
+
│ ├── ast.py syntax tree nodes and JSON export
|
|
115
|
+
│ ├── parser.py tokens → syntax tree (recursive descent)
|
|
116
|
+
│ └── errors.py diagnostics with source excerpts
|
|
117
|
+
└── cli.py the `eigrel` command
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
## Development
|
|
121
|
+
|
|
122
|
+
```bash
|
|
123
|
+
make test # pytest
|
|
124
|
+
make coverage # pytest with the 90% coverage gate
|
|
125
|
+
make lint # ruff check + format check
|
|
126
|
+
make typecheck # mypy
|
|
127
|
+
make check-examples # eigrel check examples/*.eig
|
|
128
|
+
```
|
|
129
|
+
|
|
130
|
+
Commits follow [Conventional Commits](https://www.conventionalcommits.org/); releases and the
|
|
131
|
+
changelog are generated by semantic-release.
|
|
132
|
+
|
|
133
|
+
## License
|
|
134
|
+
|
|
135
|
+
Licensed under the [Apache License 2.0](LICENSE).
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
eigrel/__init__.py,sha256=Z2X6JRZVH6UaUQWgMs5g-9t_Lk8HSn1TyJOB-NiL1F4,95
|
|
2
|
+
eigrel/__main__.py,sha256=jysB1t2TW3BREL4czKH_dnI5S4dCTAuddmrm2HxI7_g,58
|
|
3
|
+
eigrel/cli.py,sha256=_WLFsDLKhILty3aR4b9n592ukqqZsdO9oiZ-_Pt4UM0,3891
|
|
4
|
+
eigrel/compiler/__init__.py,sha256=v8mXG5QeO5fyG7_vEew8QvP054dZRcDGYul5zOWQOoc,291
|
|
5
|
+
eigrel/compiler/ast.py,sha256=XdABmJBnYQP6KaniH1ZmwCGAlZr_M7k-g154EVQbNrk,2604
|
|
6
|
+
eigrel/compiler/errors.py,sha256=3c-N7u6OPFRxcSDaoW36CeC8fNMYoPXJ975rQ8rIB2I,1008
|
|
7
|
+
eigrel/compiler/lexer.py,sha256=sjMsRLBbswG27ouHIXmRcR3tZWMlqFF_jY9lGkGDqsA,4345
|
|
8
|
+
eigrel/compiler/parser.py,sha256=d1uQXk8FfHMlEDSId3GRP2QTVIL9a3uT3DbYSMh5i9o,10155
|
|
9
|
+
eigrel/compiler/tokens.py,sha256=2Xv_Jav8_wYDy7hkxjKHVthbdtMmw9TOtuudI8UHQXc,2086
|
|
10
|
+
eigrel-0.1.0.dist-info/licenses/LICENSE,sha256=yVuuHRzgI17MzTVgt3LsHvuX80innw--CmNPDCzO_iw,11358
|
|
11
|
+
eigrel-0.1.0.dist-info/METADATA,sha256=HWsQhk9d5_nZYmdADoKVINKZE5w4HHxh94IStyDmK_o,3344
|
|
12
|
+
eigrel-0.1.0.dist-info/WHEEL,sha256=YVMoNqKzERt-wjUZwJ33xBGAwnFl-4cqbYkTtWa4itE,91
|
|
13
|
+
eigrel-0.1.0.dist-info/entry_points.txt,sha256=RCEqQ52LlxfB1TixjmW2MGD_W5sXdWDDZVJvvXpsc2Y,43
|
|
14
|
+
eigrel-0.1.0.dist-info/top_level.txt,sha256=zObn_6cQzPpZ14h1wjG50zCAct_mxKJ6kEoUzYY4BIc,7
|
|
15
|
+
eigrel-0.1.0.dist-info/RECORD,,
|
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright [yyyy] [name of copyright owner]
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
|
202
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
eigrel
|