Browse Source

Fix words being ignored by the lexer in some cases

master
Jake Wakeling 1 month ago
parent
commit
7e36ae1424
  1. 4
      CHANGELOG
  2. 2
      CMakeLists.txt
  3. 28
      src/lex.c
  4. 2
      src/main.c

4
CHANGELOG

@ -1,3 +1,7 @@
0.5.1,
* Implement pipe handling
* Implement redirect handling
0.5.0, 2021-09-11
* Rename OSH to ESH
* Implement --help and --version

2
CMakeLists.txt

@ -1,5 +1,5 @@
CMAKE_MINIMUM_REQUIRED(VERSION 3.12)
PROJECT(ESH VERSION 0.5.0 LANGUAGES C)
PROJECT(ESH VERSION 0.5.1 LANGUAGES C)
SET(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${PROJECT_SOURCE_DIR}/bin)
ADD_COMPILE_DEFINITIONS(PROJECT_VERSION="${PROJECT_VERSION}")

28
src/lex.c

@ -64,23 +64,23 @@ skip:;
if (l->sp == l->sl) { n.k = LK_EOF; goto ret; }
if (C == '\n' || C == ';') { l->sp += 1; n.k = LK_END; goto ret; }
if (C == '#') { for (l->sp += 1; C != '\n'; l->sp += 1) {} goto skip; }
for (n.k = LK_WORD, ss = &C; l->sp != l->sl && C != '\n' && C != ';';) {
if (isspace(C)) { l->sp += 1; break; }
/*
FIXME currently words are ignored if they are immediately followed
by another character such as '|', '<', or '>'
*/
ss = &C; if (l->sp != l->sl && C != '\n' && C != ';') {
switch (C) {
case '\'': { /* TODO */ } break;
case '\"': { /* TODO */ } break;
case '|': { n.k = LK_PIPE; } goto esc_1;
case '<': { n.k = LK_RDIN; } goto esc_1;
case '>': { n.k = LK_ROUT; } goto esc_1;
esc_1: { ss = &C; sl += 1; l->sp += 1; } goto end;
default: { sl += 1; l->sp += 1; } break;
case '|': { n.k = LK_PIPE; } goto esc_1;
case '<': { n.k = LK_RDIN; } goto esc_1;
case '>': { n.k = LK_ROUT; } goto esc_1;
esc_1: { /*ss = &C;*/ sl += 1; l->sp += 1; } goto end;
/* Parse anything else as a word */
default: { n.k = LK_WORD; /*sl += 1; l->sp += 1;*/ } break;
}
for (; l->sp != l->sl && C != '\n' && C != ';' && C != ' ';) {
if (C == '|' || C == '<' || C == '>') { break; }
else { sl += 1; l->sp += 1; }
}
}

2
src/main.c

@ -79,7 +79,7 @@ int main(int ac, char *av[]) { (void)(ac); A0 = av[0];
signal(SIGINT, &reset); signal(SIGTSTP, SIG_IGN); signal(SIGQUIT, SIG_IGN);
if (errno) { warn("%s", serr()); }
eshrc();
if (!Lflag) { eshrc(); }
do {
if (sigsetjmp(jmp, 1)) { fputc('\n', stdout); } jmpflag = true;

Loading…
Cancel
Save