diff options
author | Karl Berry <karl@freefriends.org> | 2010-06-14 23:14:16 +0000 |
---|---|---|
committer | Karl Berry <karl@freefriends.org> | 2010-06-14 23:14:16 +0000 |
commit | c2175edc7aa44ca0b526f008d473d6f8a8ac4933 (patch) | |
tree | d6c491676b413ad1922481f8c3fc7b64c3afc0a5 /Build/source/utils/asymptote/camp.l | |
parent | 5d08e9ff4fe5fc836d237ea08e82c82b27d558a2 (diff) |
asy 1.98
git-svn-id: svn://tug.org/texlive/trunk@18982 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Build/source/utils/asymptote/camp.l')
-rw-r--r-- | Build/source/utils/asymptote/camp.l | 64 |
1 files changed, 35 insertions, 29 deletions
diff --git a/Build/source/utils/asymptote/camp.l b/Build/source/utils/asymptote/camp.l index 477a6d32a2d..4e6f3b23bf2 100644 --- a/Build/source/utils/asymptote/camp.l +++ b/Build/source/utils/asymptote/camp.l @@ -9,6 +9,7 @@ #include <iostream> #include <fstream> #include <sstream> +#include <cstring> #include "util.h" #include "modifier.h" @@ -83,7 +84,7 @@ void adjust() yylval.pos = here(); } -void savesymbol(symbol *name) +void savesymbol(symbol name) { adjust(); yylval.ps.pos=here(); @@ -101,20 +102,15 @@ void savesymbol(symbol *name) #define DEFSYMBOL(name) \ savesymbol(name) -void makesymbol(bool op=true, string text = yytext) +void makesymbol() { - // TODO: Refactor to a call to savesymbol. - adjust(); - yylval.ps.pos=here(); - yylval.ps.sym=op ? symbol::opTrans(text) : symbol::literalTrans(text); + assert(strlen(yytext) == (size_t)yyleng); + savesymbol(symbol::rawTrans(yytext, yyleng+1)); } -void makeselfsymbol(bool op=true, string text = yytext) +void makeopsymbol() { - /* Copy all but the last digit, which should be an =. */ - assert(text[text.length()-1] == '='); - text.erase(text.length()-1); - makesymbol(op,text); + savesymbol(symbol::opTrans(yytext)); } void makemod(trans::modifier mod) { @@ -165,9 +161,16 @@ void reportEOF() { em.sync(); } -string stringbuild; +position stringpos; // The position of the start of the string. +string stringbuild; // Stores the string literal as it is read. namespace { +void startstring() +{ + adjust(); + stringpos = here(); +} + void append(char c) { stringbuild.push_back(c); @@ -177,7 +180,7 @@ void append(char c) void getstring(void) { // NOTE: Replace here() with a position at the start of the string. - makesymbol(false,stringbuild); + yylval.stre = new stringExp(stringpos, stringbuild); string().swap(stringbuild); } } @@ -323,14 +326,14 @@ EXTRAOPS <<|>>|$|$$|@|@@|~ "---" {DEFSYMBOL(SYM_LONGDASH); return LONGDASH; } "&" {DEFSYMBOL(SYM_AMPERSAND); return AMPERSAND; } "|" {DEFSYMBOL(SYM_BAR); return BAR; } -{EXTRAOPS} {makesymbol(); return OPERATOR; } +{EXTRAOPS} {makeopsymbol(); return OPERATOR; } -"+=" {makeselfsymbol(); return ADD; } -"-=" {makeselfsymbol(); return SUBTRACT; } -"*=" {makeselfsymbol(); return TIMES; } -"/=" {makeselfsymbol(); return DIVIDE; } -"%=" {makeselfsymbol(); return MOD; } -"^=" {makeselfsymbol(); return EXPONENT; } +"+=" {savesymbol(SYM_PLUS); return SELFOP; } +"-=" {savesymbol(SYM_MINUS); return SELFOP; } +"*=" {savesymbol(SYM_TIMES); return SELFOP; } +"/=" {savesymbol(SYM_DIVIDE); return SELFOP; } +"%=" {savesymbol(SYM_MOD); return SELFOP; } +"^=" {savesymbol(SYM_CARET); return SELFOP; } and {adjust(); return AND; } controls {DEFSYMBOL(SYM_CONTROLS); return CONTROLS; } @@ -398,31 +401,34 @@ operator {adjust(); BEGIN opname; } BEGIN INITIAL; return GARBAGE; } -"**" { makesymbol(true, "^"); +"**" { savesymbol(SYM_CARET); BEGIN INITIAL; return ID; } [-+*/%^!<>]|==|!=|<=|>=|&|\||\^\^|\.\.|::|--|---|\+\+|{EXTRAOPS} { - makesymbol(); + makeopsymbol(); BEGIN INITIAL; return ID;} {LETTER}({LETTER}|[0-9])* { - makesymbol(true); + makeopsymbol(); BEGIN INITIAL; return ID; } . {} } {LETTER}({LETTER}|[0-9])* { - makesymbol(false); + makesymbol(); return ID; } \/\* {adjust(); /*commentDepth = 1;*/ BEGIN lexcomment; } -\" {adjust(); BEGIN texstring; } -\' {adjust(); BEGIN cstring; } +\" {startstring(); BEGIN texstring; } +\' {startstring(); BEGIN cstring; } <<EOF>> { setEOF("unexpected end of input"); yyterminate(); } -. { - adjust(); error(); em <<"invalid token '" << yytext << "'"; } - +. {adjust(); + error(); + em << "invalid token"; + if (isgraph(yytext[0])) + em << " '" << yytext[0] << "'"; + } |