Skip to content

Commit

Permalink
First pass on aggregate options, see #95
Browse files Browse the repository at this point in the history
  • Loading branch information
dcodeIO committed Jul 17, 2015
1 parent dc1fd21 commit 96b38d4
Show file tree
Hide file tree
Showing 38 changed files with 532 additions and 416 deletions.
2 changes: 1 addition & 1 deletion dist/ProtoBuf-light.js
Original file line number Diff line number Diff line change
Expand Up @@ -429,7 +429,7 @@
ProtoBuf.Lang = {

// Characters always ending a statement
DELIM: /[\s\{\}=;\[\],'"\(\)<>]/g,
DELIM: /[\s\{\}=;:\[\],'"\(\)<>]/g,

// Field rules
RULE: /^(?:required|optional|repeated|map)$/,
Expand Down
2 changes: 1 addition & 1 deletion dist/ProtoBuf-light.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file modified dist/ProtoBuf-light.min.js.gz
Binary file not shown.
2 changes: 1 addition & 1 deletion dist/ProtoBuf-light.min.map

Large diffs are not rendered by default.

33 changes: 30 additions & 3 deletions dist/ProtoBuf.js
Original file line number Diff line number Diff line change
Expand Up @@ -429,7 +429,7 @@
ProtoBuf.Lang = {

// Characters always ending a statement
DELIM: /[\s\{\}=;\[\],'"\(\)<>]/g,
DELIM: /[\s\{\}=;:\[\],'"\(\)<>]/g,

// Field rules
RULE: /^(?:required|optional|repeated|map)$/,
Expand Down Expand Up @@ -664,10 +664,14 @@
/**
* Omits an optional token.
* @param {string} expected Expected optional token
* @returns {boolean} `true` if the token exists
*/
TokenizerPrototype.omit = function(expected) {
if (this.peek() === expected)
if (this.peek() === expected) {
this.next();
return true;
}
return false;
};

/**
Expand Down Expand Up @@ -916,11 +920,34 @@
}
}
this.tn.skip('=');
parent["options"][name] = this._readValue(true);
this._parseOptionValue(parent, name);
if (!isList)
this.tn.skip(";");
};

/**
* Parses an option value.
* @param {!Object} parent
* @param {string} name
* @private
*/
ParserPrototype._parseOptionValue = function(parent, name) {
var token = this.tn.peek();
if (token !== '{') { // Plain value
parent["options"][name] = this._readValue(true);
} else { // Aggregate options
this.tn.skip("{");
while ((token = this.tn.next()) !== '}') {
if (!Lang.NAME.test(token))
throw Error("illegal option name: " + name + "." + token);
if (this.tn.omit(":"))
parent["options"][name + "." + token] = this._readValue(true);
else
this._parseOptionValue(parent, name + "." + token);
}
}
};

/**
* Parses a service definition.
* @param {!Object} parent Parent definition
Expand Down
Loading

0 comments on commit 96b38d4

Please sign in to comment.