From e68a44b882e5d6dbbab769f7ef20355ec53a9278 Mon Sep 17 00:00:00 2001 From: Alex Merry Date: Sat, 23 Mar 2013 00:55:05 +0000 Subject: Annotate token declarations in parser Better error messages and cleaner code in the body of the parser. --- tikzit/src/common/tikzparser.ym | 132 ++++++++++++++++++++-------------------- 1 file changed, 66 insertions(+), 66 deletions(-) diff --git a/tikzit/src/common/tikzparser.ym b/tikzit/src/common/tikzparser.ym index b81b74c..074ec2d 100644 --- a/tikzit/src/common/tikzparser.ym +++ b/tikzit/src/common/tikzparser.ym @@ -52,30 +52,30 @@ struct 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 +%token BEGIN_TIKZPICTURE_CMD "\\begin{tikzpicture}" +%token END_TIKZPICTURE_CMD "\\end{tikzpicture}" +%token BEGIN_PGFONLAYER_CMD "\\begin{pgfonlayer}" +%token END_PGFONLAYER_CMD "\\end{pgfonlayer}" +%token DRAW_CMD "\\draw" +%token NODE_CMD "\\node" +%token PATH_CMD "\\path" +%token RECTANGLE "rectangle" +%token NODE "node" +%token AT "at" +%token TO "to" +%token SEMICOLON ";" +%token COMMA "," + +%token LEFTPARENTHESIS "(" +%token RIGHTPARENTHESIS ")" +%token LEFTBRACKET "[" +%token RIGHTBRACKET "]" +%token FULLSTOP "." +%token EQUALS "=" +%token COORD "co-ordinate" +%token PROPSTRING "key/value string" +%token REFSTRING "string" +%token DELIMITEDSTRING "{-delimited string" %type nodename %type optanchor @@ -90,89 +90,89 @@ struct noderef { %% -tikzpicture: BEGIN_TIKZPICTURE_CMD optproperties tikzcmds END_TIKZPICTURE_CMD; +tikzpicture: "\\begin{tikzpicture}" optproperties tikzcmds "\\end{tikzpicture}"; tikzcmds: tikzcmds tikzcmd | ; tikzcmd: node | edge | boundingbox | ignore; -ignore: BEGIN_PGFONLAYER_CMD DELIMITEDSTRING | END_PGFONLAYER_CMD; +ignore: "\\begin{pgfonlayer}" DELIMITEDSTRING | "\\end{pgfonlayer}"; optproperties: - LEFTBRACKET properties RIGHTBRACKET - { $$ = $2; } + "[" properties "]" + { $$ = $2; } | { $$ = nil; }; properties: property extraproperties { - [$2 addObject:$1]; - $$ = $2; + [$2 addObject:$1]; + $$ = $2; }; extraproperties: - COMMA property extraproperties + "," property extraproperties { - [$3 addObject:$2]; - $$ = $3; + [$3 addObject:$2]; + $$ = $3; } | { $$ = [GraphElementData data]; }; property: - val EQUALS val - { $$ = [GraphElementProperty property:$1 withValue:$3]; } + val "=" val + { $$ = [GraphElementProperty property:$1 withValue:$3]; } | val - { $$ = [GraphElementProperty atom:$1]; }; -val: PROPSTRING { $$ = $1; } | DELIMITEDSTRING { $$ = $1; }; + { $$ = [GraphElementProperty atom:$1]; }; +val: PROPSTRING { $$ = $1; } | DELIMITEDSTRING { $$ = $1; }; -nodename: LEFTPARENTHESIS REFSTRING RIGHTPARENTHESIS { $$ = $2; }; -node: NODE_CMD optproperties nodename AT COORD DELIMITEDSTRING SEMICOLON +nodename: "(" REFSTRING ")" { $$ = $2; }; +node: "\\node" optproperties nodename "at" COORD DELIMITEDSTRING ";" { Node *node = [Node node]; - [node setData:$2]; - [node setName:$3]; - [node setPoint:$5]; - [node setLabel:$6]; + [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 +optanchor: { $$ = nil; } | "." REFSTRING { $$ = $2; }; +noderef: "(" REFSTRING optanchor ")" { - $$.node = [[TikzGraphAssembler currentAssembler] nodeWithName:$2]; - $$.anchor = $3; + $$.node = [[TikzGraphAssembler currentAssembler] nodeWithName:$2]; + $$.anchor = $3; }; optnoderef: - noderef { $$ = $1; } - | LEFTPARENTHESIS RIGHTPARENTHESIS { $$.node = nil; $$.anchor = nil; } + noderef { $$ = $1; } + | "(" ")" { $$.node = nil; $$.anchor = nil; } optedgenode: { $$ = nil; } - | NODE optproperties DELIMITEDSTRING + | "node" optproperties DELIMITEDSTRING { $$ = [Node node]; - [$$ setData:$2]; - [$$ setLabel:$3]; + [$$ setData:$2]; + [$$ setLabel:$3]; } -edge: DRAW_CMD optproperties noderef TO optedgenode optnoderef SEMICOLON +edge: "\\draw" optproperties noderef "to" optedgenode optnoderef ";" { 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]; + [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 setTarget:$3.node]; + [edge setTargetAnchor:$3.anchor]; } [edge setAttributesFromData]; [[[TikzGraphAssembler currentAssembler] graph] addEdge:edge]; }; -ignoreprop: val | val EQUALS val; +ignoreprop: val | val "=" val; ignoreprops: ignoreprop ignoreprops | ; -optignoreprops: LEFTBRACKET ignoreprops RIGHTBRACKET; +optignoreprops: "[" ignoreprops "]"; boundingbox: - PATH_CMD optignoreprops COORD RECTANGLE COORD SEMICOLON + "\\path" optignoreprops COORD "rectangle" COORD ";" { - [[[TikzGraphAssembler currentAssembler] graph] setBoundingBox:NSRectAroundPoints($3, $5)]; + [[[TikzGraphAssembler currentAssembler] graph] setBoundingBox:NSRectAroundPoints($3, $5)]; }; /* vi:ft=yacc:noet:ts=4:sts=4:sw=4 -- cgit v1.2.3