diff options
Diffstat (limited to 'src/hyper/lex.c')
-rw-r--r-- | src/hyper/lex.c | 258 |
1 files changed, 252 insertions, 6 deletions
diff --git a/src/hyper/lex.c b/src/hyper/lex.c index ad6f6672..16ec3230 100644 --- a/src/hyper/lex.c +++ b/src/hyper/lex.c @@ -66,29 +66,30 @@ int useAscii; #define PARSER 1 -#include "hyper.h" -#include "hterror.h" #include "halloc.h" -#include "sockio.h" #include "lex.h" - +#include "node.h" #include <ctype.h> #include <setjmp.h> +#include <stdlib.h> static int get_char1(void ); static void spad_error_handler(void ); static int keyword_type(void ); extern int gTtFontIs850; +extern HDWindow *gWindow; + StateNode *top_state_node; HyperDocPage *gPageBeingParsed; /* page currently being parsed */ -extern jmp_buf jmpbuf; -extern char ebuffer[]; +jmp_buf jmpbuf; +char ebuffer[128]; short int gInSpadsrc = 0; short int gInVerbatim; +openaxiom_sio* spad_socket; /* Parser variables */ long fpos; /* Position of pointer in file in characters */ @@ -112,6 +113,108 @@ char sock_buf[1024]; /* buffer for socket input */ static HashTable tokenHashTable; /* hash table of parser tokens */ +char* token_table[] = { + "", /* Dummy token name */ + "word", + "page", + "lispcommandquit", + "bf", + "link", + "downlink", + "beginscroll", + "spadcommand", + "nolines", + "env", + "par", + "centerline", + "begin", + "beginitems", + "item", + "table", + "fbox", + "tab", + "space", + "indent", + "horizontalline", + "newline", + "enditems", + "returnbutton", + "memolink", + "upbutton", + "endscroll", + "thispage", + "returnto", + "free", + "bound", + "lisplink", + "unixlink", + "mbox", + "inputstring", + "stringvalue", + "spadlink", + "inputbitmap", + "inputpixmap", + "unixcommand", + "em", + "lispcommand", + "lispmemolink", + "lispdownlink", + "spadcall", + "spadcallquit", + "spaddownlink", + "spadmemolink", + "qspadcall", + "qspadcallquit", + "inputbox", + "radioboxes", + "boxvalue", + "vspace", + "hspace", + "newcommand", + "windowid", + "beep", + "quitbutton", + "begintitems", + "titem", + "end", + "it", + "sl", + "tt", + "rm", + "ifcond", + "else", + "fi", + "newcond", + "setcond" , + "button", + "windowlink", + "haslisp", + "hasup", + "hasreturn", + "hasreturnto", + "lastwindow", + "endtitems", + "lispwindowlink", + "beginpile", + "endpile", + "nextline", + "pastebutton", + "color", + "helppage", + "patch", + "radiobox", + "ifrecond", + "math", + "mitem", + "pagename", + "examplenumber", + "replacepage", + "inputimage", + "spadgraph", + "indentrel", + "controlbitmap" + }; + void dumpToken(char *caller, Token t) { fprintf(stderr,"%s:dumpToken type=%s id=%s\n", @@ -534,6 +637,15 @@ typedef struct be_struct { BeStruct *top_be_stack; +void +jump(void) +{ + if (gWindow == NULL) + exit(-1); + longjmp(jmpbuf, 1); + fprintf(stderr, "(HyperDoc) Long Jump failed, Exiting\n"); + exit(-1); +} void push_be_stack(int type, const char* id) @@ -748,6 +860,140 @@ end_type(void) } +void +token_name(int type) +{ + if (type <= NumberUserTokens) + strcpy(ebuffer, token_table[type]); + else { + switch (type) { + case Lbrace: + strcpy(ebuffer, "{"); + break; + case Rbrace: + strcpy(ebuffer, "}"); + break; + case Macro: + strcpy(ebuffer, token.id); + break; + case Group: + strcpy(ebuffer, "{"); + break; + case Pound: + strcpy(ebuffer, "#"); + break; + case Lsquarebrace: + strcpy(ebuffer, "["); + break; + case Rsquarebrace: + strcpy(ebuffer, "]"); + break; + case Punctuation: + strcpy(ebuffer, token.id); + break; + case Dash: + strcpy(ebuffer, token.id); + break; + case Verbatim: + strcpy(ebuffer, "\\begin{verbatim}"); + break; + case Scroll: + strcpy(ebuffer, "\\begin{scroll}"); + break; + case Dollar: + strcpy(ebuffer, "$"); + break; + case Percent: + strcpy(ebuffer, "%"); + break; + case Carrot: + strcpy(ebuffer, "^"); + break; + case Underscore: + strcpy(ebuffer, "_"); + break; + case Tilde: + strcpy(ebuffer, "~"); + break; + case Cond: + sprintf(ebuffer, "\\%s", token.id); + break; + case Icorrection: + strcpy(ebuffer, "\\/"); + break; + case Paste: + strcpy(ebuffer, "\\begin{paste}"); + break; + case Patch: + strcpy(ebuffer, "\\begin{patch}"); + break; + default: + sprintf(ebuffer, " %d ", type); + } + /*return 1;*/ + } +} + + +/* print out a token value */ +void +print_token(void) +{ + if (token.type == Word) + printf("%s ", token.id); + else { + token_name(token.type); + printf("\\%s ", ebuffer); + } + fflush(stdout); +} + +void +print_next_ten_tokens(void) +{ + int i; + int v; + + fprintf(stderr, "Trying to print the next ten tokens\n"); + for (i = 0; i < 10; i++) { + v = get_token(); + if (v == EOF) + break; + print_token(); + } + fprintf(stderr, "\n"); +} + +void +print_page_and_filename(void) +{ + char obuff[128]; + + if (gPageBeingParsed->type == Normal) { + + /* + * Now try to inform the user as close to possible where the error + * occurred + */ + sprintf(obuff, "(HyperDoc) While parsing %s on line %d\n\tin the file %s\n", + gPageBeingParsed->name, line_number, + gPageBeingParsed->filename); + } + else if (gPageBeingParsed->type == SpadGen) { + sprintf(obuff, "While parsing %s from the Spad socket\n", + gPageBeingParsed->name); + } + else if (gPageBeingParsed->type == Unixfd) { + sprintf(obuff, "While parsing %s from a Unixpipe\n", + gPageBeingParsed->name); + } + else { + /* Unknown page type */ + sprintf(obuff, "While parsing %s\n", gPageBeingParsed->name); + } + fprintf(stderr, "%s", obuff); +} + static int keyword_type(void) |