Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Upload Python Package
name: Build and Publish to GitHub Packages

on:
release:
Expand All @@ -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 }}
37 changes: 37 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -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
70 changes: 58 additions & 12 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,12 +1,58 @@
dist/
.venv/

.personal.md
__pycache__/
*.pyc
.gitignore
.venv/
.personal.md
.python-version

*.egg-info/
# 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
24 changes: 24 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
8 changes: 0 additions & 8 deletions CHANNELOG.md

This file was deleted.

73 changes: 56 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
@@ -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 <file_name.json>
```

### 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.)


<!--
Expand Down
14 changes: 11 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,34 +1,42 @@
[project]
name = "json-parser-cli"
version = "0.1.1"
description = "A JSON parser and CLI tool (learning purpose)"
description = "A JSON parser and CLI tool with comment support"
readme = "README.md"
requires-python = ">=3.11"
authors = [
{name = "Anand Vashishtha", email = "anandcollege07@gmail.com"}
]
license = {text = "MIT"}
keywords = ["json", "parser", "lexer", "compiler", "cli"]
keywords = ["json", "parser", "lexer", "compiler", "cli", "comments"]
classifiers = [
"Development Status :: 3 - Alpha",
"Intended Audience :: Developers",
"License :: OSI Approved :: MIT License",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
"Topic :: Software Development :: Compilers",
"Topic :: Text Processing",
]

dependencies = []


[project.scripts]
json-parser = "json_parser.json_parser:main"

[project.urls]
Repository = "https://github.com/Anand-0037/json-parser"
Homepage = "https://github.com/Anand-0037/json-parser"
"Bug Tracker" = "https://github.com/Anand-0037/json-parser/issues"
Changelog = "https://github.com/Anand-0037/json-parser/blob/main/CHANGELOG.md"

[build-system]
requires = ["hatchling"]
build-backend = "hatchling.build"

[tool.hatch.build.targets.wheel]
packages = ["src/json_parser"]

[tool.hatch.metadata]
allow-direct-references = true
2 changes: 1 addition & 1 deletion src/json_parser/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
from .lexer import Lexer, Token, TokenType
from .parser import Parser

__version__ = "0.1.0"
__version__ = "0.1.1"
__all__ = ["parse_json", "parse_json_file", "Lexer", "Token", "TokenType", "Parser"]