Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: Port to Antlr4 #4

Open
wants to merge 64 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
64 commits
Select commit Hold shift + click to select a range
9f2e19a
Start readme for next version of electro-grammar
kasbah Jan 3, 2018
f56a648
Add note about floating point numbers
kasbah Jan 3, 2018
7186dc1
Clear out initial js version
kasbah Jan 4, 2018
5f5a9d4
Remove initial python version
kasbah Jan 4, 2018
2ffcf42
Start antlr version
kasbah Jan 4, 2018
5401091
Simplify makefile
kasbah Jan 5, 2018
b6661e5
Play around with parsing capacitance
kasbah Jan 5, 2018
79d473b
Add js target
kasbah Jan 5, 2018
f17de09
Mess around with grammar and test in js
kasbah Jan 6, 2018
aac7e90
Add python3 backend.
dvc94ch Jan 20, 2018
e1ea1a2
js: Add cli.
dvc94ch Jan 20, 2018
e272d34
js: Uncomment tests.
dvc94ch Jan 20, 2018
cea8c7d
Update paths in prepare_cpl.js
dvc94ch Jan 20, 2018
3a6b1d3
antlr: Add PackageSize recognition.
dvc94ch Jan 20, 2018
a255819
Use es2015 in index.js
kasbah Jan 21, 2018
4c051b2
Correct unit conversion and tests for it
kasbah Jan 21, 2018
a767bd3
Re-enable travis testing
kasbah Jan 21, 2018
7d0fcd7
Start a lax parser
kasbah Jan 21, 2018
f26ea46
Rename test_units to test_strict_units
kasbah Jan 21, 2018
3eef93c
Add "prettier" code formatter
kasbah Jan 21, 2018
c47a0bc
Add ambiguity diagnostic output to index.js
kasbah Jan 22, 2018
6f513a9
Start ignorer error listeners in lax_parser
kasbah Jan 22, 2018
405b5e5
js: set ambiguity output directly like in python
kasbah Jan 22, 2018
4af0139
Ignore java directory.
dvc94ch Jan 22, 2018
7fc16e9
antlr: Parse package sizes.
dvc94ch Jan 20, 2018
5040fe8
antlr: Parse units.
dvc94ch Jan 21, 2018
6d8dd64
antlr: Parse dielectrics.
dvc94ch Jan 21, 2018
f757b9c
antlr: Parse passive components.
dvc94ch Jan 21, 2018
a09676b
antlr: Parse semiconductors.
dvc94ch Jan 21, 2018
2230145
Turn python package into a module.
dvc94ch Jan 21, 2018
8ad7046
python3: Add ambiguity diagnostics
kasbah Jan 22, 2018
7aa8ccd
python3: Add unit parsing tests.
dvc94ch Jan 22, 2018
af33c0d
python3: Add tolerance test case.
dvc94ch Jan 22, 2018
d4c2073
python3: Add package size tests.
dvc94ch Jan 22, 2018
0c93a59
python3: Add dielectric tests.
dvc94ch Jan 22, 2018
48a3b43
python3: Add passive tests.
dvc94ch Jan 22, 2018
8daaa95
python3: Add semiconductor tests.
dvc94ch Jan 22, 2018
96dc5a0
js: Feature parity with python port.
dvc94ch Jan 22, 2018
bb43e6e
antlr: Add some missing unit specifiers.
dvc94ch Jan 23, 2018
2b913b8
anltr: Recognize unicode characters.
dvc94ch Jan 23, 2018
1298b70
Fix lax parser tests.
dvc94ch Jan 23, 2018
ae0c048
Get some lax parsing tests working.
dvc94ch Jan 23, 2018
ea5e56e
Use lax parser in prepare_cpl.
dvc94ch Jan 23, 2018
edfa743
js: Rename listener
kasbah Jan 23, 2018
fc2c361
js: Add debugger script
kasbah Jan 23, 2018
c38b74a
Prepare cpl emits json.
dvc94ch Jan 23, 2018
1517704
js: Update cli interface.
dvc94ch Jan 26, 2018
fa74d76
py: Update cli interface.
dvc94ch Jan 26, 2018
32c34a0
Add test dependencies to root package.json
dvc94ch Jan 26, 2018
96f4aeb
Add language independent test suite.
dvc94ch Jan 26, 2018
03c29da
Recognize more package names.
dvc94ch Jan 26, 2018
de952ca
test: Enabling travis testing for new test-suite
kasbah Jan 26, 2018
2e5bbda
Move fmt:js up a dir, add a fmt:py using autopep8
kasbah Jan 26, 2018
eef61ea
test: Move pipenv invocation into package.json
kasbah Jan 26, 2018
2412075
py: Remove unused tests.
dvc94ch Jan 29, 2018
31586a6
py: autopep8 codebase.
dvc94ch Jan 29, 2018
f95e301
Merge pull request #12 from dvc94ch/package
kasbah Jan 29, 2018
7d7931c
Update package name for git installs.
dvc94ch Feb 3, 2018
0e63ef2
py: Create python package setup.py
dvc94ch Feb 3, 2018
4d0a92f
py: Build before making package.
dvc94ch Feb 3, 2018
1a80e04
Add requirement.txt
dvc94ch Feb 3, 2018
91f4af5
Remove semicolon.
dvc94ch Feb 3, 2018
d58a7a0
Tell travis to show the diff
kasbah Feb 4, 2018
2160a95
Add yarn lock
kasbah Feb 4, 2018
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
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,8 @@ coverage/
.nyc_output/
node_modules/
test-lib/

java/
js/**/ElectroGrammar*
python3/**/ElectroGrammar*
db/*.json
5 changes: 5 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
tabWidth: 2
semi: true
singleQuote: true
bracketSpacing: false
trailingComma: es5
17 changes: 13 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,14 +1,23 @@
language: node_js
node_js:
- "6"
- "8"
- "node"
matrix:
include:
- node_js: node
env: TEST_BROWSERS=true
before_install:
- cd travis
- wget --no-check-certificate https://www.antlr.org/download/antlr-4.7.1-complete.jar
- export CLASSPATH=".:$TRAVIS_BUILD_DIR/travis/antlr-4.7.1-complete.jar:$CLASSPATH"
- export PATH=$PATH:$TRAVIS_BUILD_DIR/travis
- cd ..
- cd js && npm install && cd ..
- pip install --user pipenv
- pipenv install --dev
script:
- yarn test
- yarn demo
- make
- npm test
- npm run fmt
- git diff
- git diff --quiet
- if [ "${TEST_BROWSERS}" = "true" ] && [ "${TRAVIS_PULL_REQUEST}" = "false" ]; then yarn test:sauce; fi
31 changes: 31 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
ANTLR=antlr4 -Xexact-output-dir
GRAMMAR=src/ElectroGrammar.g4
GRAMMAR_FILES=$(wildcard src/*.g4)

all: js python3

java: $(GRAMMAR) $(GRAMMAR_FILES)
$(ANTLR) $< -o java/
javac java/*.java -d java/

clean-java:
rm -f java/*


python3: $(GRAMMAR) $(GRAMMAR_FILES)
$(ANTLR) -Dlanguage=Python3 $< -o python3/electro_grammar/

clean-python3:
rm -f python3/electro_grammar/ElectroGrammar*


js: $(GRAMMAR) $(GRAMMAR_FILES)
$(ANTLR) -Dlanguage=JavaScript $< -o js/lib/

clean-js:
rm -f js/lib/ElectroGrammar*


clean: clean-java clean-python3 clean-js

.PHONY: all clean python3 clean-python3 java clean-java clean js clean-js
21 changes: 21 additions & 0 deletions Pipfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
[[source]]

url = "https://pypi.python.org/simple"
verify_ssl = true
name = "pypi"


[packages]

"antlr4-python3-runtime" = "*"


[dev-packages]

pytest = "*"
"autopep8" = "*"


[requires]

python_version = "3.6"
88 changes: 88 additions & 0 deletions Pipfile.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

41 changes: 41 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,44 @@
# Electro Grammar Next

## Goals

- Parse descriptions of common electronic components
- Primary:
- Resistors
- Capacitors
- LEDs
- Secondary
- Inductors
- Transistors
- Tertiary:
- Try and cover the [Common Parts Library][CPL]
- Be usable from multiple languages:
- Primary:
- Javascript (Browser & Node)
- Python
- Go
- Java
- Optional:
- Rust
- Haskell

## Output Details
In as much as possible the output should match that of the existing JS implementation except for:

- Unused i.e. ignored input should be returned. I made a [demo]( http://cloud.monostable.co.uk/egignore/) of an initial implementation but we need to change the lexing strategy to eek out th edge cases
- The grammar itself should work on "incomplete" descriptions i.e. component specs. E.g. the input `50V` should result in `{voltage_rating: 50}`.
- `size` should be renamed to `package`
- `characteristic` should be renamed to `dielectric` or `capacitor_dielectric`


## Open Questions

- Is floating point a good unit for capcitance, resistance e.t.c.? I noticed some floating point errors in the Python port when using them for calculation. What's a good alternative?
- Should we use Antlr or Pest or something else?
- Should we align the types with Octopart's taxonomy? (e.g. browsing parts from https://octopart.com)

---

# Electro Grammar [![Build Status][BADGE]][BUILD]

[![Sauce Test Status](https://saucelabs.com/browser-matrix/electro-grammar.svg)](https://saucelabs.com/u/electro-grammar)
Expand Down
Empty file added db/.gitkeep
Empty file.
Loading