http://lively-web.org/users/ohshima/GPMassager.ometa
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
save
load
remove
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
ometa GPMassager {
infixOp =
  ['SYMBOL'
    ('+=' | '+' | '-' | '*' | '/' | '%' | '===' | '<<' | '>>>' | '>>' | '<=' | '<' | 
'==' | '!=' | '>=' | '>' | '&' | '|' | '^' | '='):c]
       -> c,
name =
  [('CONST' | 'SYMBOL') anything:n ?[n.constructor == String]]  -> n,
trans =
  ['LIST'  
    (
      ['SYMBOL' 'to'] name:n name*:fs trans:b
      {['TO', n, fs, [], b]}:tmp
      GPLocalVarFinder.start(tmp):locals
        -> (function() {tmp[3] = locals; return tmp})()
    | ['SYMBOL' 'method'] name:c name:n name*:fs trans:b
      {['METHOD', c, n, fs, [], b]}:tmp
      GPLocalVarFinder.start(tmp):locals
        -> (function() {tmp[4] = locals; return tmp})()
    | ['SYMBOL' 'function'] name*:fs trans:b
      {['FUNCTION', fs, [], b]}:tmp
      GPLocalVarFinder.start(tmp):locals
        -> (function() {tmp[2] = locals; return tmp})()
    | ['SYMBOL' 'for'] name:n trans*:bs
        -> ['FOR', n].concat(bs)
    | ['SYMBOL' 'repeat'] trans:l trans:b
        -> ['REPEAT', l, b]
    | ['SYMBOL' 'while'] trans:l trans:b
        -> ['WHILE', l, b]
    | ['SYMBOL' 'if'] trans*:bs
        -> ['IF'].concat(bs)
    | name:n ['SYMBOL' ('=' | '+='):op] trans:b
        -> ['SETVAR', n,  op, b]
    | trans:a infixOp:op trans:b
    -> ['REPORTER', op, a, b]
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
http://lively-web.org/users/ohshima/GPMassager.ometa
X

Menu
// changed at Fri Feb 27 2015 14:32:29 GMT-0800 (PST) by bert
this.addScript(function reset() {
    this.partsBinMetaInfo.requiredModules = [
        "users.ohshima.GPParser",
        "users.ohshima.GPMassager",
        "users.ohshima.GPLocalVarFinder",
    ];
});
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
<lively.morphic.Box#DAF39... - GP>
Tag:
run
save
Tests

-- ALL --
reset
Scripts
-
+
-
Connections
+
-- ALL --
all
ObjectEditor -- GP>>reset
X

Menu
depth: 1
reset
var tree = GPParser.matchAll('3 + 4', 'topLevelCmd');
GPMassager.match(tree, 'trans')
`foo
bar`
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
show vars
JavaScript Workspace
X

Menu
GPParser.ometa
X

Menu
N

...
ElectricalCircuitTests.js (not parsed)
ElectricalComponents.js (not parsed)
ElectricalComponentsTests.js (not parsed)
experiments.js (not parsed)
FormulaHolder.js (not parsed)
GPLocalVarFinder.js (not parsed)
GPLocalVarFinder.ometa (not parsed)
GPMassager.js (not parsed)
GPMassager.ometa
GPParser.js (not parsed)
GPParser.ometa
TileExtractor.js (not parsed)
GPParser
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
   cmd :spacer =
    (apply(spacer) value)+:rs apply(spacer) -> ["LIST"].concat(rs),
   cmdList =
    "{" nl? (cmd("noNL"):c (nl | &"}") -> c)*:cs "}" -> ["SEQ"].concat(cs),
   nl = char:c ?{c == "\n" || c == "\r"}
      | end,
   noNL =
    (char:c ?{c != "\n" && c != "\r" && c.charCodeAt(0) <= " ".charCodeAt(0)})*,
 number =
    < "-"? digit+ ("." digit+)? >:ds    -> ["CONST", parseFloat(ds)],
  string =
    "'" ((&("'" "'") char char -> "'") | ~"'" char)*:cs "'" -> ["CONST", "".concat.apply("", cs)],
  symbol =
    < anyChar+>:c -> ["SYMBOL", c],
topLevelCmd =
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
>
<