Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
branch: master
Fetching contributors…

Octocat-spinner-32-eaf2f5

Cannot retrieve contributors at this time

file 36 lines (30 sloc) 1.512 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35
ometa BSNullOptimization {
  setHelped = !($elf._didSomething = true),
  helped = ?$elf._didSomething,
  trans = [:t ?$elf.hasProperty(t) apply(t):ans] -> ans
            | anything,
  optimize = trans:x helped -> x,

  Or trans*:xs -> [#Or].concat(xs),
  And trans*:xs -> [#And].concat(xs),
  Many trans:x -> [#Many, x],
  Many1 trans:x -> [#Many1, x],
  Set :n trans:v -> [#Set, n, v],
  Not trans:x -> [#Not, x],
  Lookahead trans:x -> [#Lookahead, x],
  Form trans:x -> [#Form, x],
  Rule :name :ls trans:body -> [#Rule, name, ls, body]
}
BSNullOptimization.initialize = function() { this._didSomething = false }

ometa BSAndOrOptimization <: BSNullOptimization {
  And trans:x end setHelped -> x,
  And transInside(#And):xs -> [#And].concat(xs),
  Or trans:x end setHelped -> x,
  Or transInside(#Or):xs -> [#Or].concat(xs),

  transInside :t = [exactly(t) transInside(t):xs] transInside(t):ys setHelped -> xs.concat(ys)
                 | trans:x transInside(t):xs -> [x].concat(xs)
                 | -> []
}

ometa BSOMetaOptimizer {
  optimizeGrammar = [#Grammar :n :sn optimizeRule*:rs] -> [#Grammar, n, sn].concat(rs),
  optimizeRule = :r (foreign(BSAndOrOptimization, #optimize, r):r)* -> r
}

Something went wrong with that request. Please try again.