Permalink
Browse files

bsjs: add a little bit pressure on IC

  • Loading branch information...
1 parent 2a9f141 commit 36ff541dad6b7f685ed8cef0f9f71d6d5f93dd90 @indutny indutny committed May 25, 2012
Showing with 341 additions and 329 deletions.
  1. +5 −0 lib/ometajs/compiler/ir.js
  2. +23 −16 lib/ometajs/core/grammar.js
  3. +304 −304 lib/ometajs/grammars/bsjs.js
  4. +9 −9 lib/ometajs/grammars/bsjs.ometajs
@@ -235,6 +235,7 @@ IR.prototype.render = function render() {
buf.push('this._skip()');
break;
}
+
buf.push(
'this.', '_rule', '(',
JSON.stringify(ast[1].replace(/^@/, '')),
@@ -252,6 +253,10 @@ IR.prototype.render = function render() {
']',
',',
ast[0] === 'rule' ? 'null' : parent,
+ ',',
+ ast[0] === 'rule' ? 'this[' : (parent + '.prototype['),
+ JSON.stringify(ast[1].replace(/^@/, '')),
+ ']',
')'
);
break;
@@ -99,22 +99,24 @@ AbstractGrammar.prototype._lastError = function _lastError(rule) {
};
//
-// ### function _invoke (grmr, rule, nc, args)
-// #### @grmr {AbstractGrammar} any instance of abstract grammar
-// #### @rule {String} Rule name to apply
-// #### @nc {Boolean} If true - rule will be applied without left-recursion
-// #### check.
-// #### @args {Array} Arguments to rule
-//
-AbstractGrammar.prototype._invoke = function _invoke(grmr, rule, nc, args) {
+// ### function _invoke (grmr, rule, fn, nc, args)
+// #### @grmr {String} name of grammar
+// #### @rule {String} Rule's name
+// #### @fn {Function} Rule's body
+// #### @nc {Boolean} If true - rule will be applied without left-recursion
+// #### check.
+// #### @args {Array} Arguments to rule
+//
+AbstractGrammar.prototype._invoke = function _invoke(grmr, rule, fn, nc, args) {
function invoke() {
+ var body = fn || grmr.prototype[rule];
+
// Nullify result
this._result = undefined;
// Invoke actual rule function
- var fn = grmr.prototype[rule];
- if (fn === undefined) return false;
- return fn.call(this);
+ if (body === undefined) return false;
+ return body.call(this);
}
if (args && args.length > 0) {
@@ -130,9 +132,14 @@ AbstractGrammar.prototype._invoke = function _invoke(grmr, rule, nc, args) {
// ### function rule (name, args)
// #### @name {String} rule name
// #### @args {Array} (optional) arguments
-//
-//
-AbstractGrammar.prototype._rule = function rule(name, nocache, args, cons) {
+// #### @cons {AbstractGrammar}
+// #### @body {Function} rule's body
+//
+AbstractGrammar.prototype._rule = function rule(name,
+ nocache,
+ args,
+ cons,
+ body) {
var res = false;
// `apply` is a meta rule that invokes rule provided in arguments
@@ -160,7 +167,7 @@ AbstractGrammar.prototype._rule = function rule(name, nocache, args, cons) {
} else {
res = this._atomic(function() {
// If not - invoke grammar code first
- if (!this._invoke(cons || this.constructor, name, nocache)) {
+ if (!this._invoke(cons || this.constructor, name, body, nocache)) {
return false;
}
@@ -186,7 +193,7 @@ AbstractGrammar.prototype._rule = function rule(name, nocache, args, cons) {
});
}
} else {
- res = this._invoke(cons || this.constructor, name, nocache, args);
+ res = this._invoke(cons || this.constructor, name, body, nocache, args);
}
if (!res) {
Oops, something went wrong.

0 comments on commit 36ff541

Please sign in to comment.