diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index 4bb8221..64414dd 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -1,4 +1,4 @@ -name: Upload Python Package +name: Build and Publish to GitHub Packages on: release: @@ -23,6 +23,6 @@ jobs: - name: Publish package to GitHub Packages uses: pypa/gh-action-pypi-publish@release/v1 with: - repository_url: https://pypi.pkg.github.com/Anand-0037 + repository_url: https://pypi.pkg.github.com/ user: __token__ password: ${{ secrets.GITHUB_TOKEN }} diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 0000000..c1da92d --- /dev/null +++ b/.github/workflows/test.yml @@ -0,0 +1,37 @@ +name: Test Package + +on: + push: + branches: [ main ] + pull_request: + branches: [ main ] + +jobs: + test: + runs-on: ubuntu-latest + strategy: + matrix: + python-version: [3.11, 3.12] + + steps: + - uses: actions/checkout@v4 + + - name: Set up Python ${{ matrix.python-version }} + uses: actions/setup-python@v4 + with: + python-version: ${{ matrix.python-version }} + + - name: Install package + run: | + python -m pip install --upgrade pip + pip install -e . + + - name: Run tests + run: | + python -m json_parser.test_runner + + - name: Test CLI tool + run: | + echo '{"test": "value"}' > test.json + json-parser test.json + json-parser test.json --verbose \ No newline at end of file diff --git a/.gitignore b/.gitignore index 1c87e7c..da34958 100644 --- a/.gitignore +++ b/.gitignore @@ -1,12 +1,58 @@ -dist/ -.venv/ - -.personal.md -__pycache__/ -*.pyc -.gitignore -.venv/ -.personal.md -.python-version - -*.egg-info/ \ No newline at end of file +# Python +__pycache__/ +*.py[cod] +*$py.class +*.so +.Python +build/ +develop-eggs/ +dist/ +downloads/ +eggs/ +.eggs/ +lib/ +lib64/ +parts/ +sdist/ +var/ +wheels/ +share/python-wheels/ +*.egg-info/ +.installed.cfg +*.egg +MANIFEST + +# Virtual environments +.env +.venv/ +env/ +venv/ +ENV/ +env.bak/ +venv.bak/ + +# IDEs +.vscode/ +.idea/ +*.swp +*.swo + +# OS +.DS_Store +Thumbs.db + +# Personal files +.personal.md +.python-version + +# Testing +.pytest_cache/ +.coverage +htmlcov/ +.tox/ +.cache + +# Build tools +.mypy_cache/ +.dmypy.json +dmypy.json \ No newline at end of file diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000..f24012e --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,24 @@ +# Changelog +All further changes will be documented here. + +## [0.1.1] - 2025-01-28 +### Fixed +- Fixed version consistency between pyproject.toml and __init__.py +- Fixed GitHub Packages workflow repository URL format +- Enhanced package metadata with better descriptions and URLs +- Improved .gitignore for Python projects +- Fixed filename typo: CHANNELOG.md → CHANGELOG.md + +### Enhanced +- Added support for Python 3.12 +- Better project classifiers and metadata +- More comprehensive .gitignore + +## [0.1.0] - 2025-01-28 +### Added +- Initial release of `json_parser` +- `json_parser` can parse JSON files using lexical analysis +- Support for primitive and compound datatypes +- Support for comments (// and /* */) +- CLI interface for validating JSON files +- Comprehensive test suite diff --git a/CHANNELOG.md b/CHANNELOG.md deleted file mode 100644 index 319ad14..0000000 --- a/CHANNELOG.md +++ /dev/null @@ -1,8 +0,0 @@ -# Channelog -All further changes wil be documented here. - -## [0.1.0] -2025-07-28 -- init release of `json_parser` -- `json_parser` can parse json files using lexical analysis -- support for primitve, compound datatypes, comments. -- cli interface for validating json files. diff --git a/README.md b/README.md index f05aea0..86909c5 100644 --- a/README.md +++ b/README.md @@ -1,40 +1,79 @@ # json-parser -A cli tool for lexical and syntactical analysis. It parses json files. +A CLI tool for lexical and syntactical analysis. It parses JSON files with support for comments. + ## [PyPI package](https://pypi.org/project/json-parser-cli/) +## [GitHub Packages](https://github.com/Anand-0037/json-parser/packages) --- ## Features -- Lexical analysis --> tokenize json input character by character. -- Parser --> Builds python objects fro tokens. -- CLI Interface --> Validating json files from cli. -- Error messages with line numbers -- include support for comments also. ('//' and '/* any content */') -- Uploaded on pypi [PyPI package](https://pypi.org/project/json-parser-cli/) -- No runtime dependencies required. +- Lexical analysis → tokenize JSON input character by character +- Parser → Builds Python objects from tokens using recursive descent parsing +- CLI Interface → Validating JSON files from command line +- Error messages with line numbers for precise debugging +- Support for comments (`//` single-line and `/* */` multi-line) +- Published on [PyPI](https://pypi.org/project/json-parser-cli/) and GitHub Packages +- No runtime dependencies required +- Support for all JSON data types (objects, arrays, strings, numbers, booleans, null) +- Proper Unicode and escape sequence handling ## Installation + +### From PyPI (recommended) ```bash pip install json-parser-cli ``` +### From GitHub Packages +```bash +pip install --index-url https://pypi.pkg.github.com/ json-parser-cli +``` + ## How to use -use ```json-parser``` command to validate json files. +Use `json-parser` command to validate JSON files: ```bash json-parser ``` +### Options +- `--verbose`: Show detailed parsing output +- `--help`: Show help message + +### Examples +```bash +# Basic validation +json-parser data.json + +# Verbose output showing parsed result +json-parser data.json --verbose +``` + +## Comment Support +This parser supports JSON with comments, which is useful for configuration files: + +```json +{ + // Single line comment + "name": "example", + /* Multi-line + comment */ + "value": 42 +} +``` + ## Learnings -How compiler works +Understanding how compilers work: -1. **Lexer.py** --> Convert text into tokens. -2. **Parser** --> Convert tokens to data using recursive descent parsing. +1. **Lexer.py** → Convert text into tokens (lexical analysis) +2. **Parser.py** → Convert tokens to data using recursive descent parsing (syntactic analysis) -### Json features supported -- Objects, Arrays. -- Strings, Numbers, Booleans. -- Null, nested structures, etc. -- comments, +### JSON features supported +- Objects `{}`, Arrays `[]` +- Strings, Numbers (including scientific notation), Booleans +- Null values, nested structures +- Comments: `//` and `/* */` +- Proper error reporting with line numbers +- Unicode support and escape sequences (`\n`, `\t`, `\"`, `\\`, etc.)