lispython 0.3.0__tar.gz → 0.3.1__tar.gz

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 (41) hide show
  1. {lispython-0.3.0 → lispython-0.3.1}/PKG-INFO +6 -3
  2. {lispython-0.3.0 → lispython-0.3.1}/README.md +5 -2
  3. {lispython-0.3.0 → lispython-0.3.1}/pyproject.toml +1 -1
  4. {lispython-0.3.0 → lispython-0.3.1}/src/lispy/core/meta_functions.py +15 -9
  5. {lispython-0.3.0 → lispython-0.3.1}/src/lispy/core/parser.py +6 -2
  6. {lispython-0.3.0 → lispython-0.3.1}/src/lispy/core_meta_functions.lpy +8 -4
  7. {lispython-0.3.0 → lispython-0.3.1}/src/lispy/tools.lpy +11 -8
  8. {lispython-0.3.0 → lispython-0.3.1}/uv.lock +1 -1
  9. {lispython-0.3.0 → lispython-0.3.1}/.claude/settings.local.json +0 -0
  10. {lispython-0.3.0 → lispython-0.3.1}/.gitignore +0 -0
  11. {lispython-0.3.0 → lispython-0.3.1}/.pre-commit-config.yaml +0 -0
  12. {lispython-0.3.0 → lispython-0.3.1}/LICENSE.md +0 -0
  13. {lispython-0.3.0 → lispython-0.3.1}/docs/index.md +0 -0
  14. {lispython-0.3.0 → lispython-0.3.1}/docs/macros.md +0 -0
  15. {lispython-0.3.0 → lispython-0.3.1}/docs/syntax/expressions.md +0 -0
  16. {lispython-0.3.0 → lispython-0.3.1}/docs/syntax/overview.md +0 -0
  17. {lispython-0.3.0 → lispython-0.3.1}/docs/syntax/statements.md +0 -0
  18. {lispython-0.3.0 → lispython-0.3.1}/docs/usage/cli.md +0 -0
  19. {lispython-0.3.0 → lispython-0.3.1}/docs/usage/getting-started.md +0 -0
  20. {lispython-0.3.0 → lispython-0.3.1}/docs/version_macro.py +0 -0
  21. {lispython-0.3.0 → lispython-0.3.1}/docs/why-lispy.md +0 -0
  22. {lispython-0.3.0 → lispython-0.3.1}/mkdocs.yml +0 -0
  23. {lispython-0.3.0 → lispython-0.3.1}/src/lispy/__init__.py +0 -0
  24. {lispython-0.3.0 → lispython-0.3.1}/src/lispy/core/compiler/__init__.py +0 -0
  25. {lispython-0.3.0 → lispython-0.3.1}/src/lispy/core/compiler/expr.py +0 -0
  26. {lispython-0.3.0 → lispython-0.3.1}/src/lispy/core/compiler/literal.py +0 -0
  27. {lispython-0.3.0 → lispython-0.3.1}/src/lispy/core/compiler/stmt.py +0 -0
  28. {lispython-0.3.0 → lispython-0.3.1}/src/lispy/core/compiler/utils.py +0 -0
  29. {lispython-0.3.0 → lispython-0.3.1}/src/lispy/core/importer.py +0 -0
  30. {lispython-0.3.0 → lispython-0.3.1}/src/lispy/core/macro.py +0 -0
  31. {lispython-0.3.0 → lispython-0.3.1}/src/lispy/core/nodes.py +0 -0
  32. {lispython-0.3.0 → lispython-0.3.1}/src/lispy/core/utils.py +0 -0
  33. {lispython-0.3.0 → lispython-0.3.1}/src/lispy/macros/__init__.py +0 -0
  34. {lispython-0.3.0 → lispython-0.3.1}/src/lispy/macros/init.lpy +0 -0
  35. {lispython-0.3.0 → lispython-0.3.1}/src/lispy/macros/sugar.lpy +0 -0
  36. {lispython-0.3.0 → lispython-0.3.1}/tests/__init__.py +0 -0
  37. {lispython-0.3.0 → lispython-0.3.1}/tests/test_expr.py +0 -0
  38. {lispython-0.3.0 → lispython-0.3.1}/tests/test_literal.py +0 -0
  39. {lispython-0.3.0 → lispython-0.3.1}/tests/test_parser.py +0 -0
  40. {lispython-0.3.0 → lispython-0.3.1}/tests/test_stmt.py +0 -0
  41. {lispython-0.3.0 → lispython-0.3.1}/tests/utils.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: lispython
3
- Version: 0.3.0
3
+ Version: 0.3.1
4
4
  Summary: Lisp-like Syntax for Python with Lisp-like Macros
5
5
  Project-URL: Homepage, https://jetack.github.io/lispython
6
6
  Project-URL: Repository, https://github.com/jetack/lispython
@@ -67,9 +67,12 @@ lpy -m unittest
67
67
  # Todo
68
68
  ## Environment
69
69
  - [ ] Test on more python versions
70
- - [ ] Some IDE plugins like hy-mode and jedhy for better editing experience.
70
+ - [ ] REPL should track history and arrow key navigation
71
+ - [ ] REPL multi-line input support
72
+ - [ ] Better compileation error messages
71
73
  ## Macro System
72
74
  - [ ] `as->` macro for syntactic sugar
73
75
  - [ ] `gensym` for avoiding name collision
74
76
  ## Python AST
75
- - [ ] `type_comment` never considered. Later, it should be covered
77
+ - [ ] `type_comment` never considered. Later, it should be covered
78
+ - [ ] Any missing AST nodes in the version 3.12+
@@ -46,9 +46,12 @@ lpy -m unittest
46
46
  # Todo
47
47
  ## Environment
48
48
  - [ ] Test on more python versions
49
- - [ ] Some IDE plugins like hy-mode and jedhy for better editing experience.
49
+ - [ ] REPL should track history and arrow key navigation
50
+ - [ ] REPL multi-line input support
51
+ - [ ] Better compileation error messages
50
52
  ## Macro System
51
53
  - [ ] `as->` macro for syntactic sugar
52
54
  - [ ] `gensym` for avoiding name collision
53
55
  ## Python AST
54
- - [ ] `type_comment` never considered. Later, it should be covered
56
+ - [ ] `type_comment` never considered. Later, it should be covered
57
+ - [ ] Any missing AST nodes in the version 3.12+
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "lispython"
3
- version = "0.3.0"
3
+ version = "0.3.1"
4
4
  description = "Lisp-like Syntax for Python with Lisp-like Macros"
5
5
  authors = [{ name = "Jetack", email = "jetack23@gmail.com" }]
6
6
  license = { text = "MIT" }
@@ -34,6 +34,18 @@ def require_transform(sexp):
34
34
  [macro_names] = optional
35
35
  else:
36
36
  macro_names = None
37
+ module_name_str = str(module_name).replace("-", "_")
38
+ is_relative = module_name_str.startswith(".")
39
+ import_call = (
40
+ Paren(
41
+ Symbol("importlib.import-module"),
42
+ module_name_str,
43
+ Keyword(Symbol("package")),
44
+ Symbol("__package__"),
45
+ )
46
+ if is_relative
47
+ else Paren(Symbol("importlib.import-module"), module_name_str)
48
+ )
37
49
  return Paren(
38
50
  Symbol("do"),
39
51
  Paren(Symbol("import"), Symbol("importlib")),
@@ -41,13 +53,7 @@ def require_transform(sexp):
41
53
  Symbol("="),
42
54
  Symbol("___imported-macros"),
43
55
  Paren(
44
- Symbol("getattr"),
45
- Paren(
46
- Symbol("importlib.import-module"),
47
- str(module_name).replace("-", "_"),
48
- ),
49
- String('"__macro_namespace"'),
50
- Brace(),
56
+ Symbol("getattr"), import_call, String('"__macro_namespace"'), Brace()
51
57
  ),
52
58
  ),
53
59
  Paren(
@@ -111,11 +117,11 @@ def require_transform(sexp):
111
117
  if __name__ == "__main__":
112
118
  import os.path as osp
113
119
 
114
- from lispy.tools import l2py_f
120
+ from lispy.tools import l2py_s
115
121
 
116
122
  path = osp.abspath(__file__)
117
123
  with open(path, "r") as f:
118
124
  org = f.read()
119
- translated = l2py_f(org)
125
+ translated = l2py_s(org)
120
126
  with open(osp.join(osp.dirname(path), "core", "meta_functions.py"), "w") as f:
121
127
  f.write(translated)
@@ -7,8 +7,12 @@ from lispy.core.utils import augassignop_dict
7
7
 
8
8
 
9
9
  def tokenize(src):
10
- # Remove commas except those following { or ( with optional whitespace
11
- src = re.sub(r"([{(]\s*),|,", lambda m: m.group(0) if m.group(1) else " ", src)
10
+ # Remove commas except those following { or ( with optional whitespace, but preserve commas in strings
11
+ src = re.sub(
12
+ r'(\w*"""(?:[^\\"]|\\.)*"""|\w*\'\'\'(?:[^\\\']|\\.)*\'\'\'|\w*"(?:[^\\"]|\\.)*"|[{(]\s*,)|,',
13
+ lambda m: m.group(1) if m.group(1) else " ",
14
+ src,
15
+ )
12
16
  lines = src.split("\n")
13
17
  tokens = deque([])
14
18
  int_simple = r"\d+[\dA-Za-z]*(?:_[\dA-Za-z]+)*"
@@ -21,11 +21,15 @@
21
21
  (if optional
22
22
  (= [macro-names] optional)
23
23
  (= macro-names None))
24
+ (= module-name-str (.replace (str module-name) "-" "_"))
25
+ (= is-relative (.startswith module-name-str "."))
26
+ (= import-call (ife is-relative
27
+ `(importlib.import-module ~module-name-str :package __package__)
28
+ `(importlib.import-module ~module-name-str)))
24
29
  (return
25
30
  `(do (import importlib)
26
31
  (= ___imported-macros
27
- (getattr (importlib.import-module
28
- ~(.replace (str module-name) "-" "_"))
32
+ (getattr ~import-call
29
33
  "__macro_namespace"
30
34
  {}))
31
35
  ~(conde (not macro-names)
@@ -47,14 +51,14 @@
47
51
 
48
52
  (when (== __name__ "__main__")
49
53
  (import os.path as osp)
50
- (from lispy.tools [l2py-f])
54
+ (from lispy.tools [l2py-s])
51
55
 
52
56
  (= path (osp.abspath __file__))
53
57
 
54
58
  (with [(open path "r") as f]
55
59
  (= org (f.read)))
56
60
 
57
- (= translated (l2py-f org))
61
+ (= translated (l2py-s org))
58
62
 
59
63
  (with [(open (-> path
60
64
  (osp.dirname)
@@ -20,14 +20,16 @@
20
20
  (from lispy.core.parser [parse])
21
21
  (from lispy.core.macro [macroexpand-then-compile])
22
22
 
23
- (def detect-package-name []
24
- "Detect package name from current directory by checking for __init__.py"
25
- (= cwd (os.getcwd))
26
- (if (not (osp.exists (osp.join cwd "__init__.py")))
23
+ (def detect-package-name [:path None]
24
+ "Detect package name from directory by checking for __init__.py"
25
+ (= dir-path (ife (is path None)
26
+ (os.getcwd)
27
+ (osp.dirname (osp.abspath path))))
28
+ (if (not (osp.exists (osp.join dir-path "__init__.py")))
27
29
  (return ""))
28
30
  ;; Walk up to find package root
29
31
  (= parts [])
30
- (= current cwd)
32
+ (= current dir-path)
31
33
  (while (osp.exists (osp.join current "__init__.py"))
32
34
  (parts.insert 0 (osp.basename current))
33
35
  (= parent (osp.dirname current))
@@ -88,11 +90,11 @@
88
90
  :dest "include_meta"
89
91
  :action "store_true")
90
92
 
91
- (def l2py-s [src :include-meta False :fresh-scope False]
93
+ (def l2py-s [src :include-meta False :fresh-scope False :package ""]
92
94
  "Translate lispy source string to Python source string"
93
95
  (if fresh-scope
94
96
  (= scope {"__builtins__" __builtins__
95
- "__package__" ""
97
+ "__package__" package
96
98
  "__macro_namespace" {}})
97
99
  (= scope SCOPE))
98
100
  (= pysrc (src-to-python src :include-meta include_meta :scope scope))
@@ -118,7 +120,8 @@
118
120
 
119
121
  (with [(open file-path "rb") as f]
120
122
  (= src (.decode (f.read) "utf-8")))
121
- (return (+ (l2py-s src :include-meta include_meta :fresh-scope True) "\n")))
123
+ (= pkg (detect-package-name :path file-path))
124
+ (return (+ (l2py-s src :include-meta include_meta :fresh-scope True :package pkg) "\n")))
122
125
 
123
126
  (def l2py []
124
127
  "CLI entry point: parse args and translate file"
@@ -238,7 +238,7 @@ wheels = [
238
238
 
239
239
  [[package]]
240
240
  name = "lispython"
241
- version = "0.2.1"
241
+ version = "0.3.0"
242
242
  source = { editable = "." }
243
243
 
244
244
  [package.optional-dependencies]
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes