Browse files

Merged alex's commit 43c6a74 [ JS RE /../gim support ]

  • Loading branch information...
1 parent 97c5da8 commit aefb8c2901cb249bbe3535882d335af607124c98 @tristanls committed Jul 2, 2011
Showing with 15 additions and 1 deletion.
  1. +15 −1 node_modules/ometajsnode/lib/bs-js-compiler.ometajs
View
16 node_modules/ometajsnode/lib/bs-js-compiler.ometajs
@@ -22,11 +22,23 @@ ometa BSJSParser {
| '+' | ``--'' | ``-='' | '-' | ``*='' | '*' | ``/=''
| '/' | ``%='' | '%' | ``&&='' | ``&&'' | ``||='' | ``||''
| '.' | '!' ):s -> [s, s],
- tok = spaces (name | keyword | number | str | special),
+ tok = spaces (name | keyword | number | str | rexp | special),
toks = token*:ts spaces end -> ts,
token :tt = tok:t ?(t[0] == tt) -> t[1],
spacesNoNl = (~'\n' space)*,
+ rexp = '/' rexpBody:x '/' rexpFlag*:y -> [#rexp, '/' + x + '/' + y.join('')],
+ rexpFlag = 'g' | 'i' | 'm',
+ rexpBody = rexpFChar:x rexpChar*:y -> (x + y.join('')),
+ rexpFChar = ~'*' rexpChar,
+ rexpChar = ~'\\' ~'/' ~'[' rexpNoTerm
+ | escapeChar
+ | rexpClass,
+ rexpNoTerm = ~'\n' ~'\r' char,
+ rexpClass = '[' rexpClChar*:x ']' -> ('[' + x.join('') + ']'),
+ rexpClChar = ~']' ~'\\' rexpNoTerm
+ | escapeChar,
+
expr = orExpr:e ( "?" expr:t ":" expr:f -> [#condExpr, e, t, f]
| "=" expr:rhs -> [#set, e, rhs]
| "+=" expr:rhs -> [#mset, e, "+", rhs]
@@ -101,6 +113,7 @@ ometa BSJSParser {
| empty -> [#get, 'undefined'] ):v -> [#var, n, v],
block = "{" srcElems:ss "}" -> ss,
stmt = block
+ | rexp
| "var" listOf(#binding, ','):bs sc -> [#begin].concat(bs)
| "if" "(" expr:c ")" stmt:t ( "else" stmt
| empty -> [#get, 'undefined'] ):f -> [#if, c, t, f]
@@ -170,6 +183,7 @@ ometa BSJSTranslator {
continue -> 'continue',
number :n -> ('(' + n + ')'),
string :s -> s.toProgramString(),
+ rexp :x -> x,
arr trans*:xs -> ('[' + xs.join(',') + ']'),
unop :op trans:x -> ('(' + op + ' ' + x + ')'),
getp trans:fd trans:x -> (x + '[' + fd + ']'),

0 comments on commit aefb8c2

Please sign in to comment.