From e9ff1c6fbbbac9ece2604876ab589ac282360446 Mon Sep 17 00:00:00 2001 From: Nicholas Date: Mon, 15 Nov 2021 15:08:03 -0800 Subject: Feat: added if/else branching and switch statement Unsure about my modification to the language. I found the parsing of the case body within switches to be odd - specifically that it parses liberally and then checks that it has case -> cmd structuring while it walks the code. This means the language is more permissive than the semantics. I modified it to be more explicit, but at the cost of having to end each case statement with a semicolon. I wanted a colon, but this is a valid word character and thus will be lexed as part of the word. --- src/cmd/rc/lex.c | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) (limited to 'src/cmd/rc/lex.c') diff --git a/src/cmd/rc/lex.c b/src/cmd/rc/lex.c index 9ca2453..3722606 100644 --- a/src/cmd/rc/lex.c +++ b/src/cmd/rc/lex.c @@ -142,8 +142,7 @@ putbyte(char *buf, int c) return buf; } -static -char * +static char * putrune(char *buf, int c) { buf = putbyte(buf, c); @@ -184,7 +183,7 @@ isidentchar(int c) int yylex(void) { - int c, d = peekc(); + int c, d = peekc(); Tree *node; char *w = lexer.buf; @@ -369,8 +368,15 @@ yylex(void) } for(;;){ - w = putrune(w, c); - c = peekc(); + switch(c){ + /* inject a magic glob character into our stream */ + case '*': case '[': case '?': case (int)GLOB: + w = putbyte(w, GLOB); + /* fallthrough */ + default: + w = putrune(w, c); + c = peekc(); + } if(lexer.haddollar ? !isidentchar(c) : !iswordchar(c)) break; advance(); -- cgit v1.2.1