Graphviz 12.0.1~dev.20240716.0800
Loading...
Searching...
No Matches
gmlscan.l
Go to the documentation of this file.
1 /* By default, Flex emits a lexer using symbols prefixed with "yy". Graphviz
2 * contains multiple Flex-generated lexers, so we alter this prefix to avoid
3 * symbol clashes.
4 */
5%option prefix="gml"
6
7 /* Avoid generating an unused input function. See
8 https://westes.github.io/flex/manual/Scanner-Options.html
9 */
10%option noinput
11
12%{
13#include <assert.h>
14#include <cgraph/alloc.h>
15#include <stdlib.h>
16#include <string.h>
17#include <gml2gv.h>
18#include <gmlparse.h>
19#include "config.h"
20
21#define GRAPH_EOF_TOKEN '@' /* lex class must be defined below */
22
23static int line_num = 1;
24static int errors;
25static FILE* Ifile;
26
27void initgmlscan(FILE *ifile)
28{
29 if (ifile) {
30 Ifile = ifile;
31 line_num = 1;
32 }
33 errors = 0;
34}
35
36#ifndef YY_INPUT
37#define YY_INPUT(buf,result,max_size) \
38 if ((result = fread(buf, 1, max_size, Ifile)) < 0) \
39 YY_FATAL_ERROR( "input in flex scanner failed" )
40#endif
41
42/* buffer for arbitrary length strings (longer than BUFSIZ) */
43static char *Sbuf;
44
45static void beginstr(void) {
46 assert(Sbuf == NULL && "leaking memory");
47 Sbuf = gv_strdup("");
48}
49
50static void addstr(const char *src) {
51 assert(Sbuf != NULL && "missing beginstr()");
52
53 // enlarge the buffer to make room for the suffix
54 {
55 size_t old_size = strlen(Sbuf) + 1;
56 size_t new_size = old_size + strlen(src);
57 Sbuf = gv_realloc(Sbuf, old_size, new_size);
58 }
59
60 strcat(Sbuf, src);
61}
62
63static void endstr(void) {
64 assert(Sbuf != NULL && "missing beginstr()");
65
66 // take ownership of the Sbuf backing memory
68 Sbuf = NULL;
69}
70
Memory allocation wrappers that exit on failure.
static char * gv_strdup(const char *original)
Definition alloc.h:101
static void * gv_realloc(void *ptr, size_t old_size, size_t new_size)
Definition alloc.h:49
GML-DOT converter
GMLSTYPE gmllval
static char * Sbuf
Definition gmlscan.l:43
static void endstr(void)
Definition gmlscan.l:63
static int errors
Definition gmlscan.l:24
static void addstr(const char *src)
Definition gmlscan.l:50
static int line_num
Definition gmlscan.l:23
void initgmlscan(FILE *ifile)
Definition gmlscan.l:27
static FILE * Ifile
Definition gmlscan.l:25
static void beginstr(void)
Definition gmlscan.l:45
node NULL
Definition grammar.y:149
char * str
Definition gmlparse.c:426
71%}
72GRAPH_EOF_TOKEN [@]
73ASCII [ !#$%\047-\177]
74DIGIT [0-9]
75L_INT [-+]?{DIGIT}+
76MANTISSA E[-+]?{DIGIT}
77L_REAL [-+]?{DIGIT}*\.{DIGIT}*{MANTISSA}?
78L_ID [a-zA-Z_][_a-zA-Z0-9]*
79%x qstring
80%%
81{GRAPH_EOF_TOKEN} return(EOF);
82<INITIAL,qstring>\n line_num++;
83^"#".* /* ignore # line */
84[ \t\r] /* ignore whitespace */
85
86"graph" return (GRAPH);
#define GRAPH
Definition gmlparse.c:386
87"node" return (NODE);
#define NODE
Definition gmlparse.c:387
88"edge" return (EDGE);
#define EDGE
Definition gmlparse.c:388
89"directed" return (DIRECTED);
#define DIRECTED
Definition gc.c:48
90"id" return (ID);
#define ID
Definition gmlparse.c:415
91"source" return (SOURCE);
#define SOURCE
Definition gmlparse.c:390
92"target" return (TARGET);
#define TARGET
Definition gmlparse.c:391
93"x" return (XVAL);
#define XVAL
Definition gmlparse.c:392
94"y" return (YVAL);
#define YVAL
Definition gmlparse.c:393
95"w" return (WVAL);
#define WVAL
Definition gmlparse.c:394
96"h" return (HVAL);
#define HVAL
Definition gmlparse.c:395
97"label" return (LABEL);
#define LABEL
Definition gmlparse.c:396
98"graphics" return (GRAPHICS);;
#define GRAPHICS
Definition gmlparse.c:397
99"LabelGraphics" return (LABELGRAPHICS);
#define LABELGRAPHICS
Definition gmlparse.c:398
100"type" return (TYPE);
#define TYPE
Definition gmlparse.c:399
101"fill" return (FILL);
#define FILL
Definition gmlparse.c:400
102"outline" return (OUTLINE);
#define OUTLINE
Definition gmlparse.c:401
103"outlineStyle" return (OUTLINESTYLE);
#define OUTLINESTYLE
Definition gmlparse.c:402
104"outlineWidth" return (OUTLINEWIDTH);
#define OUTLINEWIDTH
Definition gmlparse.c:403
105"width" return (WIDTH);
#define WIDTH
Definition gmlparse.c:404
106"style" return (STYLE);
#define STYLE
Definition gmlparse.c:405
107"Line" return (LINE);
#define LINE
Definition gmlparse.c:406
108"point" return (POINT);
#define POINT
Definition gmlparse.c:407
109"text" return (TEXT);
#define TEXT
Definition gmlparse.c:408
110"fontSize" return (FONTSIZE);
#define FONTSIZE
Definition gmlparse.c:409
111"fontName" return (FONTNAME);
#define FONTNAME
Definition gmlparse.c:410
112"color" return (COLOR);
#define COLOR
Definition gmlparse.c:411
113{L_INT} { gmllval.str = gv_strdup(yytext); return (INTEGER); }
#define INTEGER
Definition gmlparse.c:412
#define yytext
Definition gmlscan.c:28
114{L_REAL} { gmllval.str = gv_strdup(yytext); return (REAL); }
#define REAL
Definition gmlparse.c:413
115{L_ID} { gmllval.str = gv_strdup(yytext); return (NAME); }
#define NAME
Definition gmlparse.c:416
116["] BEGIN(qstring); beginstr();
#define qstring
Definition gmlscan.c:898
#define BEGIN
Definition gmlscan.c:377
117
118<qstring>["] BEGIN(INITIAL); endstr(); return (STRING);
#define STRING
Definition gmlparse.c:414
#define INITIAL
Definition gmlscan.c:897
119<qstring>([^"]+) addstr(yytext);
120
121. return (yytext[0]);
122
123%%
124
125void gmlerror(const char *str)
126{
127 if (errors)
128 return;
129 errors = 1;
130 agwarningf(" %s in line %d near '%s'\n", str,line_num,yytext);
131}
132
133int gmlerrors(void)
134{
135 return errors;
136}
137
139
140#ifndef YY_CALL_ONLY_ARG
141# define YY_CALL_ONLY_ARG void
142#endif
143
145{
146 return 1;
147}
148
#define unput(c)
Definition gmlscan.c:441
#define YY_CALL_ONLY_ARG
#define yywrap
Definition gmlscan.c:29
int gmlerrors(void)
Definition gmlscan.l:133
#define GRAPH_EOF_TOKEN
Definition gmlscan.l:21
void gmlerror(const char *str)
Definition gmlscan.l:125
void gmllexeof(void)
Definition gmlscan.l:138
void agwarningf(const char *fmt,...)
Definition agerror.c:173
agxbuf * str
Definition htmlparse.c:97