polux / parsers Goto Github PK
View Code? Open in Web Editor NEWParser Combinators for Dart
License: Other
Parser Combinators for Dart
License: Other
Rationale: I think it would make my programs more readable to other Dart programmers who aren't familiar with Haskell, by analogy with Future.
@polux might of found a strange bug.
When trying to parse the first example everything works fine. On the second example the parser blows up with exception. Look at the line // multiline
good
final test = """
// Data core processor package
// Second comment line
[someattribute]
namespace datacore {
// Defined interface of the processor
interface DataProc {
// Loads data for the processor as object array
// multiline
bool loadData(array data, int size);
// Loads data for the processor as int array
void load(int data[]);
// Executes the processor
void run();
/* Returns the result of the processor */
DataProcResult result();
};
/**
* A data type for the processor result
* Multi line comment
* With information.
*/
dictionary DataProcResult {
double timeSpent;
// Value calculated from processing
int value;
};
};
""";
bad
final test = """
// Data core processor package
// Second comment line
[someattribute]
namespace datacore {
// Defined interface of the processor
interface DataProc {
// Loads data for the processor as object array
// multiline
bool loadData(array data, int size);
// Loads data for the processor as int array
void load(int data[]);
// Executes the processor
void run();
/* Returns the result of the processor */
DataProcResult result();
};
/**
* A data type for the processor result
* Multi line comment
* With information.
*/
dictionary DataProcResult {
double timeSpent;
// Value calculated from processing
int value;
};
};
""";
Exception
Breaking on exception: "line 9, character 5: expected identifier or 'void', got '/'."
Sorry for the question, but I don't know where else to put this. Basically, I have this script:
import 'package:parsers/parsers.dart';
class Zinc extends LanguageParsers {
Zinc(): super(reservedNames: ['let', 'in', 'join', 'cut']);
get start => prog().between(spaces, eof);
get comma => char(',') < spaces;
get lp => symbol('(');
get rp => symbol(')');
get lb => symbol('{');
get rb => symbol('}');
get colon => symbol(':');
get dollar => symbol('\$');
get plus => symbol('+');
get minus => symbol('-');
get star => symbol('*');
get slash => symbol('/');
get eq => symbol('=');
get len => symbol('#');
get in_ => char('E');
get where => char('W');
get sort => char('S');
prog() => (reserved['let'] + decls() + reserved['in'] + expr()).list;
decls() => decl().sepBy(comma);
decl() => oprw() | fdecl();
fdecl() => (identifier + lp + identifier.sepBy(comma) + rp + eq + expr()).list;
oprw() => (op() + eq + (magicop() | op())).list |
(identifier.sepBy1(op()) + eq + expr()).list;
magicop() => reserved['join'] | reserved['cut'];
basicop() => plus | minus | star | slash | len | eq;
op() => (basicop() + colon).list | basicop();
expr() => setcomp() | binop();
setcomp() => (lb + identifier + in_ + rec(expr) + clause() + rb).list;
clause() => ((where | sort) + rec(expr)).list;
binop() => (prim() + op() + expr()) | (dollar + prim());
prim() => identifier | intLiteral;
}
final test = """
let
in x
""";
void main() {
print(new Zinc().start.parse(test));
}
I would guess it should work. Except that it DOESN'T. It just loops forever. What am I doing wrong?
Some parsers shouldn't have error messages, they always should produce success results. For such parsers caring about expectations is really expensive and unnecessary. Idea is to make some subclass or some flag to exclude everything unneeded. I've tested on my library (just copied and rewrote many, skipMany and choose methods) and parser started working 30% faster.
Most of the operators and methods on Parser have cryptic comments. For example:
/// Applicative <*>
Parser operator *(Parser p) => this >> (f) => p >> (x) {
Function ff = f;
return success(ff(x));
};
I think most Dart developers will be entirely mystified by this comment. It would be more user-friendly explain what this operator does without assuming you know Haskell or have read the research papers.
Is this project still maintained?
Are there plans to support strong mode in the source so that it works with DDC?
Current version of alphanum, upper, lower parser accepts only latin chars while Haskell's parsers accept all unicode chars.
I know that Dart doesn't have methods to test char agains unicode class, but we could implement it on our own but we can use http://www.unicode.org/Public/6.3.0/ucd/UnicodeData.txt to generate predicates which work with all unicode chars.
Does it makes sense? Or this shouldn't be part of parsers library?
@polux can you publish a new version with the everythingBetween
changes? Thanks!
Would it be possible to modify the base LanguageParsers
class to support some kind of buffering or storage of comments? I had recently copied it out and made minor modifications to support what I was trying to accomplish with good results. https://github.com/dart-gde/chrome_gen.dart/blob/master/tool/web_idl_parser.dart#L37 It was not the best design but enough to get what I need in the short term.
Since I updated flutter yesterday I'm always getting this error if I try to execute the full_arith example:
type '() => dynamic' is not a subtype of type '() => Parser'
It seems that there has something changed, or am I wrong?
Hi Paul,
I'm reading the source of 'parsers' these days, and found the 'isCommitted' property is not easy to understand.
I asked a question:
http://stackoverflow.com/questions/22432617/how-to-understand-the-iscommitted-property-of-parserresult
Could you help me when you have time? Thank you!
The tutorial ends just after a heading for "Recursion". Could you explain how it works?
Hey,
since strong_mode is working I was thinking Dart 2 is already supported, but if I try to pub get ^1.0.0
of parsers I'll get:
Resolving dependencies...
The current Dart SDK version is 2.0.0.
Because systori depends on parsers >=0.0.2 which requires SDK version <2.0.0, version solving failed.
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.