From a8a8dfb90d6a51ae369c042c95162f45754c7c4b Mon Sep 17 00:00:00 2001 From: randomguy3 Date: Mon, 9 Jan 2012 11:00:50 +0000 Subject: Move tikzit into "trunk" directory git-svn-id: https://tikzit.svn.sourceforge.net/svnroot/tikzit/trunk@365 7c02a99a-9b00-45e3-bf44-6f3dd7fddb64 --- tikzit/src/common/tikzparser.ym | 178 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 178 insertions(+) create mode 100644 tikzit/src/common/tikzparser.ym (limited to 'tikzit/src/common/tikzparser.ym') diff --git a/tikzit/src/common/tikzparser.ym b/tikzit/src/common/tikzparser.ym new file mode 100644 index 0000000..e55a881 --- /dev/null +++ b/tikzit/src/common/tikzparser.ym @@ -0,0 +1,178 @@ +%expect 6 + +%{ +// +// 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 int yylex(void); +extern void yyerror(const char *str); + +%} + +%union { + NSPoint pt; + NSString *nsstr; +}; + +%token LATEXBEGIN +%token LATEXEND +%token TIKZPICTURE +%token PGFONLAYER +%token ANCHORCENTER +%token LEFTPARENTHESIS +%token RIGHTPARENTHESIS +%token LEFTBRACKET +%token RIGHTBRACKET +%token SEMICOLON +%token COMMA +%token EQUALS +%token DRAW +%token TO +%token NODE +%token RECTANGLE +%token PATH +%token ALTNODE +%token AT +%token REALNUMBER +%token NATURALNUMBER +%token LWORD +%token QUOTEDSTRING +%token DELIMITEDSTRING + +%type nodename +%type nodeid +%type coords +%type target +%type propsym +%type propsyms +%type val +%type number + +%% + +tikzpicture: LATEXBEGIN TIKZPICTURE optproperties expressions LATEXEND TIKZPICTURE; +expressions: expressions expression | ; +expression: node | edge | boundingbox | ignore; + +ignore: LATEXBEGIN PGFONLAYER DELIMITEDSTRING | LATEXEND PGFONLAYER; + +number: REALNUMBER { $$ = $1; } | NATURALNUMBER { $$ = $1; }; + +optproperties: LEFTBRACKET properties RIGHTBRACKET | ; +properties: property extraproperties; +extraproperties: COMMA property extraproperties | property extraproperties | ; + +property: + propsyms EQUALS val + { + TikzGraphAssembler *a = [TikzGraphAssembler currentAssembler]; + GraphElementProperty *p = [[GraphElementProperty alloc] initWithPropertyValue:$3 forKey:$1]; + [[a data] addObject:p]; + [p release]; + } + | propsyms + { + TikzGraphAssembler *a = [TikzGraphAssembler currentAssembler]; + GraphElementProperty *p = [[GraphElementProperty alloc] initWithAtomName:$1]; + [[a data] addObject:p]; + [p release]; + }; + +val: propsyms { $$ = $1; } | QUOTEDSTRING { $$ = $1; }; +propsyms: + propsym { $$ = $1; } + | propsyms propsym + { + NSString *s = [$1 stringByAppendingFormat:@" %@", $2]; + $$ = s; + }; + +propsym: + LWORD { $$ = $1; } + | number { $$ = $1; }; + + +nodecmd : NODE { [[TikzGraphAssembler currentAssembler] prepareNode]; }; + +node: + nodecmd optproperties nodename AT coords nodelabel SEMICOLON + { + TikzGraphAssembler *a = [TikzGraphAssembler currentAssembler]; + [[a currentNode] setName:$3]; + [[a currentNode] setPoint:$5]; + [a finishNode]; + }; + +nodelabel: + DELIMITEDSTRING + { + Node *n = [[TikzGraphAssembler currentAssembler] currentNode]; + NSString *label = $1; + [n setLabel:[label substringWithRange:NSMakeRange(1, [label length]-2)]]; + } + +optanchor: | ANCHORCENTER; +nodename: LEFTPARENTHESIS nodeid optanchor RIGHTPARENTHESIS { $$ = $2; }; +nodeid: LWORD { $$ = $1; } | NATURALNUMBER { $$ = $1; }; + +coords: + LEFTPARENTHESIS number COMMA number RIGHTPARENTHESIS + { + $$ = NSMakePoint([$2 floatValue], [$4 floatValue]); + }; + +edgecmd : DRAW { [[TikzGraphAssembler currentAssembler] prepareEdge]; }; +edge: + edgecmd optproperties nodename TO optedgenode target SEMICOLON + { + TikzGraphAssembler *a = [TikzGraphAssembler currentAssembler]; + [a setEdgeSource:$3 + target:$6]; + [a finishEdge]; + }; +target: nodename { $$=$1; } | selfloop { $$=@""; }; +selfloop: LEFTPARENTHESIS RIGHTPARENTHESIS; + +altnodecmd: ALTNODE { [[TikzGraphAssembler currentAssembler] prepareNode]; }; +optedgenode: + | altnodecmd optproperties nodelabel + { + [[TikzGraphAssembler currentAssembler] finishNode]; + } + +bbox_ignoreprops: + | LEFTBRACKET LWORD LWORD LWORD LWORD RIGHTBRACKET; + +boundingbox: + PATH bbox_ignoreprops coords RECTANGLE coords SEMICOLON + { + Graph *g = [[TikzGraphAssembler currentAssembler] graph]; + [g setBoundingBox:NSRectAroundPoints($3, $5)]; + }; + +%% -- cgit v1.2.3