Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(378)

Issue 8404031: IDL parser (Closed)

Created:
9 years, 1 month ago by sra1
Modified:
9 years, 1 month ago
Reviewers:
vsm, Jennifer Messerly
CC:
reviews_dartlang.org
Visibility:
Public.

Description

PEG Parser: under review at http://codereview.chromium.org/8399029 Some features are not yet implemented (e.g. attributes). BUG= TEST= Committed: https://code.google.com/p/dart/source/detail?r=869

Patch Set 1 #

Patch Set 2 : Add copyright #

Total comments: 55

Patch Set 3 : CR changes #

Patch Set 4 : merge #

Unified diffs Side-by-side diffs Delta from patch set Stats (+2047 lines, -0 lines) Patch
A client/dom/scripts/idlparser.dart View 1 2 1 chunk +547 lines, -0 lines 0 comments Download
A client/dom/scripts/idlparser_test.dart View 1 1 chunk +115 lines, -0 lines 0 comments Download
A client/dom/scripts/idlrenderer.dart View 1 1 chunk +181 lines, -0 lines 0 comments Download
A utils/peg/pegparser.dart View 1 2 3 1 chunk +858 lines, -0 lines 0 comments Download
A utils/peg/pegparser_test.dart View 1 2 3 1 chunk +346 lines, -0 lines 0 comments Download

Messages

Total messages: 4 (0 generated)
sra1
9 years, 1 month ago (2011-10-27 08:19:59 UTC) #1
sra1
9 years, 1 month ago (2011-10-27 08:29:32 UTC) #2
Jennifer Messerly
I didn't look in detail through the IDL parser, but it's neat how simple/tweakable it ...
9 years, 1 month ago (2011-10-28 01:21:10 UTC) #3
sra1
9 years, 1 month ago (2011-10-28 05:06:25 UTC) #4
Thanks for the review.
Vijay - any comments.

http://codereview.chromium.org/8404031/diff/2001/client/dom/scripts/idlparser...
File client/dom/scripts/idlparser.dart (right):

http://codereview.chromium.org/8404031/diff/2001/client/dom/scripts/idlparser...
client/dom/scripts/idlparser.dart:54: }
On 2011/10/28 01:21:10, John Messerly wrote:
> indent +2

Done.

http://codereview.chromium.org/8404031/diff/2001/client/dom/scripts/idlparser...
client/dom/scripts/idlparser.dart:62: //IDLType.nullable(IDLType base) {
On 2011/10/28 01:21:10, John Messerly wrote:
> remove or add TODO?

Done.

http://codereview.chromium.org/8404031/diff/2001/utils/peg/pegparser.dart
File utils/peg/pegparser.dart (right):

http://codereview.chromium.org/8404031/diff/2001/utils/peg/pegparser.dart#new...
utils/peg/pegparser.dart:1: #library('Peg Parser');
On 2011/10/28 01:21:10, John Messerly wrote:
> Do they intend to allow spaces in the name? (I'm not entirely sure what the
> names are for... if it's descriptive, then spaces totally makes sense.)

My working hypothesis is if it was meant to be an identifier, the syntax would
be an identifier.

But we also have:
#import('...', prefix: 'a string');
:-)

http://codereview.chromium.org/8404031/diff/2001/utils/peg/pegparser.dart#new...
utils/peg/pegparser.dart:42: if (spec is int)
On 2011/10/28 01:21:10, John Messerly wrote:
> I hesitate to suggest style for someone else's code. feel free to ignore style
> nits :)
> 
> but fwiw, the C++ guide (and JS) generally has { } around if-body, unless it's
a
> single line if.
> (http://google-styleguide.googlecode.com/svn/trunk/cppguide.xml#Conditionals)

I'm experimenting. cpp style does not actually say the braces are needed here,
juts that both legs must have them if one leg does.  I read omission as
permission.

http://codereview.chromium.org/8404031/diff/2001/utils/peg/pegparser.dart#new...
utils/peg/pegparser.dart:55: return new _AnyCharRule();
On 2011/10/28 01:21:10, John Messerly wrote:
> const?

Done.

http://codereview.chromium.org/8404031/diff/2001/utils/peg/pegparser.dart#new...
utils/peg/pegparser.dart:62: codes.sort((a, b) =>  a < b ? -1 : a > b ? 1 : 0);
On 2011/10/28 01:21:10, John Messerly wrote:
> codes.sort((a, b) => a.compareTo(b));
> ...since num is Comparable?

I could, but the Frog code is kind of disgusting.

http://codereview.chromium.org/8404031/diff/2001/utils/peg/pegparser.dart#new...
utils/peg/pegparser.dart:68: List<bool> flags = new List<bool>(len);
On 2011/10/28 01:21:10, John Messerly wrote:
> style nit: repeated type name

Done.

http://codereview.chromium.org/8404031/diff/2001/utils/peg/pegparser.dart#new...
utils/peg/pegparser.dart:70: flags[i] = false;
On 2011/10/28 01:21:10, John Messerly wrote:
> I wonder if we should have a BitList class somewhere in the core libs.
> Not a big deal for these guys though, since presumably IDL isn't going to use
> crazy 32-bit unicode chars :)

The bitlist would probably be slower in access too.

http://codereview.chromium.org/8404031/diff/2001/utils/peg/pegparser.dart#new...
utils/peg/pegparser.dart:184: _Rule
OR([a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z]) =>
On 2011/10/28 01:21:10, John Messerly wrote:
> something tells me you wanted spread/rest args :)
> 
> Does it look too bad to use [...] at the call sites?

Yes, it looks bad because [ means both sequence and choice.
It took me a long time to decide to do it this way.

http://codereview.chromium.org/8404031/diff/2001/utils/peg/pegparser.dart#new...
utils/peg/pegparser.dart:216: class Grammar {
On 2011/10/28 01:21:10, John Messerly wrote:
> In theory, you could get by without this class? It seems like the main thing
it
> does is skip whitespace. (holds onto Symbols, too, but those could easily be
> stored in variables)

In a different implementation the Grammar would be the collection of rules to
allow analysis.
It could also be a useful point for keeping a set of caches that need clearing.

http://codereview.chromium.org/8404031/diff/2001/utils/peg/pegparser.dart#new...
utils/peg/pegparser.dart:227: //whitespace = OR([' ', '\t', '\r', '\n']);
On 2011/10/28 01:21:10, John Messerly wrote:
> remove?

Done.

http://codereview.chromium.org/8404031/diff/2001/utils/peg/pegparser.dart#new...
utils/peg/pegparser.dart:228: this.whitespace = CHAR(' \t\r\n');
On 2011/10/28 01:21:10, John Messerly wrote:
> shouldn't need "this." anymore now that the bug is fixed

Done.

http://codereview.chromium.org/8404031/diff/2001/utils/peg/pegparser.dart#new...
utils/peg/pegparser.dart:235: Symbol operator [](String name) {
On 2011/10/28 01:21:10, John Messerly wrote:
> Could define a setter too that would set the Symbol.def? Hmm, maybe that's too
> strange because the types would be different.

The whole thing with having to define symbols and then define their rule is a
bit clunky.
I'll leave it as is for now.  I know Gilad wants to make the types the same.

http://codereview.chromium.org/8404031/diff/2001/utils/peg/pegparser.dart#new...
utils/peg/pegparser.dart:269: for (var rule in state.max_rule)
On 2011/10/28 01:21:10, John Messerly wrote:
> if we got here, isn't state.max_rule empty? should the check above be
!isEmpty?

Good catch.  I was wondering where the informative messages has gone :-)

http://codereview.chromium.org/8404031/diff/2001/utils/peg/pegparser.dart#new...
utils/peg/pegparser.dart:272: tokens.sort((a, b) =>
a.startsWith("'")==b.startsWith("'") ? a.compareTo(b)
On 2011/10/28 01:21:10, John Messerly wrote:
> style nit: long line, spaces etc

Done.

http://codereview.chromium.org/8404031/diff/2001/utils/peg/pegparser.dart#new...
utils/peg/pegparser.dart:322: bool in_whitespace_mode = false;
On 2011/10/28 01:21:10, John Messerly wrote:
> style nit: camelCase

Done.

http://codereview.chromium.org/8404031/diff/2001/utils/peg/pegparser.dart#new...
utils/peg/pegparser.dart:400: _Rule _compile_optional(rule) {
On 2011/10/28 01:21:10, John Messerly wrote:
> why not put this check in _compile?
> style nit: name should be _compileOptional

It gives the user better errors if null throws at 'compile' time.

Done.

http://codereview.chromium.org/8404031/diff/2001/utils/peg/pegparser.dart#new...
utils/peg/pegparser.dart:404: _Rule _compile(rule) {
On 2011/10/28 01:21:10, John Messerly wrote:
> I found the name "compile" a bit confusing here. Not sure what to suggest
> instead though.

Me neither.

http://codereview.chromium.org/8404031/diff/2001/utils/peg/pegparser.dart#new...
utils/peg/pegparser.dart:436: throw new ParseError(message);
On 2011/10/28 01:21:10, John Messerly wrote:
> include position?

The position needs to be converted into something pretty.
I think I want to handle that in diagnose.

http://codereview.chromium.org/8404031/diff/2001/utils/peg/pegparser.dart#new...
utils/peg/pegparser.dart:447: if (pos == state._end)
On 2011/10/28 01:21:10, John Messerly wrote:
> I wonder if there's a way to do this without checking this condition in every
> rule

I din't think there is.  Every access to the text needs to be guarded somewhere,
explicitly or implicitly.

http://codereview.chromium.org/8404031/diff/2001/utils/peg/pegparser.dart#new...
utils/peg/pegparser.dart:504: if (pos + _len > state._end)
On 2011/10/28 01:21:10, John Messerly wrote:
> should be >=, to match a string at the end ?

It is correct.  Normally you check pos < end. But this is pos+len, the last
position of which is pos+len-1 < end  --->  pos+len <= end  so the negative is
pos+len > end.

This is well tested :-).

http://codereview.chromium.org/8404031/diff/2001/utils/peg/pegparser.dart#new...
utils/peg/pegparser.dart:680: if (match == null)
On 2011/10/28 01:21:10, John Messerly wrote:
> I often write this as:
> return (match == null) ? [pos, null] : match;

I'm not a fan of ?:
I prefer if-then-else as an expression.
But it beats adding a bunch of curlies.
I know Google style is vehemently anti-pretty-formatting, but this way the
alternatives line up visually.

http://codereview.chromium.org/8404031/diff/2001/utils/peg/pegparser.dart#new...
utils/peg/pegparser.dart:787: return map[pos];
On 2011/10/28 01:21:10, John Messerly wrote:
> btw: instead of doing two lookups via "map.containsKey(pos)" then "map[pos]"
you
> can just do "map[pos]" and return the result if it's != null.

But null can be stored in the map!

Powered by Google App Engine
This is Rietveld 408576698