rsc | b2ad2ef | 2005-01-04 22:30:59 +0000 | [diff] [blame] | 1 | /* Make this with: lex delatex.lex; cc lex.yy.c -ll -o delatex */ |
| 2 | L [A-Za-z] |
rsc | b8e710d | 2005-01-30 16:48:14 +0000 | [diff] [blame] | 3 | %Start Display Math Normal Tag VerbPlus Bracket |
rsc | b2ad2ef | 2005-01-04 22:30:59 +0000 | [diff] [blame] | 4 | %% |
| 5 | <Normal>\' {yyleng--; yymore(); /* ignore apostrophes */} |
| 6 | <Normal>{L}+\\- {yyleng-=2; yymore(); /* ignore hyphens */} |
rsc | b8e710d | 2005-01-30 16:48:14 +0000 | [diff] [blame] | 7 | <Normal>[a-zA-Z0-9_]+@[a-zA-Z0-9_.]+ ; /* ignore email addresses */ |
rsc | b2ad2ef | 2005-01-04 22:30:59 +0000 | [diff] [blame] | 8 | <Normal>[a-z]/[^A-Za-z] ; /* ignore single letter "words" */ |
| 9 | <Normal>[A-Z]+ ; /* ignore words all in uppercase */ |
| 10 | <Normal>{L}+('{L}*)*{L} {printf("%s\n",yytext); /* any other letter seq is a word */} |
| 11 | <Normal>"%".* ; /* ignore comments */ |
| 12 | <Normal>\\{L}+ ; /* ignore other control sequences */ |
| 13 | <Normal>"\\begin{" BEGIN Tag; /* ignore this and up to next "}" */ |
| 14 | <Normal>"\\bibitem{" BEGIN Tag; |
| 15 | <Normal>"\\bibliography{" BEGIN Tag; |
| 16 | <Normal>"\\bibstyle{" BEGIN Tag; |
| 17 | <Normal>"\\cite{" BEGIN Tag; |
| 18 | <Normal>"\\end{" BEGIN Tag; |
| 19 | <Normal>"\\include{" BEGIN Tag; |
| 20 | <Normal>"\\includeonly{" BEGIN Tag; |
| 21 | <Normal>"\\input{" BEGIN Tag; |
| 22 | <Normal>"\\label{" BEGIN Tag; |
| 23 | <Normal>"\\pageref{" BEGIN Tag; |
| 24 | <Normal>"\\ref{" BEGIN Tag; |
rsc | b8e710d | 2005-01-30 16:48:14 +0000 | [diff] [blame] | 25 | <Normal>"\\verb+" BEGIN VerbPlus; |
| 26 | <Normal>"\\documentclass[" BEGIN Bracket; |
| 27 | <Normal>"\\documentclass{" BEGIN Tag; |
| 28 | <Normal>"\\usepackage[" BEGIN Bracket; |
| 29 | <Normal>"\\usepackage{" BEGIN Tag; |
| 30 | <Bracket>[^\]] ; |
| 31 | <Bracket>"][" ; |
| 32 | <Bracket>"]{" BEGIN Tag; |
| 33 | <Bracket>"]" BEGIN Normal; |
rsc | b2ad2ef | 2005-01-04 22:30:59 +0000 | [diff] [blame] | 34 | <Tag>[^}] ; /* ignore things up to next "}" */ |
| 35 | <Tag>"}" BEGIN Normal; |
rsc | b8e710d | 2005-01-30 16:48:14 +0000 | [diff] [blame] | 36 | <VerbPlus>[^+] ; /* ignore thing up to next "+" */ |
| 37 | <VerbPlus>"+" BEGIN Normal; |
rsc | b2ad2ef | 2005-01-04 22:30:59 +0000 | [diff] [blame] | 38 | <Normal>[0-9]+ ; /* ignore numbers */ |
| 39 | <Normal>"\\(" BEGIN Math; /* begin latex math mode */ |
| 40 | <Math>"\\)" BEGIN Normal; /* end latex math mode */ |
| 41 | <Math>.|\\[^)]|\n ; /* ignore anything else in latex math mode */ |
| 42 | <Normal>"\\[" BEGIN Display; /* now in Latex display mode */ |
| 43 | <Display>[^$]|\\[^\]] ; /* ignore most things in display math mode */ |
| 44 | <Display>"\\]" BEGIN Normal; /* get out of Display math mode */ |
| 45 | <Normal>\\. ; /* ignore other single character control sequences */ |
| 46 | <Normal>\\\n ; /* more of the same */ |
| 47 | <Normal>\n|. ; /* ignore anything else, a character at a time */ |
| 48 | %% |
| 49 | #include <stdio.h> |
| 50 | #include <stdlib.h> |
| 51 | |
| 52 | int |
| 53 | main(int argc, char **argv) |
| 54 | { |
| 55 | int i; |
| 56 | |
| 57 | BEGIN Normal; /* Starts yylex off in the right state */ |
| 58 | if (argc==1) { |
| 59 | yyin = stdin; |
| 60 | yylex(); |
| 61 | } |
| 62 | else for (i=1; i<argc; i++) { |
| 63 | yyin = fopen(argv[i],"r"); |
| 64 | if (yyin==NULL) { |
| 65 | fprintf(stderr,"can't open %s\n",argv[i]); |
| 66 | exit(1); |
| 67 | } |
| 68 | yylex(); |
| 69 | } |
| 70 | exit(0); |
| 71 | } |
| 72 | int |
| 73 | yywrap(void) |
| 74 | { |
| 75 | return 1; |
| 76 | } |