%error-verbose %{ /* * Copyright 2010 Chris Heunen * Copyright 2010-2013 Aleks Kissinger * Copyright 2013 K. Johan Paulsson * Copyright 2013 Alex Merry * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License as * published by the Free Software Foundation; either version 2 of * the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ #import "TikzGraphAssembler+Parser.h" #import "Edge.h" extern char* yystr; extern int yylineno; extern int tokenpos; extern int yylex(void); extern void yyerror(const char *str); %} %code requires { #import "GraphElementData.h" #import "GraphElementProperty.h" #import "Node.h" struct noderef { Node *node; NSString *anchor; }; } %union { NSPoint pt; NSString *nsstr; GraphElementProperty *prop; GraphElementData *data; Node *node; struct noderef noderef; }; %token BEGIN_TIKZPICTURE_CMD %token END_TIKZPICTURE_CMD %token BEGIN_PGFONLAYER_CMD %token END_PGFONLAYER_CMD %token DRAW_CMD %token NODE_CMD %token PATH_CMD %token RECTANGLE %token NODE %token AT %token TO %token SEMICOLON %token COMMA %token LEFTPARENTHESIS %token RIGHTPARENTHESIS %token LEFTBRACKET %token RIGHTBRACKET %token FULLSTOP %token EQUALS %token COORD %token PROPSTRING %token REFSTRING %token DELIMITEDSTRING %type nodename %type optanchor %type val %type property %type extraproperties %type properties %type optproperties %type optedgenode %type noderef %type optnoderef %% tikzpicture: BEGIN_TIKZPICTURE_CMD optproperties tikzcmds END_TIKZPICTURE_CMD; tikzcmds: tikzcmds tikzcmd | ; tikzcmd: node | edge | boundingbox | ignore; ignore: BEGIN_PGFONLAYER_CMD DELIMITEDSTRING | END_PGFONLAYER_CMD; optproperties: LEFTBRACKET properties RIGHTBRACKET { $$ = $2; } | { $$ = nil; }; properties: property extraproperties { [$2 addObject:$1]; $$ = $2; }; extraproperties: COMMA property extraproperties { [$3 addObject:$2]; $$ = $3; } | { $$ = [GraphElementData data]; }; property: val EQUALS val { $$ = [GraphElementProperty property:$1 withValue:$3]; } | val { $$ = [GraphElementProperty atom:$1]; }; val: PROPSTRING { $$ = $1; } | DELIMITEDSTRING { $$ = $1; }; nodename: LEFTPARENTHESIS REFSTRING RIGHTPARENTHESIS { $$ = $2; }; node: NODE_CMD optproperties nodename AT COORD DELIMITEDSTRING SEMICOLON { Node *node = [Node node]; [node setData:$2]; [node setName:$3]; [node setPoint:$5]; [node setLabel:$6]; [[TikzGraphAssembler currentAssembler] addNodeToMap:node]; [[[TikzGraphAssembler currentAssembler] graph] addNode:node]; }; optanchor: { $$ = nil; } | FULLSTOP REFSTRING { $$ = $2; }; noderef: LEFTPARENTHESIS REFSTRING optanchor RIGHTPARENTHESIS { $$.node = [[TikzGraphAssembler currentAssembler] nodeWithName:$2]; $$.anchor = $3; }; optnoderef: noderef { $$ = $1; } | LEFTPARENTHESIS RIGHTPARENTHESIS { $$.node = nil; $$.anchor = nil; } optedgenode: { $$ = nil; } | NODE optproperties DELIMITEDSTRING { $$ = [Node node]; [$$ setData:$2]; [$$ setLabel:$3]; } edge: DRAW_CMD optproperties noderef TO optedgenode optnoderef SEMICOLON { Edge *edge = [Edge edge]; [edge setData:$2]; [edge setSource:$3.node]; [edge setSourceAnchor:$3.anchor]; [edge setEdgeNode:$5]; if ($6.node) { [edge setTarget:$6.node]; [edge setTargetAnchor:$6.anchor]; } else { [edge setTarget:$3.node]; [edge setTargetAnchor:$3.anchor]; } [edge setAttributesFromData]; [[[TikzGraphAssembler currentAssembler] graph] addEdge:edge]; }; ignoreprop: val | val EQUALS val; ignoreprops: ignoreprop ignoreprops | ; optignoreprops: LEFTBRACKET ignoreprops RIGHTBRACKET; boundingbox: PATH_CMD optignoreprops COORD RECTANGLE COORD SEMICOLON { [[[TikzGraphAssembler currentAssembler] graph] setBoundingBox:NSRectAroundPoints($3, $5)]; }; /* vi:ft=yacc:noet:ts=4:sts=4:sw=4 */