Housekeeping
This commit is contained in:
parent
5f70f09ce3
commit
50424f4d0c
32
src/modal.c
32
src/modal.c
|
@ -129,6 +129,19 @@ commit_rule(Rule *r, char *s, int create)
|
|||
return 1;
|
||||
}
|
||||
|
||||
static int
|
||||
write_rule(Rule *r, char last, char *res)
|
||||
{
|
||||
char cc, *b = r->b;
|
||||
if(!*b && last == ' ') outp_--;
|
||||
while((cc = *b++))
|
||||
if(cc == '?')
|
||||
put_reg(*b++);
|
||||
else
|
||||
*outp_++ = cc;
|
||||
return commit_rule(r, res, 0);
|
||||
}
|
||||
|
||||
static char *
|
||||
parse_frag(char *s)
|
||||
{
|
||||
|
@ -142,19 +155,6 @@ parse_frag(char *s)
|
|||
return s;
|
||||
}
|
||||
|
||||
static int
|
||||
write(Rule *r, char last, char *res)
|
||||
{
|
||||
char cc, *b = r->b;
|
||||
if(!*b && last == ' ') outp_--;
|
||||
while((cc = *b++))
|
||||
if(cc == '?')
|
||||
put_reg(*b++);
|
||||
else
|
||||
*outp_++ = cc;
|
||||
return commit_rule(r, res, 0);
|
||||
}
|
||||
|
||||
static char *
|
||||
create_rule(Rule *r, int id, char *s)
|
||||
{
|
||||
|
@ -182,11 +182,11 @@ rewrite(void)
|
|||
r = λ
|
||||
p = create_rule(&lambda, -1, p) + 1;
|
||||
if((res = match_rule(&lambda, p)) != NULL)
|
||||
return write(&lambda, last, res);
|
||||
return write_rule(&lambda, last, res);
|
||||
}
|
||||
for(r = rules; r < rules_; r++)
|
||||
if((res = match_rule(r, p)) != NULL)
|
||||
return write(r, last, res);
|
||||
return write_rule(r, last, res);
|
||||
}
|
||||
*outp_++ = last = c;
|
||||
p++;
|
||||
|
@ -203,7 +203,7 @@ main(int argc, char **argv)
|
|||
if(argc < 2)
|
||||
return !printf("usage: modal [-v] source.modal\n");
|
||||
if(argc < 3 && argv[1][0] == '-' && argv[1][1] == 'v')
|
||||
return !printf("Modal Interpreter, 10 Apr 2024.\n");
|
||||
return !printf("Modal Interpreter, 11 Apr 2024.\n");
|
||||
if(!(f = fopen(argv[1], "r")))
|
||||
return !printf("Invalid Modal file: %s.\n", argv[1]);
|
||||
while(fread(&c, 1, 1, f)) {
|
||||
|
|
Loading…
Reference in New Issue