fromscratch-pebble 0.3.0__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 (138) hide show
  1. fromscratch_pebble-0.3.0/.github/workflows/ci.yml +14 -0
  2. fromscratch_pebble-0.3.0/.github/workflows/docs.yml +16 -0
  3. fromscratch_pebble-0.3.0/.github/workflows/release.yml +58 -0
  4. fromscratch_pebble-0.3.0/.gitignore +42 -0
  5. fromscratch_pebble-0.3.0/.pre-commit-config.yaml +56 -0
  6. fromscratch_pebble-0.3.0/CLAUDE.md +56 -0
  7. fromscratch_pebble-0.3.0/CONTRIBUTING.md +196 -0
  8. fromscratch_pebble-0.3.0/LICENSE +21 -0
  9. fromscratch_pebble-0.3.0/PKG-INFO +156 -0
  10. fromscratch_pebble-0.3.0/README.md +121 -0
  11. fromscratch_pebble-0.3.0/conftest.py +21 -0
  12. fromscratch_pebble-0.3.0/docs/concepts/analyzer.md +253 -0
  13. fromscratch_pebble-0.3.0/docs/concepts/arrays.md +374 -0
  14. fromscratch_pebble-0.3.0/docs/concepts/ast.md +174 -0
  15. fromscratch_pebble-0.3.0/docs/concepts/async.md +296 -0
  16. fromscratch_pebble-0.3.0/docs/concepts/classes.md +397 -0
  17. fromscratch_pebble-0.3.0/docs/concepts/closures-as-classes.md +358 -0
  18. fromscratch_pebble-0.3.0/docs/concepts/closures.md +159 -0
  19. fromscratch_pebble-0.3.0/docs/concepts/compiler.md +389 -0
  20. fromscratch_pebble-0.3.0/docs/concepts/debugger.md +179 -0
  21. fromscratch_pebble-0.3.0/docs/concepts/dicts.md +167 -0
  22. fromscratch_pebble-0.3.0/docs/concepts/enums.md +219 -0
  23. fromscratch_pebble-0.3.0/docs/concepts/error-handling.md +265 -0
  24. fromscratch_pebble-0.3.0/docs/concepts/errors.md +88 -0
  25. fromscratch_pebble-0.3.0/docs/concepts/formatter.md +145 -0
  26. fromscratch_pebble-0.3.0/docs/concepts/functions.md +267 -0
  27. fromscratch_pebble-0.3.0/docs/concepts/higher-order.md +213 -0
  28. fromscratch_pebble-0.3.0/docs/concepts/inheritance.md +367 -0
  29. fromscratch_pebble-0.3.0/docs/concepts/iterators.md +234 -0
  30. fromscratch_pebble-0.3.0/docs/concepts/lexer.md +134 -0
  31. fromscratch_pebble-0.3.0/docs/concepts/linter.md +135 -0
  32. fromscratch_pebble-0.3.0/docs/concepts/list-comprehensions.md +178 -0
  33. fromscratch_pebble-0.3.0/docs/concepts/match.md +290 -0
  34. fromscratch_pebble-0.3.0/docs/concepts/modules.md +278 -0
  35. fromscratch_pebble-0.3.0/docs/concepts/operator-overloading.md +355 -0
  36. fromscratch_pebble-0.3.0/docs/concepts/operators.md +375 -0
  37. fromscratch_pebble-0.3.0/docs/concepts/optimizer.md +192 -0
  38. fromscratch_pebble-0.3.0/docs/concepts/parser.md +160 -0
  39. fromscratch_pebble-0.3.0/docs/concepts/repl.md +123 -0
  40. fromscratch_pebble-0.3.0/docs/concepts/stack-traces.md +167 -0
  41. fromscratch_pebble-0.3.0/docs/concepts/statements.md +422 -0
  42. fromscratch_pebble-0.3.0/docs/concepts/stdlib.md +614 -0
  43. fromscratch_pebble-0.3.0/docs/concepts/string-interpolation.md +89 -0
  44. fromscratch_pebble-0.3.0/docs/concepts/strings.md +291 -0
  45. fromscratch_pebble-0.3.0/docs/concepts/structs.md +284 -0
  46. fromscratch_pebble-0.3.0/docs/concepts/tokens.md +182 -0
  47. fromscratch_pebble-0.3.0/docs/concepts/tuple-unpacking.md +166 -0
  48. fromscratch_pebble-0.3.0/docs/concepts/type-annotations.md +403 -0
  49. fromscratch_pebble-0.3.0/docs/concepts/type-checker.md +222 -0
  50. fromscratch_pebble-0.3.0/docs/concepts/types.md +255 -0
  51. fromscratch_pebble-0.3.0/docs/concepts/using-pebble-from-python.md +217 -0
  52. fromscratch_pebble-0.3.0/docs/concepts/vm.md +222 -0
  53. fromscratch_pebble-0.3.0/docs/index.md +93 -0
  54. fromscratch_pebble-0.3.0/docs/property-testing.md +336 -0
  55. fromscratch_pebble-0.3.0/mkdocs.yml +121 -0
  56. fromscratch_pebble-0.3.0/overrides/main.html +7 -0
  57. fromscratch_pebble-0.3.0/pyproject.toml +184 -0
  58. fromscratch_pebble-0.3.0/src/pebble/__init__.py +22 -0
  59. fromscratch_pebble-0.3.0/src/pebble/__main__.py +5 -0
  60. fromscratch_pebble-0.3.0/src/pebble/_pipeline.py +137 -0
  61. fromscratch_pebble-0.3.0/src/pebble/_version.py +24 -0
  62. fromscratch_pebble-0.3.0/src/pebble/analyzer.py +1136 -0
  63. fromscratch_pebble-0.3.0/src/pebble/api.py +122 -0
  64. fromscratch_pebble-0.3.0/src/pebble/ast_nodes.py +664 -0
  65. fromscratch_pebble-0.3.0/src/pebble/builtins.py +764 -0
  66. fromscratch_pebble-0.3.0/src/pebble/bytecode.py +211 -0
  67. fromscratch_pebble-0.3.0/src/pebble/cli.py +154 -0
  68. fromscratch_pebble-0.3.0/src/pebble/compiler.py +1305 -0
  69. fromscratch_pebble-0.3.0/src/pebble/debugger.py +372 -0
  70. fromscratch_pebble-0.3.0/src/pebble/errors.py +194 -0
  71. fromscratch_pebble-0.3.0/src/pebble/formatter.py +965 -0
  72. fromscratch_pebble-0.3.0/src/pebble/lexer.py +541 -0
  73. fromscratch_pebble-0.3.0/src/pebble/linter.py +475 -0
  74. fromscratch_pebble-0.3.0/src/pebble/optimizer.py +532 -0
  75. fromscratch_pebble-0.3.0/src/pebble/parser.py +1384 -0
  76. fromscratch_pebble-0.3.0/src/pebble/py.typed +0 -0
  77. fromscratch_pebble-0.3.0/src/pebble/repl.py +206 -0
  78. fromscratch_pebble-0.3.0/src/pebble/resolver.py +393 -0
  79. fromscratch_pebble-0.3.0/src/pebble/stdlib.py +199 -0
  80. fromscratch_pebble-0.3.0/src/pebble/tokens.py +169 -0
  81. fromscratch_pebble-0.3.0/src/pebble/type_checker.py +537 -0
  82. fromscratch_pebble-0.3.0/src/pebble/vm.py +1834 -0
  83. fromscratch_pebble-0.3.0/tests/__init__.py +1 -0
  84. fromscratch_pebble-0.3.0/tests/conftest.py +207 -0
  85. fromscratch_pebble-0.3.0/tests/test_analyzer.py +382 -0
  86. fromscratch_pebble-0.3.0/tests/test_api.py +138 -0
  87. fromscratch_pebble-0.3.0/tests/test_arrays.py +692 -0
  88. fromscratch_pebble-0.3.0/tests/test_ast_nodes.py +362 -0
  89. fromscratch_pebble-0.3.0/tests/test_async.py +476 -0
  90. fromscratch_pebble-0.3.0/tests/test_bytecode.py +158 -0
  91. fromscratch_pebble-0.3.0/tests/test_chained_comparisons.py +224 -0
  92. fromscratch_pebble-0.3.0/tests/test_classes.py +786 -0
  93. fromscratch_pebble-0.3.0/tests/test_cli_fmt.py +42 -0
  94. fromscratch_pebble-0.3.0/tests/test_closures.py +458 -0
  95. fromscratch_pebble-0.3.0/tests/test_closures_as_classes.py +472 -0
  96. fromscratch_pebble-0.3.0/tests/test_compiler.py +704 -0
  97. fromscratch_pebble-0.3.0/tests/test_constants.py +146 -0
  98. fromscratch_pebble-0.3.0/tests/test_debugger.py +474 -0
  99. fromscratch_pebble-0.3.0/tests/test_default_params.py +323 -0
  100. fromscratch_pebble-0.3.0/tests/test_dicts.py +295 -0
  101. fromscratch_pebble-0.3.0/tests/test_docs_api_examples.py +19 -0
  102. fromscratch_pebble-0.3.0/tests/test_enums.py +428 -0
  103. fromscratch_pebble-0.3.0/tests/test_error_handling.py +605 -0
  104. fromscratch_pebble-0.3.0/tests/test_error_reporting.py +172 -0
  105. fromscratch_pebble-0.3.0/tests/test_errors.py +246 -0
  106. fromscratch_pebble-0.3.0/tests/test_floats.py +262 -0
  107. fromscratch_pebble-0.3.0/tests/test_format_roundtrip.py +268 -0
  108. fromscratch_pebble-0.3.0/tests/test_formatter.py +811 -0
  109. fromscratch_pebble-0.3.0/tests/test_generics.py +553 -0
  110. fromscratch_pebble-0.3.0/tests/test_higher_order.py +290 -0
  111. fromscratch_pebble-0.3.0/tests/test_inheritance.py +707 -0
  112. fromscratch_pebble-0.3.0/tests/test_iterators.py +457 -0
  113. fromscratch_pebble-0.3.0/tests/test_lexer.py +645 -0
  114. fromscratch_pebble-0.3.0/tests/test_linter.py +309 -0
  115. fromscratch_pebble-0.3.0/tests/test_list_comprehensions.py +307 -0
  116. fromscratch_pebble-0.3.0/tests/test_match.py +352 -0
  117. fromscratch_pebble-0.3.0/tests/test_modules.py +380 -0
  118. fromscratch_pebble-0.3.0/tests/test_null.py +246 -0
  119. fromscratch_pebble-0.3.0/tests/test_number_size_limit.py +208 -0
  120. fromscratch_pebble-0.3.0/tests/test_operator_overloading.py +611 -0
  121. fromscratch_pebble-0.3.0/tests/test_operators.py +337 -0
  122. fromscratch_pebble-0.3.0/tests/test_optimizer.py +985 -0
  123. fromscratch_pebble-0.3.0/tests/test_parser_expressions.py +627 -0
  124. fromscratch_pebble-0.3.0/tests/test_parser_statements.py +789 -0
  125. fromscratch_pebble-0.3.0/tests/test_properties.py +547 -0
  126. fromscratch_pebble-0.3.0/tests/test_repl.py +241 -0
  127. fromscratch_pebble-0.3.0/tests/test_smoke.py +116 -0
  128. fromscratch_pebble-0.3.0/tests/test_stack_traces.py +383 -0
  129. fromscratch_pebble-0.3.0/tests/test_stdlib.py +930 -0
  130. fromscratch_pebble-0.3.0/tests/test_string_interpolation.py +244 -0
  131. fromscratch_pebble-0.3.0/tests/test_strings.py +454 -0
  132. fromscratch_pebble-0.3.0/tests/test_structs.py +485 -0
  133. fromscratch_pebble-0.3.0/tests/test_tokens.py +404 -0
  134. fromscratch_pebble-0.3.0/tests/test_tuple_unpacking.py +411 -0
  135. fromscratch_pebble-0.3.0/tests/test_type_annotations.py +782 -0
  136. fromscratch_pebble-0.3.0/tests/test_type_checker.py +495 -0
  137. fromscratch_pebble-0.3.0/tests/test_vm.py +764 -0
  138. fromscratch_pebble-0.3.0/uv.lock +1124 -0
@@ -0,0 +1,14 @@
1
+ name: CI
2
+
3
+ on:
4
+ push:
5
+ branches: [main]
6
+ pull_request:
7
+ branches: [main]
8
+
9
+ permissions:
10
+ contents: read
11
+
12
+ jobs:
13
+ ci:
14
+ uses: robcox2910/robcox2910.github.io/.github/workflows/python-ci.yml@v1
@@ -0,0 +1,16 @@
1
+ name: Deploy Docs
2
+
3
+ on:
4
+ push:
5
+ branches: [main]
6
+ workflow_dispatch: {}
7
+
8
+ jobs:
9
+ docs:
10
+ uses: robcox2910/robcox2910.github.io/.github/workflows/docs.yml@v1
11
+ permissions:
12
+ contents: read
13
+ pages: write
14
+ id-token: write
15
+ with:
16
+ coverage-report: true
@@ -0,0 +1,58 @@
1
+ name: Release
2
+
3
+ on:
4
+ push:
5
+ tags:
6
+ - "v*.*.*"
7
+
8
+ permissions:
9
+ contents: write
10
+ id-token: write
11
+
12
+ jobs:
13
+ build:
14
+ runs-on: ubuntu-latest
15
+ steps:
16
+ - uses: actions/checkout@v7
17
+ with:
18
+ fetch-depth: 0
19
+
20
+ - name: Install uv
21
+ uses: astral-sh/setup-uv@v7
22
+ with:
23
+ version: "latest"
24
+
25
+ - name: Set up Python
26
+ run: uv python install 3.14
27
+
28
+ - name: Build distributions
29
+ run: uv build
30
+
31
+ - name: Upload build artifacts
32
+ uses: actions/upload-artifact@v7
33
+ with:
34
+ name: dist
35
+ path: dist/
36
+
37
+ - name: Upload to GitHub Release
38
+ uses: softprops/action-gh-release@v3
39
+ with:
40
+ files: dist/*
41
+
42
+ publish:
43
+ needs: build
44
+ runs-on: ubuntu-latest
45
+ environment:
46
+ name: pypi
47
+ url: https://pypi.org/project/fromscratch-pebble/
48
+ permissions:
49
+ id-token: write
50
+ steps:
51
+ - name: Download build artifacts
52
+ uses: actions/download-artifact@v8
53
+ with:
54
+ name: dist
55
+ path: dist/
56
+
57
+ - name: Publish to PyPI
58
+ uses: pypa/gh-action-pypi-publish@release/v1
@@ -0,0 +1,42 @@
1
+ # Byte-compiled / optimised
2
+ __pycache__/
3
+ *.py[cod]
4
+ *$py.class
5
+
6
+ # Distribution / packaging
7
+ dist/
8
+ build/
9
+ *.egg-info/
10
+ *.egg
11
+
12
+ # Virtual environments
13
+ .venv/
14
+ venv/
15
+
16
+ # IDE
17
+ .idea/
18
+ .vscode/
19
+ *.swp
20
+ *.swo
21
+
22
+ # Coverage
23
+ htmlcov/
24
+ .coverage
25
+ .coverage.*
26
+
27
+ # mypy / pyright
28
+ .mypy_cache/
29
+ .pyright/
30
+
31
+ # mkdocs
32
+ site/
33
+
34
+ # OS
35
+ .DS_Store
36
+ Thumbs.db
37
+
38
+ # hatch-vcs generated
39
+ src/pebble/_version.py
40
+
41
+ # Hypothesis
42
+ .hypothesis/
@@ -0,0 +1,56 @@
1
+ default_language_version:
2
+ python: python3.14
3
+
4
+ repos:
5
+ - repo: https://github.com/pre-commit/pre-commit-hooks
6
+ rev: v5.0.0
7
+ hooks:
8
+ # Pages paste real pytest output, trailing spaces included.
9
+ - id: trailing-whitespace
10
+ exclude: ^docs/property-testing\.md$
11
+ - id: end-of-file-fixer
12
+ exclude: ^docs/property-testing\.md$
13
+ - id: check-yaml
14
+ args: ['--unsafe']
15
+ - id: check-added-large-files
16
+ - id: check-json
17
+ - id: check-toml
18
+ - id: check-merge-conflict
19
+ - id: debug-statements
20
+
21
+ - repo: https://github.com/astral-sh/ruff-pre-commit
22
+ rev: v0.15.4
23
+ hooks:
24
+ - id: ruff
25
+ args: [--fix, --exit-non-zero-on-fix]
26
+ - id: ruff-format
27
+
28
+ - repo: https://github.com/RobertCraigie/pyright-python
29
+ rev: v1.1.408
30
+ hooks:
31
+ - id: pyright
32
+
33
+ - repo: local
34
+ hooks:
35
+ - id: pip-audit
36
+ name: pip-audit
37
+ language: system
38
+ pass_filenames: false
39
+ files: ^(pyproject\.toml|uv\.lock)$
40
+ entry: >-
41
+ bash -c 'f=$(mktemp) &&
42
+ uv export --frozen --no-emit-project --all-extras --no-hashes -o "$f" >/dev/null &&
43
+ uvx pip-audit==2.10.0 -r "$f" --disable-pip --no-deps;
44
+ status=$?; rm -f "$f"; exit $status'
45
+
46
+ - repo: https://github.com/rhysd/actionlint
47
+ rev: v1.7.7
48
+ hooks:
49
+ - id: actionlint
50
+
51
+ - repo: https://github.com/commitizen-tools/commitizen
52
+ rev: v4.13.8
53
+ hooks:
54
+ - id: commitizen
55
+ stages: [commit-msg]
56
+ additional_dependencies: [typing_extensions]
@@ -0,0 +1,56 @@
1
+ # Claude Code Instructions
2
+
3
+ <!-- standard:start -->
4
+ ## Code Style
5
+
6
+ - All public functions, methods, classes, and modules **must** have a docstring
7
+ - Use imperative mood: "Return the result." not "Returns the result."
8
+ - One-line docstrings for simple functions; multi-line with summary + details for complex ones
9
+ - Follow the Google docstring convention (D211, D212 selected via ruff)
10
+
11
+ ## Linting
12
+
13
+ - Ruff enforces a comprehensive rule set -- run `uv run ruff check .` before committing
14
+ - Pyright runs in strict mode -- run `uv run pyright src tests` before committing
15
+ - All violations must be fixed, not ignored. Exceptions are the repo-owned `ignore` and `per-file-ignores` lists in `pyproject.toml`, which belong to this repo; the series sync never edits them
16
+
17
+ ## Testing
18
+
19
+ - TDD workflow: Red-Green-Refactor
20
+ - Coverage is enforced by pytest-cov; the floor in `pyproject.toml` is repo-owned
21
+ - Test classes and methods also require docstrings
22
+ - Use named constants instead of magic values (PLR2004)
23
+ - Run `uv run pytest` before committing
24
+ - Property-based tests (Hypothesis) live in `tests/test_properties.py` and `tests/test_model.py`; the shared profiles are in the root `conftest.py` (owned by `series sync`). Run `uv run pytest --hypothesis-profile=thorough` before a release.
25
+
26
+ ## Commits
27
+
28
+ - Use conventional commits: `feat:`, `fix:`, `refactor:`, `test:`, `docs:`, `ci:`, `chore:`
29
+ - All changes go via PR from a feature branch (main is protected); merge when CI is green
30
+
31
+ ## Dependencies
32
+
33
+ - Package manager: uv
34
+ - Run `uv sync --all-extras` after modifying dependencies
35
+ - `uv.lock` is committed; CI and pre-commit audit it with pip-audit through `uvx`, so pip-audit is not a project dependency
36
+ - Sibling projects, where used, are pinned release tags in `[tool.uv.sources]` (git + tag); never use `path` sources
37
+
38
+ ## Releasing
39
+
40
+ - A release is a `vX.Y.Z` tag on main after the PR is merged
41
+ - Docs-only and tooling-only changes do not get a release tag
42
+ - Docs are built with `mkdocs build --strict` and deployed to GitHub Pages by the docs workflow
43
+ <!-- standard:end -->
44
+
45
+ ## Project notes
46
+
47
+ - Use imperative mood: "Return the token." not "Returns the token."
48
+ - Pyright in strict mode -- run `uv run pyright src tests` before committing
49
+ - All violations must be fixed, not ignored (except D203/D213 incompatible pair)
50
+ - Inline `# noqa:` is acceptable only when tools genuinely conflict (e.g., ARG002 vs pyright protocol parameter names, PLW0108 for typed default_factory lambdas)
51
+ - Minimum 80% coverage enforced by pytest-cov
52
+ - Use conventional commits (enforced by commitizen): `feat:`, `fix:`, `refactor:`, `test:`, `docs:`, `ci:`, `chore:`
53
+ - All changes go via PR from a feature branch (main is protected)
54
+ - Pre-commit hooks must pass: ruff, ruff-format, pyright, pip-audit
55
+ - Add production deps to `[project.dependencies]`
56
+ - Add dev deps to `[project.optional-dependencies.dev]` or `[dependency-groups.dev]`
@@ -0,0 +1,196 @@
1
+ # Contributing to Pebble
2
+
3
+ Thanks for your interest in contributing! This guide covers everything you need
4
+ to get started.
5
+
6
+ ## Prerequisites
7
+
8
+ | Tool | Version | Install |
9
+ |------|---------|---------|
10
+ | Python | 3.14+ | [python.org](https://www.python.org/downloads/) |
11
+ | uv | latest | `curl -LsSf https://astral.sh/uv/install.sh \| sh` |
12
+ | git | 2.x+ | [git-scm.com](https://git-scm.com/) |
13
+
14
+ ## Setup
15
+
16
+ ```bash
17
+ # Clone the repo
18
+ git clone https://github.com/robcox2910/pebble-lang.git
19
+ cd pebble-lang
20
+
21
+ # Install all dependencies (including dev tools)
22
+ uv sync --all-extras
23
+
24
+ # Install pre-commit hooks (linting + commit message validation)
25
+ uv run pre-commit install
26
+ uv run pre-commit install --hook-type commit-msg
27
+ ```
28
+
29
+ Verify everything works:
30
+
31
+ ```bash
32
+ uv run pytest --cov # tests pass, >= 80% coverage
33
+ uv run ruff check src/ tests/ # no lint errors
34
+ uv run pyright src tests # no type errors
35
+ ```
36
+
37
+ ## TDD Workflow
38
+
39
+ We follow **Red-Green-Refactor** for every code change:
40
+
41
+ 1. **Red** -- Write a failing test that describes the behaviour you want.
42
+ 2. **Green** -- Write the simplest code that makes the test pass.
43
+ 3. **Refactor** -- Clean up while keeping all tests green.
44
+
45
+ Never skip the red step. If you can't write a failing test first, take a moment
46
+ to think about what the code should actually do.
47
+
48
+ ## Branch Naming
49
+
50
+ Create a branch from `main` using one of these prefixes:
51
+
52
+ | Prefix | When to use |
53
+ |--------|-------------|
54
+ | `feat/` | New feature or language construct |
55
+ | `fix/` | Bug fix |
56
+ | `refactor/` | Restructuring without behaviour change |
57
+ | `test/` | Test-only changes |
58
+ | `docs/` | Documentation updates |
59
+ | `ci/` | CI/CD workflow changes |
60
+ | `chore/` | Dependency bumps, config tweaks |
61
+
62
+ Example: `feat/lexer`, `fix/parser-precedence`
63
+
64
+ ## Conventional Commits
65
+
66
+ Every commit message must follow [Conventional Commits](https://www.conventionalcommits.org/):
67
+
68
+ ```
69
+ <type>: <short description in imperative mood>
70
+
71
+ Optional longer explanation.
72
+ ```
73
+
74
+ Types match the branch prefixes: `feat:`, `fix:`, `refactor:`, `test:`,
75
+ `docs:`, `ci:`, `chore:`.
76
+
77
+ Good examples:
78
+
79
+ ```
80
+ feat: add lexer with token scanning
81
+ fix: handle unterminated string literals
82
+ docs: add tokens concept page
83
+ ```
84
+
85
+ Bad examples:
86
+
87
+ ```
88
+ updated stuff # no type, vague description
89
+ feat: adds lexer # not imperative mood ("adds" -> "add")
90
+ ```
91
+
92
+ ## Code Style
93
+
94
+ ### Modern Python
95
+
96
+ Use Python 3.14 idioms everywhere:
97
+
98
+ - `X | Y` for union types (not `Union[X, Y]` or `Optional[X]`)
99
+ - `StrEnum` for string enumerations
100
+ - `match/case` instead of if/elif chains where appropriate
101
+ - Direct imports: `from enum import StrEnum` not `import enum`
102
+
103
+ ### Docstrings
104
+
105
+ Every public function, method, class, and module needs a docstring:
106
+
107
+ - Use **imperative mood**: "Return the token." not "Returns the token."
108
+ - One-liner for simple functions, multi-line (Google style) for complex ones.
109
+
110
+ ```python
111
+ def next_token(self) -> Token:
112
+ """Return the next token from the source."""
113
+
114
+ def tokenize(self, source: str) -> list[Token]:
115
+ """Tokenize source code into a list of tokens.
116
+
117
+ Args:
118
+ source: The Pebble source code to tokenize.
119
+
120
+ Returns:
121
+ List of tokens including an EOF token at the end.
122
+
123
+ Raises:
124
+ LexerError: If the source contains invalid characters.
125
+ """
126
+ ```
127
+
128
+ ### Named Constants
129
+
130
+ Use named constants instead of magic numbers in tests and source code. Ruff
131
+ rule PLR2004 enforces this.
132
+
133
+ ```python
134
+ # Good
135
+ EXPECTED_TOKEN_COUNT = 5
136
+ assert len(tokens) == EXPECTED_TOKEN_COUNT
137
+
138
+ # Bad
139
+ assert len(tokens) == 5
140
+ ```
141
+
142
+ ## Linting and Type Checking
143
+
144
+ Run these before every commit (pre-commit hooks enforce them automatically):
145
+
146
+ ```bash
147
+ uv run ruff check src/ tests/ # lint
148
+ uv run ruff format src/ tests/ # format (or --check to verify)
149
+ uv run pyright src tests # type check (strict mode)
150
+ ```
151
+
152
+ Fix all violations. Inline `# noqa:` is acceptable only when tools genuinely
153
+ conflict (e.g., ARG002 vs pyright protocol parameter names).
154
+
155
+ ## Testing
156
+
157
+ ```bash
158
+ uv run pytest # run all tests
159
+ uv run pytest --cov # with coverage report
160
+ uv run pytest tests/test_x.py # run a specific file
161
+ uv run pytest -k "test_name" # run tests matching a pattern
162
+ ```
163
+
164
+ - Minimum **80% coverage** is enforced.
165
+ - Test classes and methods need docstrings too.
166
+ - Use `pytest.raises` as a context manager for exception testing.
167
+
168
+ ## Documentation Style
169
+
170
+ Our docs target a **12-year-old with an interest in computing**. Keep language
171
+ simple, use analogies, and avoid jargon without explanation.
172
+
173
+ Good:
174
+
175
+ > Tokens are like Lego bricks. The lexer sorts your code into different shaped
176
+ > bricks -- number bricks, word bricks, symbol bricks -- so the parser knows
177
+ > what to build with them.
178
+
179
+ Bad:
180
+
181
+ > The lexer performs lexical analysis, decomposing the source character stream
182
+ > into a sequence of classified tokens via finite automaton simulation.
183
+
184
+ ## Pull Request Process
185
+
186
+ 1. Create a feature branch from `main`.
187
+ 2. Make your changes following TDD.
188
+ 3. Ensure all checks pass: `uv run ruff check .`, `uv run pyright src tests`,
189
+ `uv run pytest --cov`.
190
+ 4. Push your branch and open a PR against `main`.
191
+ 5. PRs are squash-merged to keep history clean.
192
+
193
+ ## Questions?
194
+
195
+ Open an issue on [GitHub](https://github.com/robcox2910/pebble-lang/issues) --
196
+ we're happy to help!
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Rob Cox
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,156 @@
1
+ Metadata-Version: 2.5
2
+ Name: fromscratch-pebble
3
+ Version: 0.3.0
4
+ Summary: An educational compiler and bytecode VM for the Pebble language
5
+ Project-URL: Homepage, https://github.com/robcox2910/pebble-lang
6
+ Project-URL: Repository, https://github.com/robcox2910/pebble-lang
7
+ Project-URL: Issues, https://github.com/robcox2910/pebble-lang/issues
8
+ Project-URL: Documentation, https://robcox2910.github.io/pebble-lang/
9
+ Author: Rob Cox
10
+ License: MIT
11
+ License-File: LICENSE
12
+ Keywords: bytecode,compiler,education,language,virtual-machine
13
+ Classifier: Development Status :: 3 - Alpha
14
+ Classifier: Intended Audience :: Education
15
+ Classifier: License :: OSI Approved :: MIT License
16
+ Classifier: Programming Language :: Python :: 3
17
+ Classifier: Programming Language :: Python :: 3.14
18
+ Classifier: Topic :: Education
19
+ Classifier: Topic :: Software Development :: Compilers
20
+ Classifier: Topic :: Software Development :: Interpreters
21
+ Classifier: Typing :: Typed
22
+ Requires-Python: >=3.14
23
+ Provides-Extra: dev
24
+ Requires-Dist: commitizen>=4.4.0; extra == 'dev'
25
+ Requires-Dist: hypothesis>=6.170; extra == 'dev'
26
+ Requires-Dist: pip-audit>=2.10.0; extra == 'dev'
27
+ Requires-Dist: pre-commit>=4.0.1; extra == 'dev'
28
+ Requires-Dist: pyright>=1.1.400; extra == 'dev'
29
+ Requires-Dist: pytest-cov>=6.0.0; extra == 'dev'
30
+ Requires-Dist: pytest>=8.3.4; extra == 'dev'
31
+ Requires-Dist: ruff>=0.9.3; extra == 'dev'
32
+ Provides-Extra: docs
33
+ Requires-Dist: mkdocs-material>=9.5; extra == 'docs'
34
+ Description-Content-Type: text/markdown
35
+
36
+ # Pebble
37
+
38
+ An educational compiler and bytecode VM for the **Pebble** programming language.
39
+
40
+ Pebble is a small imperative language that compiles to bytecode and runs on a
41
+ custom stack-based virtual machine. The project is designed for learning how
42
+ compilers work, built incrementally using TDD.
43
+
44
+ ## Language Features
45
+
46
+ - Integers, floats, strings, booleans
47
+ - Variables (`let` declarations, `const`, reassignment)
48
+ - Arithmetic, comparison, bitwise, and logical operators (`and`, `or`, `not`)
49
+ - Short-circuiting `and` / `or` and chained comparisons (`1 < x < 10`)
50
+ - Control flow: `if/else`, `while`, `for` loops, `match`
51
+ - Collections: lists, dicts, list comprehensions, slicing, tuple unpacking
52
+ - Functions (`fn`, `return`), default arguments, closures, and generators (`yield`)
53
+ - Async / await (`async fn`, `await`)
54
+ - Structs, classes with inheritance, and enums
55
+ - Error handling: `try` / `catch` / `finally` and `throw`
56
+ - Modules and imports (`import`, `from ... import`)
57
+ - String interpolation (`"hello {name}"`)
58
+ - `print()` built-in
59
+ - Comments (`#`)
60
+ - Curly-brace blocks, newline-delimited statements (no semicolons)
61
+
62
+ ## Example
63
+
64
+ ```
65
+ let count = 0
66
+ while count < 5 {
67
+ if count > 0 {
68
+ print(count)
69
+ }
70
+ count = count + 1
71
+ }
72
+ ```
73
+
74
+ ## Pipeline
75
+
76
+ ```
77
+ Source -> Lexer -> Parser -> Analyzer -> Module Resolver -> Type Checker -> Compiler -> Optimizer -> VM
78
+ ```
79
+
80
+ See the [documentation](https://robcox2910.github.io/pebble-lang/) for a
81
+ kid-friendly walk-through of each stage.
82
+
83
+ ## Quick Start
84
+
85
+ ```bash
86
+ # Install dependencies
87
+ uv sync --all-extras
88
+
89
+ # Run tests
90
+ uv run pytest
91
+
92
+ # Lint and type check
93
+ uv run ruff check .
94
+ uv run pyright src tests
95
+ ```
96
+
97
+ ## Using Pebble from Python
98
+
99
+ ```python
100
+ from pebble import run_source
101
+
102
+ print(run_source('print("Hello from Pebble!")'), end="")
103
+ ```
104
+
105
+ `run_source`, `compile_source`, `check` and `format_source` are Pebble's public
106
+ API; see [Using Pebble from Python](docs/concepts/using-pebble-from-python.md).
107
+
108
+ <!-- docs:start -->
109
+ ## Documentation
110
+
111
+ Full docs (with kid-friendly explanations of every idea): https://robcox2910.github.io/pebble-lang/
112
+ <!-- docs:end -->
113
+
114
+ ## Releasing
115
+
116
+ Other projects in the series ([PyStack](https://github.com/robcox2910/pystack) and [PyLLM](https://github.com/robcox2910/pyllm)) use a pinned release of this one,
117
+ not whatever is on `main`. To publish a change for them:
118
+
119
+ 1. Merge the change to `main`.
120
+ 2. Tag it: `git tag -a vX.Y.Z -m vX.Y.Z && git push origin vX.Y.Z`.
121
+ A change to the public API bumps the minor version (`v0.1.0` → `v0.2.0`);
122
+ anything else bumps the patch (`v0.1.0` → `v0.1.1`).
123
+ 3. In each project that uses it, edit the tag in `[tool.uv.sources]`, run
124
+ `uv lock --upgrade-package <name>`, and open a pull request so CI checks
125
+ the pair together.
126
+
127
+ <!-- series:start -->
128
+ ## Related Projects
129
+
130
+ This project is one of a series that builds real systems "from scratch in Python" to teach how they work. See the [series home](https://robcox2910.github.io/) for the full story.
131
+
132
+ | Project | What it teaches | Repository | Docs |
133
+ | --- | --- | --- | --- |
134
+ | PyOS | Operating systems | [py-os](https://github.com/robcox2910/py-os) | [Docs](https://robcox2910.github.io/py-os/) |
135
+ | **Pebble** | **Compilers and programming languages** | [pebble-lang](https://github.com/robcox2910/pebble-lang) | [Docs](https://robcox2910.github.io/pebble-lang/) |
136
+ | PyDB | Relational databases | [pydb](https://github.com/robcox2910/pydb) | [Docs](https://robcox2910.github.io/pydb/) |
137
+ | PyKV | Key-value stores | [pykv](https://github.com/robcox2910/pykv) | [Docs](https://robcox2910.github.io/pykv/) |
138
+ | PyDocDB | Document databases | [pydoc-db](https://github.com/robcox2910/pydoc-db) | [Docs](https://robcox2910.github.io/pydoc-db/) |
139
+ | PyGraphDB | Graph databases | [pygraphdb](https://github.com/robcox2910/pygraphdb) | [Docs](https://robcox2910.github.io/pygraphdb/) |
140
+ | PyTSDB | Time-series databases | [pytsdb](https://github.com/robcox2910/pytsdb) | [Docs](https://robcox2910.github.io/pytsdb/) |
141
+ | PyVecDB | Vector databases | [pyvecdb](https://github.com/robcox2910/pyvecdb) | [Docs](https://robcox2910.github.io/pyvecdb/) |
142
+ | PyColDB | Column-family databases | [pycoldb](https://github.com/robcox2910/pycoldb) | [Docs](https://robcox2910.github.io/pycoldb/) |
143
+ | PyCrypt | Cryptography | [pycrypt](https://github.com/robcox2910/pycrypt) | [Docs](https://robcox2910.github.io/pycrypt/) |
144
+ | PyNet | Computer networking | [pynet](https://github.com/robcox2910/pynet) | [Docs](https://robcox2910.github.io/pynet/) |
145
+ | PyWeb | HTTP web servers | [pyweb](https://github.com/robcox2910/pyweb) | [Docs](https://robcox2910.github.io/pyweb/) |
146
+ | PyGit | Version control | [pygit](https://github.com/robcox2910/pygit) | [Docs](https://robcox2910.github.io/pygit/) |
147
+ | PySearch | Search engines | [pysearch](https://github.com/robcox2910/pysearch) | [Docs](https://robcox2910.github.io/pysearch/) |
148
+ | PyMQ | Message queues | [pymq](https://github.com/robcox2910/pymq) | [Docs](https://robcox2910.github.io/pymq/) |
149
+ | PyLLM | Language models (the brain) | [pyllm](https://github.com/robcox2910/pyllm) | [Docs](https://robcox2910.github.io/pyllm/) |
150
+ | PyScheduler | Job scheduling | [pyscheduler](https://github.com/robcox2910/pyscheduler) | [Docs](https://robcox2910.github.io/pyscheduler/) |
151
+ | PyStack | Full-stack integration | [pystack](https://github.com/robcox2910/pystack) | [Docs](https://robcox2910.github.io/pystack/) |
152
+ <!-- series:end -->
153
+
154
+ ## License
155
+
156
+ MIT