summaryrefslogtreecommitdiff
path: root/tikzit
diff options
context:
space:
mode:
authorAleks Kissinger <aleks0@gmail.com>2017-01-15 18:45:15 +0100
committerAleks Kissinger <aleks0@gmail.com>2017-01-15 18:45:15 +0100
commit716aadc00c1a03e43c246a72be4758fcdf809fe0 (patch)
tree7ea8584217a4239148463e82fae580da5f72163a /tikzit
parent3947a6b0fd38af964f5a09bd919d5d7f317697db (diff)
working on parser
Diffstat (limited to 'tikzit')
-rw-r--r--tikzit/edge.cpp19
-rw-r--r--tikzit/edge.h26
-rw-r--r--tikzit/graph.cpp30
-rw-r--r--tikzit/graph.h32
-rw-r--r--tikzit/graphelementdata.cpp37
-rw-r--r--tikzit/graphelementdata.h24
-rw-r--r--tikzit/graphelementproperty.cpp34
-rw-r--r--tikzit/graphelementproperty.h35
-rw-r--r--tikzit/main.cpp9
-rw-r--r--tikzit/mainwindow.cpp14
-rw-r--r--tikzit/mainwindow.h6
-rw-r--r--tikzit/mainwindow.ui36
-rw-r--r--tikzit/node.cpp43
-rw-r--r--tikzit/node.h34
-rw-r--r--tikzit/tikzgraphassembler.cpp9
-rw-r--r--tikzit/tikzgraphassembler.h25
-rw-r--r--tikzit/tikzit.pro16
-rw-r--r--tikzit/tikzit.pro.user4
-rw-r--r--tikzit/tikzlexer.lpp171
-rw-r--r--tikzit/tikzparser.ypp228
-rw-r--r--tikzit/tikzparserdefs.h2
-rw-r--r--tikzit/toolpalette.cpp7
-rw-r--r--tikzit/toolpalette.h2
23 files changed, 827 insertions, 16 deletions
diff --git a/tikzit/edge.cpp b/tikzit/edge.cpp
new file mode 100644
index 0000000..bea96b8
--- /dev/null
+++ b/tikzit/edge.cpp
@@ -0,0 +1,19 @@
+#include "edge.h"
+
+Edge::Edge(Node *s, Node *t, QObject *parent) :
+ QObject(parent), _source(s), _target(t)
+{
+
+}
+
+Node *Edge::source() const
+{
+ return _source;
+}
+
+Node *Edge::target() const
+{
+ return _target;
+}
+
+
diff --git a/tikzit/edge.h b/tikzit/edge.h
new file mode 100644
index 0000000..2153f30
--- /dev/null
+++ b/tikzit/edge.h
@@ -0,0 +1,26 @@
+#ifndef EDGE_H
+#define EDGE_H
+
+#include <QObject>
+
+class Node;
+
+class Edge : public QObject
+{
+ Q_OBJECT
+public:
+ explicit Edge(Node *s, Node *t, QObject *parent = 0);
+
+ Node *source() const;
+ Node *target() const;
+
+signals:
+
+public slots:
+
+private:
+ Node *_source;
+ Node *_target;
+};
+
+#endif // EDGE_H
diff --git a/tikzit/graph.cpp b/tikzit/graph.cpp
new file mode 100644
index 0000000..0db20e1
--- /dev/null
+++ b/tikzit/graph.cpp
@@ -0,0 +1,30 @@
+#include "graph.h"
+
+Graph::Graph(QObject *parent) : QObject(parent)
+{
+
+}
+
+void Graph::removeNode(Node *n) {
+ nodes.removeAll(n);
+ inEdges.remove(n);
+ outEdges.remove(n);
+}
+
+Edge *Graph::addEdge(Node *s, Node *t)
+{
+
+}
+
+void Graph::removeEdge(Edge *e)
+{
+
+}
+
+Node *Graph::addNode() {
+ Node *n = new Node(this);
+ nodes << n;
+ return n;
+}
+
+
diff --git a/tikzit/graph.h b/tikzit/graph.h
new file mode 100644
index 0000000..f55b3c9
--- /dev/null
+++ b/tikzit/graph.h
@@ -0,0 +1,32 @@
+#ifndef GRAPH_H
+#define GRAPH_H
+
+#include "node.h"
+#include "edge.h"
+
+#include <QObject>
+#include <QVector>
+#include <QMultiHash>
+
+class Graph : public QObject
+{
+ Q_OBJECT
+public:
+ explicit Graph(QObject *parent = 0);
+ Node *addNode();
+ void removeNode(Node *n);
+ Edge *addEdge(Node *s, Node*t);
+ void removeEdge(Edge *e);
+
+signals:
+
+public slots:
+
+private:
+ QVector<Node*> nodes;
+ QVector<Edge*> edges;
+ QMultiHash<Node*,Edge*> inEdges;
+ QMultiHash<Node*,Edge*> outEdges;
+};
+
+#endif // GRAPH_H
diff --git a/tikzit/graphelementdata.cpp b/tikzit/graphelementdata.cpp
new file mode 100644
index 0000000..7240ea8
--- /dev/null
+++ b/tikzit/graphelementdata.cpp
@@ -0,0 +1,37 @@
+#include "graphelementdata.h"
+
+GraphElementData::GraphElementData(QObject *parent) : QObject(parent)
+{
+
+}
+
+void GraphElementData::setProperty(QString key, QString value)
+{
+
+}
+
+void GraphElementData::unsetProperty(QString key)
+{
+
+}
+
+void GraphElementData::setAtom(QString atom)
+{
+
+}
+
+void GraphElementData::unsetAtom(QString atom)
+{
+
+}
+
+QString GraphElementData::property(QString key)
+{
+
+}
+
+QString GraphElementData::atom(QString atom)
+{
+
+}
+
diff --git a/tikzit/graphelementdata.h b/tikzit/graphelementdata.h
new file mode 100644
index 0000000..e67d740
--- /dev/null
+++ b/tikzit/graphelementdata.h
@@ -0,0 +1,24 @@
+#ifndef GRAPHELEMENTDATA_H
+#define GRAPHELEMENTDATA_H
+
+#include <QObject>
+#include <QString>
+
+class GraphElementData : public QObject
+{
+ Q_OBJECT
+public:
+ explicit GraphElementData(QObject *parent = 0);
+ void setProperty(QString key, QString value);
+ void unsetProperty(QString key);
+ void setAtom(QString atom);
+ void unsetAtom(QString atom);
+ QString property(QString key);
+ QString atom(QString atom);
+
+signals:
+
+public slots:
+};
+
+#endif // GRAPHELEMENTDATA_H
diff --git a/tikzit/graphelementproperty.cpp b/tikzit/graphelementproperty.cpp
new file mode 100644
index 0000000..7602b1c
--- /dev/null
+++ b/tikzit/graphelementproperty.cpp
@@ -0,0 +1,34 @@
+#include "graphelementproperty.h"
+
+GraphElementProperty::GraphElementProperty(QString key, QString value,
+ bool atom, bool keyMatch, QObject *parent) :
+ QObject(parent), _key(key), _value(value), _atom(atom), _keyMatch(keyMatch)
+{}
+
+GraphElementProperty::GraphElementProperty(QString key, QString value, QObject *parent) :
+ QObject(parent), _key(key), _value(value), _atom(false), _keyMatch(false)
+{}
+
+GraphElementProperty::GraphElementProperty(QString key, QObject *parent) :
+ QObject(parent), _key(key), _value(""), _atom(true), _keyMatch(false)
+{}
+
+QString GraphElementProperty::key() const
+{ return _key; }
+
+QString GraphElementProperty::value() const
+{ return _value; }
+
+bool GraphElementProperty::atom() const
+{ return _atom; }
+
+bool GraphElementProperty::keyMatch() const
+{ return _keyMatch; }
+
+bool GraphElementProperty::matches(GraphElementProperty *p)
+{
+ if (p->atom()) return _atom && _key == p->key();
+ if (p->keyMatch()) return !_atom && _key == p->key();
+ if (_keyMatch) return !p->atom() && _key == p->key();
+ return !_atom && _key == p->key() && _value == p->value();
+}
diff --git a/tikzit/graphelementproperty.h b/tikzit/graphelementproperty.h
new file mode 100644
index 0000000..56d20e9
--- /dev/null
+++ b/tikzit/graphelementproperty.h
@@ -0,0 +1,35 @@
+#ifndef GRAPHELEMENTPROPERTY_H
+#define GRAPHELEMENTPROPERTY_H
+
+#include <QObject>
+
+class GraphElementProperty : public QObject
+{
+ Q_OBJECT
+public:
+ GraphElementProperty(QString key, QString value, bool atom, bool keyMatch, QObject *parent = 0);
+
+ // construct a property
+ GraphElementProperty(QString key, QString value, QObject *parent = 0);
+
+ // construct an atom
+ GraphElementProperty(QString key, QObject *parent = 0);
+
+ QString key() const;
+ QString value() const;
+ bool atom() const;
+ bool keyMatch() const;
+
+ bool matches(GraphElementProperty *p);
+signals:
+
+public slots:
+
+private:
+ QString _key;
+ QString _value;
+ bool _atom;
+ bool _keyMatch;
+};
+
+#endif // GRAPHELEMENTPROPERTY_H
diff --git a/tikzit/main.cpp b/tikzit/main.cpp
index 7ece416..50c6978 100644
--- a/tikzit/main.cpp
+++ b/tikzit/main.cpp
@@ -1,5 +1,7 @@
#include "mainwindow.h"
#include "toolpalette.h"
+#include "graph.h"
+
#include <QApplication>
int main(int argc, char *argv[])
@@ -8,8 +10,13 @@ int main(int argc, char *argv[])
MainWindow *w = new MainWindow();
w->show();
- ToolPalette *tp = new ToolPalette();
+ ToolPalette *tp = new ToolPalette(new QMainWindow());
tp->show();
+ //w->addToolBar(Qt::LeftToolBarArea, tp);
+
+ Graph *g = new Graph;
+ Node *n = g->addNode();
+ delete g;
return a.exec();
}
diff --git a/tikzit/mainwindow.cpp b/tikzit/mainwindow.cpp
index cbb0f60..ef73a20 100644
--- a/tikzit/mainwindow.cpp
+++ b/tikzit/mainwindow.cpp
@@ -1,14 +1,20 @@
#include "mainwindow.h"
+#include "ui_mainwindow.h"
#include <QDebug>
-MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent)
+MainWindow::MainWindow(QWidget *parent) :
+ QMainWindow(parent),
+ ui(new Ui::MainWindow)
{
+ ui->setupUi(this);
setAttribute(Qt::WA_DeleteOnClose);
tikzScene = new TikzScene(this);
- tikzView = new QGraphicsView(tikzScene);
- setCentralWidget(tikzView);
- resize(700, 500);
+ ui->tikzView->setScene(tikzScene);
+ //tikzView = new QGraphicsView(tikzScene);
+ //setCentralWidget(tikzView);
+ //resize(700, 500);
+ // badger?
}
MainWindow::~MainWindow()
diff --git a/tikzit/mainwindow.h b/tikzit/mainwindow.h
index 167707a..d33a89d 100644
--- a/tikzit/mainwindow.h
+++ b/tikzit/mainwindow.h
@@ -6,6 +6,10 @@
#include <QMainWindow>
#include <QGraphicsView>
+namespace Ui {
+class MainWindow;
+}
+
class MainWindow : public QMainWindow
{
Q_OBJECT
@@ -15,7 +19,7 @@ public:
~MainWindow();
private:
TikzScene *tikzScene;
- QGraphicsView *tikzView;
+ Ui::MainWindow *ui;
};
#endif // MAINWINDOW_H
diff --git a/tikzit/mainwindow.ui b/tikzit/mainwindow.ui
index d04e8e9..6439ee8 100644
--- a/tikzit/mainwindow.ui
+++ b/tikzit/mainwindow.ui
@@ -11,9 +11,41 @@
</rect>
</property>
<property name="windowTitle">
- <string>MainWindow</string>
+ <string>TikZiT</string>
</property>
- <widget class="QWidget" name="centralWidget"/>
+ <widget class="QWidget" name="centralWidget">
+ <layout class="QVBoxLayout" name="verticalLayout">
+ <property name="leftMargin">
+ <number>0</number>
+ </property>
+ <property name="topMargin">
+ <number>0</number>
+ </property>
+ <property name="rightMargin">
+ <number>0</number>
+ </property>
+ <property name="bottomMargin">
+ <number>0</number>
+ </property>
+ <item>
+ <widget class="QSplitter" name="splitter">
+ <property name="orientation">
+ <enum>Qt::Vertical</enum>
+ </property>
+ <widget class="QGraphicsView" name="tikzView"/>
+ <widget class="QTextEdit" name="tikzSource">
+ <property name="html">
+ <string>&lt;!DOCTYPE HTML PUBLIC &quot;-//W3C//DTD HTML 4.0//EN&quot; &quot;http://www.w3.org/TR/REC-html40/strict.dtd&quot;&gt;
+&lt;html&gt;&lt;head&gt;&lt;meta name=&quot;qrichtext&quot; content=&quot;1&quot; /&gt;&lt;style type=&quot;text/css&quot;&gt;
+p, li { white-space: pre-wrap; }
+&lt;/style&gt;&lt;/head&gt;&lt;body style=&quot; font-family:'.SF NS Text'; font-size:13pt; font-weight:400; font-style:normal;&quot;&gt;
+&lt;p style=&quot; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;Stuff written here&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
+ </property>
+ </widget>
+ </widget>
+ </item>
+ </layout>
+ </widget>
<widget class="QMenuBar" name="menuBar">
<property name="geometry">
<rect>
diff --git a/tikzit/node.cpp b/tikzit/node.cpp
new file mode 100644
index 0000000..2c1c7ee
--- /dev/null
+++ b/tikzit/node.cpp
@@ -0,0 +1,43 @@
+#include "node.h"
+
+#include <QDebug>
+
+Node::Node(QObject *parent) : QObject(parent)
+{
+ qDebug() << "Node()";
+}
+
+Node::~Node()
+{
+ qDebug() << "~Node()";
+}
+
+QPointF Node::pos() const
+{
+ return _pos;
+}
+
+void Node::setPos(const QPointF &pos)
+{
+ _pos = pos;
+}
+
+QString Node::name() const
+{
+ return _name;
+}
+
+void Node::setName(const QString &name)
+{
+ _name = name;
+}
+
+QString Node::label() const
+{
+ return _label;
+}
+
+void Node::setLabel(const QString &label)
+{
+ _label = label;
+}
diff --git a/tikzit/node.h b/tikzit/node.h
new file mode 100644
index 0000000..8eae520
--- /dev/null
+++ b/tikzit/node.h
@@ -0,0 +1,34 @@
+#ifndef NODE_H
+#define NODE_H
+
+#include <QObject>
+#include <QPointF>
+#include <QString>
+
+class Node : public QObject
+{
+ Q_OBJECT
+public:
+ explicit Node(QObject *parent = 0);
+ ~Node();
+
+ QPointF pos() const;
+ void setPos(const QPointF &pos);
+
+ QString name() const;
+ void setName(const QString &name);
+
+ QString label() const;
+ void setLabel(const QString &label);
+
+signals:
+
+public slots:
+
+private:
+ QPointF _pos;
+ QString _name;
+ QString _label;
+};
+
+#endif // NODE_H
diff --git a/tikzit/tikzgraphassembler.cpp b/tikzit/tikzgraphassembler.cpp
new file mode 100644
index 0000000..a785d85
--- /dev/null
+++ b/tikzit/tikzgraphassembler.cpp
@@ -0,0 +1,9 @@
+#include "tikzgraphassembler.h"
+
+TikzGraphAssembler::TikzGraphAssembler(QObject *parent) : QObject(parent)
+{
+
+}
+
+void TikzGraphAssembler::addNodeToMap(Node *n) { _nodeMap.insert(n->name(), n); }
+Node *TikzGraphAssembler::nodeWithName(QString name) { return _nodeMap[name]; }
diff --git a/tikzit/tikzgraphassembler.h b/tikzit/tikzgraphassembler.h
new file mode 100644
index 0000000..5869d95
--- /dev/null
+++ b/tikzit/tikzgraphassembler.h
@@ -0,0 +1,25 @@
+#ifndef TIKZGRAPHASSEMBLER_H
+#define TIKZGRAPHASSEMBLER_H
+
+#include "node.h"
+
+#include <QObject>
+#include <QHash>
+
+class TikzGraphAssembler : public QObject
+{
+ Q_OBJECT
+public:
+ explicit TikzGraphAssembler(QObject *parent = 0);
+ void addNodeToMap(Node *n);
+ Node *nodeWithName(QString name);
+
+signals:
+
+public slots:
+
+private:
+ QHash<QString,Node*> _nodeMap;
+};
+
+#endif // TIKZGRAPHASSEMBLER_H
diff --git a/tikzit/tikzit.pro b/tikzit/tikzit.pro
index 3301c1a..2762908 100644
--- a/tikzit/tikzit.pro
+++ b/tikzit/tikzit.pro
@@ -26,11 +26,23 @@ DEFINES += QT_DEPRECATED_WARNINGS
SOURCES += main.cpp\
mainwindow.cpp \
toolpalette.cpp \
- tikzscene.cpp
+ tikzscene.cpp \
+ graph.cpp \
+ node.cpp \
+ edge.cpp \
+ tikzgraphassembler.cpp \
+ graphelementdata.cpp \
+ graphelementproperty.cpp
HEADERS += mainwindow.h \
toolpalette.h \
- tikzscene.h
+ tikzscene.h \
+ graph.h \
+ node.h \
+ edge.h \
+ tikzgraphassembler.h \
+ graphelementdata.h \
+ graphelementproperty.h
FORMS += mainwindow.ui
diff --git a/tikzit/tikzit.pro.user b/tikzit/tikzit.pro.user
index 5f8dab8..f8495a5 100644
--- a/tikzit/tikzit.pro.user
+++ b/tikzit/tikzit.pro.user
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE QtCreatorProject>
-<!-- Written by QtCreator 4.2.0, 2017-01-13T23:09:58. -->
+<!-- Written by QtCreator 4.2.0, 2017-01-15T13:42:00. -->
<qtcreator>
<data>
<variable>EnvironmentId</variable>
@@ -19,7 +19,7 @@
<valuemap type="QVariantMap" key="EditorConfiguration.CodeStyle.0">
<value type="QString" key="language">Cpp</value>
<valuemap type="QVariantMap" key="value">
- <value type="QByteArray" key="CurrentPreferences">CppGlobal</value>
+ <value type="QByteArray" key="CurrentPreferences">qt</value>
</valuemap>
</valuemap>
<valuemap type="QVariantMap" key="EditorConfiguration.CodeStyle.1">
diff --git a/tikzit/tikzlexer.lpp b/tikzit/tikzlexer.lpp
new file mode 100644
index 0000000..19c4d85
--- /dev/null
+++ b/tikzit/tikzlexer.lpp
@@ -0,0 +1,171 @@
+%{
+/*
+ * Copyright 2010 Chris Heunen
+ * Copyright 2010-2013 Aleks Kissinger
+ * Copyright 2013 K. Johan Paulsson
+ * Copyright 2013 Alex Merry <dev@randomguy3.me.uk>
+ *
+ * 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 <http://www.gnu.org/licenses/>.
+ */
+
+#include "tikzparserdefs.h"
+#include "tikzparser.h"
+
+#include <QString>
+
+#define YY_USER_ACTION \
+ yylloc->first_line = yylloc->last_line; \
+ yylloc->first_column = yylloc->last_column + 1; \
+ yylloc->last_column = yylloc->first_column + yyleng - 1;
+
+%}
+
+%option reentrant bison-bridge bison-locations 8bit
+%option nounput
+%option yylineno
+%option noyywrap
+%option header-file="common/tikzlexer.h"
+%option extra-type="TikzGraphAssembler *"
+
+
+%s props
+%s xcoord
+%s ycoord
+%s noderef
+
+FLOAT \-?[0-9]*(\.[0-9]+)?
+
+%%
+
+ /* whitespace is ignored, except for position counting; we don't
+ count formfeed and vtab as whitespace, because it's not obvious
+ how they should be dealt with and no-one actually uses them */
+
+ /* lex will take the longest-matching string */
+<INITIAL,xcoord,ycoord,props,noderef>\r\n|\r|\n {
+ yylloc->first_line += 1;
+ yylloc->last_line = yylloc->first_line;
+ yylloc->first_column = yylloc->last_column = 0;
+}
+<INITIAL,xcoord,ycoord,props,noderef>[\t ]+ { }
+
+\\begin\{tikzpicture\} { return BEGIN_TIKZPICTURE_CMD; }
+\\end\{tikzpicture\} { return END_TIKZPICTURE_CMD; }
+\\begin\{pgfonlayer\} { return BEGIN_PGFONLAYER_CMD; }
+\\end\{pgfonlayer\} { return END_PGFONLAYER_CMD; }
+\\draw { return DRAW_CMD; }
+\\node { return NODE_CMD; }
+\\path { return PATH_CMD; }
+rectangle { return RECTANGLE; }
+node { return NODE; }
+at { return AT; }
+to { return TO; }
+; { return SEMICOLON; }
+
+\([ ]*{FLOAT}[ ]*,[ ]*{FLOAT}[ ]*\) {
+ yylloc->last_column = yylloc->first_column + 1;
+ yyless(1);
+ BEGIN(xcoord);
+}
+<xcoord>{FLOAT} {
+ yylval->pt.x=(float)strtod(yytext,NULL);
+ BEGIN(ycoord);
+}
+<ycoord>, { }
+<ycoord>{FLOAT} {
+ yylval->pt.y=(float)strtod(yytext,NULL);
+}
+<ycoord>\) {
+ BEGIN(INITIAL);
+ return COORD;
+}
+
+ /* when we see "[", change parsing mode */
+\[ /*syntaxhlfix]*/ {
+ BEGIN(props);
+ return LEFTBRACKET;
+}
+<props>= { return EQUALS; }
+<props>, { return COMMA; }
+ /* technically, it is possible to have newlines in the middle of
+ property names or values, but in practice this is unlikely and
+ screws up our line counting */
+<props>[^=,\{\] \t\n]([^=,\{\]\n]*[^=,\{\] \t\n])? {
+ yylval->nsstr=[NSString stringWithUTF8String:yytext];
+ return PROPSTRING;
+}
+<props>\] {
+ BEGIN(INITIAL);
+ return RIGHTBRACKET;
+}
+
+\( {
+ BEGIN(noderef);
+ return LEFTPARENTHESIS;
+}
+<noderef>\. {
+ return FULLSTOP;
+}
+ /* we assume node names (and anchor names) never contain
+ newlines */
+<noderef>[^\.\{\)\n]+ {
+ yylval->nsstr=[NSString stringWithUTF8String:yytext];
+ return REFSTRING;
+}
+<noderef>\) {
+ BEGIN(INITIAL);
+ return RIGHTPARENTHESIS;
+}
+
+<INITIAL,props>\{ {
+ NSMutableString *buf = [NSMutableString string];
+ unsigned int brace_depth = 1;
+ unsigned int escape = 0;
+ while (1) {
+ char c = input(yyscanner);
+ // eof reached before closing brace
+ if (c == '\0' || c == EOF) {
+ return UNCLOSED_DELIM_STR;
+ }
+
+ yylloc->last_column += 1;
+ yyleng += 1;
+ if (escape) {
+ escape = 0;
+ } else if (c == '\\') {
+ escape = 1;
+ } else if (c == '{') {
+ brace_depth++;
+ } else if (c == '}') {
+ brace_depth--;
+ if (brace_depth == 0) break;
+ } else if (c == '\n') {
+ yylloc->last_line += 1;
+ yylloc->last_column = 0;
+ }
+ [buf appendFormat:@"%c", c];
+ }
+
+ yylval->nsstr = buf;
+ return DELIMITEDSTRING;
+}
+
+\\begin { return UNKNOWN_BEGIN_CMD; }
+\\end { return UNKNOWN_END_CMD; }
+\\[a-zA-Z0-9]+ { return UNKNOWN_CMD; }
+[a-zA-Z0-9]+ { return UNKNOWN_STR; }
+<INITIAL,xcoord,ycoord,props,noderef>. { return UNKNOWN_STR; }
+
+ /* vi:ft=lex:noet:ts=4:sts=4:sw=4:
+ */
diff --git a/tikzit/tikzparser.ypp b/tikzit/tikzparser.ypp
new file mode 100644
index 0000000..e97b1c7
--- /dev/null
+++ b/tikzit/tikzparser.ypp
@@ -0,0 +1,228 @@
+%{
+/*
+ * Copyright 2010 Chris Heunen
+ * Copyright 2010-2013 Aleks Kissinger
+ * Copyright 2013 K. Johan Paulsson
+ * Copyright 2013 Alex Merry <dev@randomguy3.me.uk>
+ *
+ * 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 <http://www.gnu.org/licenses/>.
+ */
+
+#include "tikzparserdefs.h"
+%}
+
+/* we use features added to bison 2.4 */
+%require "2.3"
+
+%error-verbose
+/* enable maintaining locations for better error messages */
+%locations
+/* the name of the header file */
+/*%defines "common/tikzparser.h"*/
+/* make it re-entrant (no global variables) */
+%pure-parser
+/* We use a pure (re-entrant) lexer. This means yylex
+ will take a void* (opaque) type to maintain its state */
+%lex-param {void *scanner}
+/* Since this parser is also pure, yyparse needs to take
+ that lexer state as an argument */
+%parse-param {void *scanner}
+
+/* possible data types for semantic values */
+%union {
+ QString qstr;
+ GraphElementProperty *prop;
+ GraphElementData *data;
+ Node *node;
+ QPointF pt;
+ struct noderef noderef;
+}
+
+%{
+#include "node.h"
+#include "edge.h"
+ #include "graphelementdata.h"
+#include "graphelementproperty.h"
+
+#include "tikzlexer.h"
+#import "tikzgraphassembler.h"
+/* the assembler (used by this parser) is stored in the lexer
+ state as "extra" data */
+#define assembler yyget_extra(scanner)
+
+/* pass errors off to the assembler */
+void yyerror(YYLTYPE *yylloc, void *scanner, const char *str) {
+ // TODO: implement reportError()
+ //assembler->reportError(str, yylloc);
+}
+%}
+
+/* yyloc is set up with first_column = last_column = 1 by default;
+ however, it makes more sense to think of us being "before the
+ start of the line" before we parse anything */
+%initial-action {
+ yylloc.first_column = yylloc.last_column = 0;
+}
+
+
+%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 <pt> COORD "co-ordinate"
+%token <qstr> PROPSTRING "key/value string"
+%token <qstr> REFSTRING "string"
+%token <qstr> DELIMITEDSTRING "{-delimited string"
+
+%token UNKNOWN_BEGIN_CMD "unknown \\begin command"
+%token UNKNOWN_END_CMD "unknown \\end command"
+%token UNKNOWN_CMD "unknown latex command"
+%token UNKNOWN_STR "unknown string"
+%token UNCLOSED_DELIM_STR "unclosed {-delimited string"
+
+%type<qstr> nodename
+%type<qstr> optanchor
+%type<qstr> val
+%type<prop> property
+%type<data> extraproperties
+%type<data> properties
+%type<data> optproperties
+%type<node> optedgenode
+%type<noderef> noderef
+%type<noderef> optnoderef
+
+%%
+
+tikzpicture: "\\begin{tikzpicture}" optproperties tikzcmds "\\end{tikzpicture}"
+ {
+ if ($2) {
+ assembler->graph()->setData($2);
+ }
+ };
+tikzcmds: tikzcmds tikzcmd | ;
+tikzcmd: node | edge | boundingbox | ignore;
+
+ignore: "\\begin{pgfonlayer}" DELIMITEDSTRING | "\\end{pgfonlayer}";
+
+optproperties:
+ "[" "]"
+ { $$ = 0; }
+ | "[" properties "]"
+ { $$ = $2; }
+ | { $$ = 0; };
+properties: extraproperties property
+ {
+ [$1 addObject:$2];
+ $$ = $1;
+ };
+extraproperties:
+ extraproperties property ","
+ {
+ [$1 addObject:$2];
+ $$ = $1;
+ }
+ | { $$ = [GraphElementData data]; };
+property:
+ val "=" val
+ { $$ = [GraphElementProperty property:$1 withValue:$3]; }
+ | val
+ { $$ = [GraphElementProperty atom:$1]; };
+val: PROPSTRING { $$ = $1; } | DELIMITEDSTRING { $$ = $1; };
+
+nodename: "(" REFSTRING ")" { $$ = $2; };
+node: "\\node" optproperties nodename "at" COORD DELIMITEDSTRING ";"
+ {
+ Node *node = assembler->graph()->addNode();
+ if ($2)
+ node->setData($2);
+ node->setName($3);
+ node->setPoint($5);
+ node->setLabel($6);
+ assembler->addNodeToMap(node);
+ };
+
+optanchor: { $$ = 0; } | "." REFSTRING { $$ = $2; };
+noderef: "(" REFSTRING optanchor ")"
+ {
+ $$.node = assembler->nodeWithName($2);
+ $$.anchor = $3;
+ };
+optnoderef:
+ noderef { $$ = $1; }
+ | "(" ")" { $$.node = 0; $$.anchor = 0; }
+optedgenode:
+ { $$ = 0; }
+ | "node" optproperties DELIMITEDSTRING
+ {
+ // TODO: implement edge-nodes
+ // $$ = [Node node];
+ // if ($2)
+ // [$$ setData:$2];
+ // [$$ setLabel:$3];
+ }
+edge: "\\draw" optproperties noderef "to" optedgenode optnoderef ";"
+ {
+ Node *s;
+ Node *t;
+ Node *en;
+
+ // TODO: anchors and edge nodes
+
+ s = $3.node;
+ if ($6.node) {
+ t = $6.node;
+ //[edge setTargetAnchor:$6.anchor];
+ } else {
+ t = $3.node;
+ //[edge setTargetAnchor:$3.anchor];
+ }
+
+ Edge *edge = assembler->graph()->addEdge(s, t);
+ if ($2)
+ edge->setData($2);
+
+ // [edge setSourceAnchor:$3.anchor];
+ // [edge setEdgeNode:$5];
+
+ // [edge setAttributesFromData];
+ };
+
+ignoreprop: val | val "=" val;
+ignoreprops: ignoreprop ignoreprops | ;
+optignoreprops: "[" ignoreprops "]";
+boundingbox:
+ "\\path" optignoreprops COORD "rectangle" COORD ";"
+ {
+ // TODO: bounding box
+ //[[assembler graph] setBoundingBox:NSRectAroundPoints($3, $5)];
+ };
+
+/* vi:ft=yacc:noet:ts=4:sts=4:sw=4
+*/
diff --git a/tikzit/tikzparserdefs.h b/tikzit/tikzparserdefs.h
new file mode 100644
index 0000000..f721ba5
--- /dev/null
+++ b/tikzit/tikzparserdefs.h
@@ -0,0 +1,2 @@
+// nothing here
+
diff --git a/tikzit/toolpalette.cpp b/tikzit/toolpalette.cpp
index cd939c2..fd06730 100644
--- a/tikzit/toolpalette.cpp
+++ b/tikzit/toolpalette.cpp
@@ -4,12 +4,13 @@
#include <QLayout>
#include <QVBoxLayout>
-ToolPalette::ToolPalette()
+ToolPalette::ToolPalette(QWidget *parent) :
+ QToolBar(parent)
{
setWindowFlags(Qt::Window
- | Qt::WindowTitleHint
| Qt::WindowStaysOnTopHint
- | Qt::CustomizeWindowHint);
+ | Qt::CustomizeWindowHint
+ | Qt::WindowDoesNotAcceptFocus);
setOrientation(Qt::Vertical);
setFocusPolicy(Qt::NoFocus);
diff --git a/tikzit/toolpalette.h b/tikzit/toolpalette.h
index 158f76c..05b2e12 100644
--- a/tikzit/toolpalette.h
+++ b/tikzit/toolpalette.h
@@ -10,7 +10,7 @@ class ToolPalette : public QToolBar
{
Q_OBJECT
public:
- ToolPalette();
+ ToolPalette(QWidget *parent = 0);
private:
QActionGroup *tools;
QAction *select;