Browse code

Support nested comments in asma too.

Andrew Alderwick authored on 29/12/2021 11:59:20
Showing 3 changed files
... ...
@@ -89,7 +89,8 @@ do
89 89
     ['}'] = 'asma-macro-end'
90 90
   })
91 91
   process('asma-first-char-comment', {
92
-    [')'] = 'asma-comment-end'
92
+    ['('] = 'asma-comment-more',
93
+    [')'] = 'asma-comment-less'
93 94
   })
94 95
 end
95 96
 local traverse_node
... ...
@@ -87,7 +87,8 @@ do -- first characters
87 87
 		'{': 'asma-ignore'
88 88
 		'}': 'asma-macro-end'
89 89
 	process 'asma-first-char-comment',
90
-		')': 'asma-comment-end'
90
+		'(': 'asma-comment-more'
91
+		')': 'asma-comment-less'
91 92
 
92 93
 traverse_node = (t, min, max, lefts, rights) ->
93 94
 	i = math.ceil (min + max) / 2
... ...
@@ -347,6 +347,7 @@
347 347
 
348 348
 @asma [
349 349
 	&pass $1 &state $1 &line $2 &lines $2 &break $1 &eof $1
350
+	&comment-level $1
350 351
 	&token $2 &orig-token $2 &lit $1 &lit-present $1
351 352
 	&addr $2 &written-addr $2 &flush-fn $2
352 353
 	&src-filename $2 &dest-filename $2
... ...
@@ -610,11 +611,17 @@
610 611
 %asma-STATE-SET { ;asma/state LDA ORA ;asma/state STA }
611 612
 %asma-STATE-CLEAR { #ff EOR ;asma/state LDA AND ;asma/state STA }
612 613
 
614
+@asma-comment-more
615
+	;asma/token LDA2 ;strlen JSR2 ORA ,asma-ignore JCN
613 616
 @asma-comment-start
617
+	;asma/comment-level LDAk INC ROT ROT STA
614 618
 	#02 asma-STATE-SET
615 619
 @asma-ignore
616 620
 	JMP2r
617 621
 
622
+@asma-comment-less
623
+	;asma/token LDA2 ;strlen JSR2 ORA ,asma-ignore JCN
624
+	;asma/comment-level LDAk #01 SUB DUP SWP2 STA ,asma-ignore JCN
618 625
 @asma-comment-end
619 626
 	#02 asma-STATE-CLEAR
620 627
 	JMP2r
... ...
@@ -908,7 +915,8 @@
908 915
 	            than       than         string         data )
909 916
 
910 917
 @asma-first-char-comment
911
-	&_entry      $2         $2          ') 00          :asma-comment-end
918
+	&28          $2         $2          '( 00          :asma-comment-more
919
+	&_entry     :&28        $2          ') 00          :asma-comment-less
912 920
 
913 921
 @asma-first-char-macro
914 922
 	&28          $2         $2          '( 00          :asma-comment-start