bkiers / pcreparser Goto Github PK
View Code? Open in Web Editor NEWAn ANTLR 3 grammar for PCRE
License: MIT License
An ANTLR 3 grammar for PCRE
License: MIT License
$ java -cp antlr-3.3-complete.jar org.antlr.Tool PCRE.g
Error: Could not find or load main class org.antlr.Tool
$ ls
antlr-3.3-complete.jar PCRE.gr
$ pwd
/home/charly/gitrepo/PCREParser/src/main/antlr3/pcreparser
Iam not sure what iam I missing
At this point only named groups with letters can be processed. And as far as PCRE standard is concerned, digits can be there as well.
name
: letters -> NAME[$letters.text]
;
P.s. Great project btw, helped a lot!
"(?<hello_world>.+)"
That should be a valid capture group, but instead we see errors like this:
line 1:4 missing GreaterThan at '_'
The fix should be as simple as adding underscore to allowed characters in the NAME type.
P.S. Thank you for this awesome AST. It made my life a hundred times easier!
I've found what appears to be an error with parsing named captures.
Using the online parser I entered the following regular expression:
(?<named_cap>hello)
It produces the following AST:
'- ALTERNATIVE
'- ELEMENT
'- NAMED_CAPTURING_GROUP_PERL
|- NAME='named'
'- ALTERNATIVE
|- ELEMENT
| '- LITERAL='_'
|- ELEMENT
| '- LITERAL='c'
|- ELEMENT
| '- LITERAL='a'
|- ELEMENT
| '- LITERAL='p'
|- ELEMENT
| '- LITERAL='>'
|- ELEMENT
| '- LITERAL='h'
|- ELEMENT
| '- LITERAL='e'
|- ELEMENT
| '- LITERAL='l'
|- ELEMENT
| '- LITERAL='l'
'- ELEMENT
'- LITERAL='o'
As you can see, instead of identifying a named capturing group with the name named_cap
, it identifies a group with the name named
, and inteprets _cap>
(including, oddly, the trailing >
) as literals.
According pcrepattern(3), underscores are valid in named capture names:
In PCRE, a subpattern can be named in one of three ways:
(?<name>...)
or(?'name'...)
as in Perl, or(?P<name>...)
as in Python. ... Names consist of up to 32 alphanumeric characters and underscores, but must start with a non-digit.
Am I correct in thinking this is a bug, or have I misunderstood something?
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.