Inlined create_rule
This commit is contained in:
parent
73e9ebcfdd
commit
05e620bac5
22
src/modal.c
22
src/modal.c
|
@ -168,15 +168,6 @@ parse_frag(char *s)
|
||||||
return s;
|
return s;
|
||||||
}
|
}
|
||||||
|
|
||||||
static char *
|
|
||||||
create_rule(Rule *r, int id, char *s)
|
|
||||||
{
|
|
||||||
r->id = id, s += 2;
|
|
||||||
r->a = dict_, s = parse_frag(s);
|
|
||||||
r->b = dict_, s = parse_frag(s);
|
|
||||||
return s;
|
|
||||||
}
|
|
||||||
|
|
||||||
static int
|
static int
|
||||||
rewrite(void)
|
rewrite(void)
|
||||||
{
|
{
|
||||||
|
@ -186,14 +177,17 @@ rewrite(void)
|
||||||
if(spacer(last)) {
|
if(spacer(last)) {
|
||||||
Rule *r;
|
Rule *r;
|
||||||
if(c == '<' && s[1] == '>') {
|
if(c == '<' && s[1] == '>') {
|
||||||
r = rules_++;
|
r = rules_++, r->id = rules_ - rules - 1;
|
||||||
s = create_rule(r, rules_ - rules - 1, s);
|
r->a = dict_, s = parse_frag(s + 2);
|
||||||
|
r->b = dict_, s = parse_frag(s);
|
||||||
while(*s == ' ') s++;
|
while(*s == ' ') s++;
|
||||||
return commit_rule(r, s, 1);
|
return commit_rule(r, s, 1);
|
||||||
}
|
}
|
||||||
if(c == '?' && s[1] == '(') {
|
if(c == '?' && s[1] == '(') {
|
||||||
r = &lambda, cap = walk(s + 1);
|
cap = walk(s + 1);
|
||||||
create_rule(&lambda, -1, s), s = cap;
|
r = &lambda, r->id = -1;
|
||||||
|
r->a = dict_, s = parse_frag(s + 2);
|
||||||
|
r->b = dict_, parse_frag(s), s = cap;
|
||||||
while(*s == ' ') s++;
|
while(*s == ' ') s++;
|
||||||
if((res = match_rule(&lambda, s)) != NULL)
|
if((res = match_rule(&lambda, s)) != NULL)
|
||||||
return write_rule(&lambda, res);
|
return write_rule(&lambda, res);
|
||||||
|
@ -219,7 +213,7 @@ main(int argc, char **argv)
|
||||||
return !printf("usage: modal [-vqn] source.modal\n");
|
return !printf("usage: modal [-vqn] source.modal\n");
|
||||||
for(i = 1; i < argc && *argv[i] == '-'; i++) {
|
for(i = 1; i < argc && *argv[i] == '-'; i++) {
|
||||||
switch(argv[i][1]) {
|
switch(argv[i][1]) {
|
||||||
case 'v': /* version */ return !printf("Modal Interpreter, 20 Apr 2024.\n");
|
case 'v': /* version */ return !printf("Modal Interpreter, 21 Apr 2024.\n");
|
||||||
case 'q': /* quiet */ fclose(stderr); break;
|
case 'q': /* quiet */ fclose(stderr); break;
|
||||||
case 'n': /* infinite */ cycles = 0xffffffff; break;
|
case 'n': /* infinite */ cycles = 0xffffffff; break;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue