// %expect 3 %{ // // tikzparser.y // TikZiT // // Copyright 2010 Chris Heunen. All rights reserved. // // // This file is part of TikZiT. // // TikZiT 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 3 of the License, or // (at your option) any later version. // // TikZiT 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 TikZiT. If not, see . // #include #include #import #import "TikzGraphAssembler.h" #import "GraphElementProperty.h" extern char* yystr; extern int yylineno; extern int tokenpos; extern int yylex(void); extern void yyerror(const char *str); %} %union { NSPoint pt; NSString *nsstr; }; %error-verbose %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 %% 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 | ; properties: property extraproperties; extraproperties: COMMA property extraproperties | ; property: val EQUALS val { TikzGraphAssembler *a = [TikzGraphAssembler currentAssembler]; GraphElementProperty *p = [[GraphElementProperty alloc] initWithPropertyValue:$3 forKey:$1]; [[a data] addObject:p]; [p release]; } | val { TikzGraphAssembler *a = [TikzGraphAssembler currentAssembler]; GraphElementProperty *p = [[GraphElementProperty alloc] initWithAtomName:$1]; [[a data] addObject:p]; [p release]; }; val: PROPSTRING { $$ = $1; } | DELIMITEDSTRING { $$ = $1; }; nodecmd: NODE_CMD { [[TikzGraphAssembler currentAssembler] prepareNode]; }; nodename: LEFTPARENTHESIS REFSTRING RIGHTPARENTHESIS { $$ = $2; }; node: nodecmd optproperties nodename AT COORD DELIMITEDSTRING SEMICOLON { TikzGraphAssembler *a = [TikzGraphAssembler currentAssembler]; [[a currentNode] setName:$3]; [[a currentNode] setPoint:$5]; [[a currentNode] setLabel:$6]; [a finishNode]; }; edgecmd : DRAW_CMD { [[TikzGraphAssembler currentAssembler] prepareEdge]; }; edge: edgecmd optproperties source TO optedgenode target SEMICOLON { TikzGraphAssembler *a = [TikzGraphAssembler currentAssembler]; [a finishEdge]; }; optanchor: { $$ = @""; } | FULLSTOP REFSTRING { $$ = $2; }; source: LEFTPARENTHESIS REFSTRING optanchor RIGHTPARENTHESIS { TikzGraphAssembler *a = [TikzGraphAssembler currentAssembler]; [a setEdgeSource:$2 anchor:$3]; }; target: LEFTPARENTHESIS REFSTRING optanchor RIGHTPARENTHESIS { TikzGraphAssembler *a = [TikzGraphAssembler currentAssembler]; [a setEdgeTarget:$2 anchor:$3]; } | selfloop { TikzGraphAssembler *a = [TikzGraphAssembler currentAssembler]; [a setEdgeTarget:@"" anchor:@""]; }; selfloop: LEFTPARENTHESIS RIGHTPARENTHESIS; edgenodecmd: NODE { [[TikzGraphAssembler currentAssembler] prepareNode]; }; optedgenode: | edgenodecmd optproperties DELIMITEDSTRING { TikzGraphAssembler *a = [TikzGraphAssembler currentAssembler]; [[a currentNode] setLabel:$3]; [a finishNode]; } ignoreprop: val | val EQUALS val; ignoreprops: ignoreprop ignoreprops | ; optignoreprops: LEFTBRACKET ignoreprops RIGHTBRACKET; boundingbox: PATH_CMD optignoreprops COORD RECTANGLE COORD SEMICOLON { Graph *g = [[TikzGraphAssembler currentAssembler] graph]; [g setBoundingBox:NSRectAroundPoints($3, $5)]; }; /* vi:ft=yacc:noet:ts=4:sts=4:sw=4 */