Support nested comments in uxnasm.
Previously, code like this would fail with an error about an unrecognized ) token: ( this is a ( nested ) comment ) With this patch, the above code will now work. Relatedly, it was previously possible to write code that compiled but was confusing: (open parenthesis should have a space ) ( in this case the ADD2 will be ignored )ADD2 ( this comment with ( would have been fine ) With this commit, the first example will emit a warning but continue to work as intended. The second and third examples will continue searching for a matching ) token, which due to the new nested coment behavior will probably mean the rest of the file gets commented out.
This commit is contained in:
parent
55f448fb77
commit
abd6a3a5da
|
@ -243,8 +243,13 @@ parse(char *w, FILE *f)
|
||||||
return error("Invalid token", w);
|
return error("Invalid token", w);
|
||||||
switch(w[0]) {
|
switch(w[0]) {
|
||||||
case '(': /* comment */
|
case '(': /* comment */
|
||||||
while(fscanf(f, "%63s", word) == 1)
|
if(slen(w) != 1) fprintf(stderr, "-- Malformed comment: %s\n", w);
|
||||||
if(word[0] == ')') break;
|
i = 1; /* track nested comment depth */
|
||||||
|
while(fscanf(f, "%63s", word) == 1) {
|
||||||
|
if(slen(word) != 1) continue;
|
||||||
|
else if(word[0] == '(') i++;
|
||||||
|
else if(word[0] == ')' && --i < 1) break;
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
case '~': /* include */
|
case '~': /* include */
|
||||||
if(!doinclude(w + 1))
|
if(!doinclude(w + 1))
|
||||||
|
|
Loading…
Reference in New Issue