mirror of
https://git.sr.ht/~rabbits/uxn
synced 2024-11-26 15:53:01 +00:00
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
1 changed files with 7 additions and 2 deletions
|
@ -243,8 +243,13 @@ parse(char *w, FILE *f)
|
|||
return error("Invalid token", w);
|
||||
switch(w[0]) {
|
||||
case '(': /* comment */
|
||||
while(fscanf(f, "%63s", word) == 1)
|
||||
if(word[0] == ')') break;
|
||||
if(slen(w) != 1) fprintf(stderr, "-- Malformed comment: %s\n", w);
|
||||
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;
|
||||
case '~': /* include */
|
||||
if(!doinclude(w + 1))
|
||||
|
|
Loading…
Reference in a new issue