ldthomas / apg-py Goto Github PK
View Code? Open in Web Editor NEWPython APG - an ABNF Parser Generator
License: BSD 2-Clause "Simplified" License
Python APG - an ABNF Parser Generator
License: BSD 2-Clause "Simplified" License
I'd like to use this project to validate some input using our ABNF, but it's having issues with any UTF-8 that's greater than a single byte. It looks like it's has something to do with the way you handle Unicode. Maybe you have a different approach than what I'm doing.
Part of the ABNF ensures that UTF-8 text is properly XML escaped.
xml-text = 1*(unencoded / encoded)
unencoded = %x09 /
%x0A /
%x0D /
%x20-21 /
; omit 0x22 double quote
%x23-25 /
; omit 0x26 ampersand
; omit 0x27 single quote
%x28-3B /
; omit 0x3C less than
%x3D /
; omit 0x3E greater than
%x3F-7E /
UTF8-2 /
UTF8-3 /
UTF8-4
encoded = %x26 (%s"quot" / %s"amp" / %s"apos" / %s"lt" / %s"gt") %x3B
UTF8-2 = %xC2-DF UTF8-tail
UTF8-3 = %xE0 %xA0-BF UTF8-tail / %xE1-EC 2(UTF8-tail) /
%xED %x80-9F UTF8-tail / %xEE-EF 2(UTF8-tail)
UTF8-4 = %xF0 %x90-BF 2(UTF8-tail) / %xF1-F3 3(UTF8-tail) /
%xF4 %x80-8F 2(UTF8-tail)
UTF8-tail = %x80-BF
Validation script:
#!/usr/bin/env python3
from apg_py.lib import utilities as utils
from apg_py.lib.parser import Parser
from apg_py.api.api import Api
import sys
with open(sys.argv[1]) as f:
grammar = f.read()
with open(sys.argv[2]) as f:
input = f.read()
result = Parser(Api().generate(grammar)).parse(utils.string_to_tuple(input))
print(result.success)
Some small tests:
input | expected | actual |
---|---|---|
Hello |
Pass | Pass |
G'day |
Fail | Fail |
G'day |
Pass | Pass |
G’day |
Pass | Fail |
Adiós |
Pass | Fail |
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.