@@ -324,6 +324,8 @@ var NODE_EVAL = 95;
324324var NODE_HEREDOC = 96 ;
325325var NODE_METHOD = 97 ;
326326var NODE_ECHOCONSOLE = 98 ;
327+ var NODE_LSHIFT = 99 ;
328+ var NODE_RSHIFT = 100 ;
327329var TOKEN_EOF = 1 ;
328330var TOKEN_EOL = 2 ;
329331var TOKEN_SPACE = 3 ;
@@ -393,6 +395,8 @@ var TOKEN_BLOB = 66;
393395var TOKEN_LITCOPEN = 67 ;
394396var TOKEN_DOTDOT = 68 ;
395397var TOKEN_HEREDOC = 69 ;
398+ var TOKEN_LSHIFT = 70 ;
399+ var TOKEN_RSHIFT = 71 ;
396400var MAX_FUNC_ARGS = 20 ;
397401function isalpha ( c ) {
398402 return viml_eqregh ( c , "^[A-Za-z]$" ) ;
@@ -2709,6 +2713,10 @@ ExprTokenizer.prototype.get2 = function() {
27092713 r . seek_cur ( 2 ) ;
27102714 return this . token ( TOKEN_GTCS , ">#" , pos ) ;
27112715 }
2716+ else if ( r . p ( 1 ) == ">" ) {
2717+ r . seek_cur ( 2 ) ;
2718+ return this . token ( TOKEN_RSHIFT , ">>" , pos ) ;
2719+ }
27122720 else {
27132721 r . seek_cur ( 1 ) ;
27142722 return this . token ( TOKEN_GT , ">" , pos ) ;
@@ -2723,6 +2731,10 @@ ExprTokenizer.prototype.get2 = function() {
27232731 r . seek_cur ( 2 ) ;
27242732 return this . token ( TOKEN_LTCS , "<#" , pos ) ;
27252733 }
2734+ else if ( r . p ( 1 ) == "<" ) {
2735+ r . seek_cur ( 2 ) ;
2736+ return this . token ( TOKEN_LSHIFT , "<<" , pos ) ;
2737+ }
27262738 else {
27272739 r . seek_cur ( 1 ) ;
27282740 return this . token ( TOKEN_LT , "<" , pos ) ;
@@ -3274,37 +3286,66 @@ ExprParser.prototype.parse_expr4 = function() {
32743286// expr6 . expr6 ..
32753287// expr6 .. expr6 ..
32763288ExprParser . prototype . parse_expr5 = function ( ) {
3277- var left = this . parse_expr6 ( ) ;
3289+ var left = this . parse_expr5_5 ( ) ;
32783290 while ( TRUE ) {
32793291 var pos = this . reader . tell ( ) ;
32803292 var token = this . tokenizer . get ( ) ;
32813293 if ( token . type == TOKEN_PLUS ) {
32823294 var node = Node ( NODE_ADD ) ;
32833295 node . pos = token . pos ;
32843296 node . left = left ;
3285- node . right = this . parse_expr6 ( ) ;
3297+ node . right = this . parse_expr5_5 ( ) ;
32863298 var left = node ;
32873299 }
32883300 else if ( token . type == TOKEN_MINUS ) {
32893301 var node = Node ( NODE_SUBTRACT ) ;
32903302 node . pos = token . pos ;
32913303 node . left = left ;
3292- node . right = this . parse_expr6 ( ) ;
3304+ node . right = this . parse_expr5_5 ( ) ;
32933305 var left = node ;
32943306 }
32953307 else if ( token . type == TOKEN_DOTDOT ) {
32963308 // TODO check scriptversion?
32973309 var node = Node ( NODE_CONCAT ) ;
32983310 node . pos = token . pos ;
32993311 node . left = left ;
3300- node . right = this . parse_expr6 ( ) ;
3312+ node . right = this . parse_expr5_5 ( ) ;
33013313 var left = node ;
33023314 }
33033315 else if ( token . type == TOKEN_DOT ) {
33043316 // TODO check scriptversion?
33053317 var node = Node ( NODE_CONCAT ) ;
33063318 node . pos = token . pos ;
33073319 node . left = left ;
3320+ node . right = this . parse_expr5_5 ( ) ;
3321+ var left = node ;
3322+ }
3323+ else {
3324+ this . reader . seek_set ( pos ) ;
3325+ break ;
3326+ }
3327+ }
3328+ return left ;
3329+ }
3330+
3331+ // expr5_5: expr6 << expr6 ..
3332+ // expr6 >> expr6 ..
3333+ ExprParser . prototype . parse_expr5_5 = function ( ) {
3334+ var left = this . parse_expr6 ( ) ;
3335+ while ( TRUE ) {
3336+ var pos = this . reader . tell ( ) ;
3337+ var token = this . tokenizer . get ( ) ;
3338+ if ( token . type == TOKEN_LSHIFT ) {
3339+ var node = Node ( NODE_LSHIFT ) ;
3340+ node . pos = token . pos ;
3341+ node . left = left ;
3342+ node . right = this . parse_expr6 ( ) ;
3343+ var left = node ;
3344+ }
3345+ else if ( token . type == TOKEN_RSHIFT ) {
3346+ var node = Node ( NODE_RSHIFT ) ;
3347+ node . pos = token . pos ;
3348+ node . left = left ;
33083349 node . right = this . parse_expr6 ( ) ;
33093350 var left = node ;
33103351 }
@@ -4536,6 +4577,12 @@ Compiler.prototype.compile = function(node) {
45364577 else if ( node . type == NODE_REMAINDER ) {
45374578 return this . compile_remainder ( node ) ;
45384579 }
4580+ else if ( node . type == NODE_LSHIFT ) {
4581+ return this . compile_lshift ( node ) ;
4582+ }
4583+ else if ( node . type == NODE_RSHIFT ) {
4584+ return this . compile_rshift ( node ) ;
4585+ }
45394586 else if ( node . type == NODE_NOT ) {
45404587 return this . compile_not ( node ) ;
45414588 }
@@ -5023,6 +5070,14 @@ Compiler.prototype.compile_remainder = function(node) {
50235070 return viml_printf ( "(%% %s %s)" , this . compile ( node . left ) , this . compile ( node . right ) ) ;
50245071}
50255072
5073+ Compiler . prototype . compile_lshift = function ( node ) {
5074+ return viml_printf ( "(<< %s %s)" , this . compile ( node . left ) , this . compile ( node . right ) ) ;
5075+ }
5076+
5077+ Compiler . prototype . compile_rshift = function ( node ) {
5078+ return viml_printf ( "(>> %s %s)" , this . compile ( node . left ) , this . compile ( node . right ) ) ;
5079+ }
5080+
50265081Compiler . prototype . compile_not = function ( node ) {
50275082 return viml_printf ( "(! %s)" , this . compile ( node . left ) ) ;
50285083}
0 commit comments