Comments (6)
Your proposal mixes two (quite distinct) styles of defining grammars.
The first style is the one you typically see in-lined with normal Dart code. Here you build little grammars, assign them to variables, compose them and use them for parsing/matching right away. This is how most of the tests are built, and the suggested way of building grammars if productions don't refer to themselves and if re-usability is not of a concern.
The second style is the one where you subclass CompositeParser
. This is where you declaratively define large, possibly recursive grammars that have possibly different production actions associated. I don't mind letting def(...)
return the new production, but it looks to me that you just try to avoid having to refer to productions by name? Did you see CompositeParser2
that uses noSuchMethod(...)
to define and refer to productions?
from dart-petitparser.
I just tried CompositeParser2
, it works but not friendly to my IDE(I use IDEA dart plugin).
For the code:
dart_instr_expr = char(r'$') & block_brace;
dart_str_single = char("'") & (dart_instr_expr | string(r"\'") | char("'").neg()).star() & char("'");
dart_str_double = char('"') & (dart_instr_expr | string(r'\"') | char('"').neg()).star() & char('"');
The type checker of IDE will warning that it can't resolve the variables like dart_instr_expr
, and it won't help to assist the names when I typing.
So I think it's great to let me write code like this:
class MyParser extends CompositeParser {
var start;
var aaa ;
void initialize() {
aaa = def("aaa", string("aaa")); // return value if void !!!
start = def("start", aaa) ;
aaa.map((each) => "[$each]"); // action can't work !!
}
}
In this way, the editor will work perfectly.
from dart-petitparser.
Or provide a powerful function to generate a name for me, that I don't need to write it?
class MyParser extends CompositeParser {
var aaa ;
void initialize() {
aaa = powerful(string("aaa"));
def("start", aaa) ;
aaa.map((each) => "[$each]");
}
}
from dart-petitparser.
Aha, I find I can use a fake class to help IDE:
class PaserDef {
var aaa;
var start;
}
class MyParser extends CompositeParser2 implements PaserDef {
void initialize() {
aaa = string("aaa");
start = aaa;
aaa((each) => "[$each]");
}
}
main() {
var parser = new MyParser();
var rs = parser.parse("aaa");
print(rs.value);
}
The ParserDef
class is only used to help IDE. But the noSuchMethod
is still working :)
from dart-petitparser.
The names/variables of CompositeParser
or CompositeParser2
are not used by PetitParser, they are purely for the convenience of the grammar designer. Not clear why you try to work around these helpers? Why don't you create your grammar in a factory method or your own helper class then?
from dart-petitparser.
You are right, I didn't realize I can create my own, thank you!
from dart-petitparser.
Related Issues (20)
- how do I provide better error messages? HOT 1
- Translate JS/TS to Dart? HOT 5
- Alternative to trim parser or how to discard HOT 2
- Relevance of `refX`? HOT 1
- Broken link for linter rules HOT 1
- Eliminate dynamic calls
- How to upgrade? HOT 7
- Getting line and colone in the code. HOT 2
- Improve error reporting of `ExpressionPaser` HOT 1
- Consider rolling meta back to ^1.8.0 HOT 1
- Greedy parse problem HOT 2
- Higher Unicode planes support? HOT 2
- Collecting Parsed result and passing it to next product HOT 1
- Possible alternative use of switch that might be fast enough HOT 3
- ReferenceParser prevents repeatString optimization HOT 1
- Projects that are using PetitParser HOT 1
- Parsing Latin1 characters HOT 4
- Alternative to deprecated `separatedBy(separator, includeSeparators: false)` HOT 2
- Choice parser behavior HOT 2
- use petitparser to recognize jsonDecode output HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from dart-petitparser.