2 Cassowary Incremental Constraint Solver
3 Original Smalltalk Implementation by Alan Borning
4 This C++ Implementation by Greg J. Badros, <gjb@cs.washington.edu>
5 http://www.cs.washington.edu/homes/gjb
6 (C) 1998, 1999 Greg J. Badros and Alan Borning
7 See ../LICENSE for legal details regarding this software
9 ClReader.l - Scanner for constraint parsing.
14 /* Get the token numbers that bison created for us
15 (uses the -d option of bison) */
17 #include <cassowary/ClReader.h>
18 #include "ClReader.cc.h"
22 #define CONFIG_H_INCLUDED
25 /* global variable for the istream we are reading from;
26 gets set by PcnParseConstraint */
29 /* Pass in an extra variable (ClParseData *) to cllex so that
30 it can look up variable names */
31 #define YY_DECL int cllex(YYSTYPE *lvalp, void *YYLEX_PARAM)
33 /* Make lexer reader from the global variable */
34 #define YY_INPUT(buf,result,max_size) \
35 do { if (pxi_lexer->get(buf[0]) && buf[0] > 0) result = 1; \
36 else result = YY_NULL; } while (0)
47 ID {ALPHA}({ALPHANUM}|{ID_OK_PUNC})*({RO_ANNOTATION})?
52 {ws} /* skip whitespace */
59 "="|"-"|"+"|"*"|"/"|"("|")" { return yytext[0]; }
61 {DIGIT}+("."{DIGIT}*)? |
62 "."{DIGIT}+ { lvalp->num = strtod(yytext,0); return NUM; }
64 {ID} { /* Lookup the variable name */
65 ClParseData *pclpd = ((ClParseData *) YYLEX_PARAM);
66 int cch = strlen(yytext);
67 ClVariable *pclv = NULL;
68 bool fReadOnly = false;
69 if (yytext[cch-1] == '?') {
73 const string str = string(yytext);
74 pclv = pclpd->_lookup_func(str);
77 return fReadOnly?RO_VAR:VAR;
80 yy_flush_buffer(YY_CURRENT_BUFFER);
81 throw ExCLParseErrorBadIdentifier(str);
86 . { pxi_lexer = NULL; throw ExCLParseErrorMisc("Unrecognized character"); }