]> gitweb.factorcode.org Git - factor.git/commitdiff
fjsc: allow comments with ! and #!
authorchris.double <chris.double@double.co.nz>
Fri, 15 Dec 2006 08:11:07 +0000 (08:11 +0000)
committerchris.double <chris.double@double.co.nz>
Fri, 15 Dec 2006 08:11:07 +0000 (08:11 +0000)
libs/fjsc/fjsc.factor

index 3eff68104edff85c5cf6eca696f7023b41d7cefd..b5aa33317da99a3ba91a9ae1dd5d4e8c8c1b769a 100644 (file)
@@ -13,6 +13,7 @@ TUPLE: ast-define name expression ;
 TUPLE: ast-expression values ;
 TUPLE: ast-word value ;
 TUPLE: ast-alien return method args ;
+TUPLE: ast-comment ;
 
 LAZY: 'digit' ( -- parser )
   [ digit? ] satisfy [ digit> ] <@ ;
@@ -92,8 +93,15 @@ LAZY: 'alien' ( -- parser )
   'array' [ ast-array-elements ast-expression-values [ ast-string-value ] map ] <@ <:&>
   "alien-invoke" token sp <& [ first3 <ast-alien> ] <@ ;
 
+LAZY: 'comment' ( -- parser )
+  "#!" token sp
+  "!" token sp <|> [
+    dup CHAR: \n = swap CHAR: \r = or not
+  ] satisfy <*> <&> [ drop <ast-comment> ] <@ ;
+
 LAZY: 'expression' ( -- parser )
-  'define' sp 
+  'comment' 
+  'define' sp <|>
   'word' sp <|>
   'alien' sp <|>
   'atom' sp <|> 
@@ -189,6 +197,9 @@ M: ast-word (compile)
   (literal)
   ")" , ;
   
+M: ast-comment (compile)
+  drop "/* */" , ;
+
 : fjsc-compile ( ast -- string )
   [
     [ (compile) ] { } make [ write ] each