+++ /dev/null
-// Copyright (C) 2000-2002, Luca Padovani <luca.padovani@cs.unibo.it>.
-//
-// This file is part of GtkMathView, a Gtk widget for MathML.
-//
-// GtkMathView 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.
-//
-// GtkMathView 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 GtkMathView; if not, write to the Free Software
-// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
-//
-// For details, see the GtkMathView World-Wide-Web page,
-// http://www.cs.unibo.it/helm/mml-widget, or send a mail to
-// <luca.padovani@cs.unibo.it>
-
-#ifndef Ptr_hh
-#define Ptr_hh
-
-template <class P>
-class Ptr
-{
-public:
- Ptr(P* p = 0) : ptr(p) { if (ptr != 0) ptr->ref(); }
- Ptr(const Ptr& p) : ptr(p.ptr) { if (ptr != 0) ptr->ref(); }
- ~Ptr() { if (ptr != 0) ptr->unref(); }
-
- P* operator->() const { assert(ptr != 0); return ptr; }
- Ptr& operator=(const Ptr& p)
- {
- if (ptr == p.ptr) return *this;
- if (p.ptr != 0) p.ptr->ref();
- if (ptr != 0) ptr->unref();
- ptr = p.ptr;
- return *this;
- }
-
- operator P*() const { return ptr; }
- template <class Q> friend Ptr<Q> smart_cast(const Ptr& p) { return Ptr<Q>(dynamic_cast<Q*>(p.ptr)); }
- template <class Q> friend bool is_a(const Ptr& p) { return dynamic_cast<Q*>(p.ptr) != 0; }
- template <class Q> operator Ptr<Q>() const { return Ptr<Q>(ptr); }
-
-private:
- P* ptr;
-};
-
-#endif // Ptr_hh
+++ /dev/null
-
-#ifndef __TCharStream_hh__
-#define __TCharStream_hh__
-
-#include "dom.hh"
-
-class TCharStream
-{
-public:
- TCharStream(void) { };
- virtual ~TCharStream() { };
-
- virtual bool more(void) const = 0;
- virtual TChar look(void) const = 0;
- virtual TChar next(void) = 0;
-
- class EmptyStream { };
-};
-
-#endif // __TCharStream_hh__
+++ /dev/null
-
-#ifndef __TCharStreamString_hh__
-#define __TCharStreamString_hh__
-
-#include "TCharStream.hh"
-
-class TCharStreamString : public TCharStream
-{
-public:
- TCharStreamString(const TString& s) : buffer(s), idx(0) { };
- virtual ~TCharStreamString() { };
-
- virtual bool more(void) const { return idx < buffer.length(); };
- virtual TChar look(void) const { if (more()) return buffer[idx]; else throw EmptyStream(); };
- virtual TChar next(void) { if (more()) return buffer[idx++]; else throw EmptyStream(); };
-
-private:
- unsigned long idx;
- TString buffer;
-};
-
-#endif // __TCharStreamString_hh__
+++ /dev/null
-
-#include "TCharStream.hh"
-#include "TCharStreamString.hh"
-
-TToken
-TLexerPull::pop(TCharStream& stream)
-{
- if (stream.more())
- {
- TChar ch = stream.next();
- if (ch == '\\')
- {
- if (stream.more())
- {
- if (isUnicodeAlpha(stream.look()))
- {
- TString s;
- while (stream.more() && isUnicodeAlpha(stream.look()))
- s.push_back(stream.next());
- TToken res(TToken::CONTROL, s);
- while (stream.more() && isUnicodeSpace(stream.look()))
- stream.next();
- return res;
- }
- else
- return TToken(TToken::CONTROL, TString(1, stream.next()));
- }
- else
- return TToken(TToken::INVALID_CHAR, TString(1, ch));
- }
- else return TToken(ch);
- }
- else return TToken(TToken::END_OF_BUFFER);
-}
-
+++ /dev/null
-
-#include "TLexerPush.hh"
-
-TLexerPush::TLexerPush()
-{
- state = ACCEPT;
-}
-
-TToken
-TLexerPush::pop()
-{
- if (tokens.empty()) throw EmptyBuffer();
- else
- {
- TToken res = tokens.front();
- tokens.pop_front();
- if (tokens.size() == 1 && state == CONTROL) state = ACCEPT;
- return res;
- }
-}
-
-TToken
-TLexerPush::front() const
-{
- if (tokens.empty()) throw EmptyBuffer();
- else return tokens.front();
-}
-
-bool
-TLexerPush::empty() const
-{
- return tokens.empty();
-}
-
-bool
-TLexerPush::pending() const
-{
- return state == ESCAPE;
-}
-
-bool
-TLexerPush::ambiguous() const
-{
- return tokens.size() == 1 && state == CONTROL;
-}
-
-void
-TLexerPush::push(TChar ch)
-{
- switch (state)
- {
- case ACCEPT:
- if (ch == '\\') state = ESCAPE;
- else tokens.push_back(TToken(ch));
- break;
- case ESCAPE:
- tokens.push_back(TToken(TToken::CONTROL, std::string(1, ch)));
- if (isUnicodeAlpha(ch)) state = CONTROL;
- else state = ACCEPT;
- break;
- case CONTROL:
- if (ch == '\\') state = ESCAPE;
- else if (isUnicodeAlpha(ch))
- {
- assert(!tokens.empty());
- TToken& tok = tokens.back();
- tok.value.push_back(ch);
- }
- else if (isUnicodeSpace(ch)) state = IGNORE_SPACE;
- else
- {
- tokens.push_back(TToken(ch));
- state = ACCEPT;
- }
- break;
- case IGNORE_SPACE:
- if (ch == '\\') state = ESCAPE;
- else if (isUnicodeSpace(ch)) ;
- else tokens.push_back(TToken(ch));
- break;
- }
-}
+++ /dev/null
-
-#include <deque>
-
-#include "TToken.hh"
-
-class TLexerPush
-{
-public:
- TLexerPush(void);
-
- void push(TChar);
- TToken pop(void);
- TToken front(void) const;
- bool ambiguous(void) const;
- bool pending(void) const;
- bool empty(void) const;
-
- class EmptyBuffer { };
-
-private:
- enum State
- {
- ACCEPT,
- ESCAPE,
- CONTROL,
- IGNORE_SPACE
- };
-
- State state;
- std::deque<TToken> tokens;
-};
+++ /dev/null
-
-#ifndef __TObject_hh__
-#define __TObject_hh__
-
-class TObject
-{
-protected:
- TObject(void) { refCounter = 1; };
- virtual ~TObject() { };
-
-public:
- void ref(coid) const { refCounter++; };
- void unref(void) const { if (--refCounter) delete this; };
-};
-
-#endif // __TObject_hh__
void
TPushParser::do_letter(const std::string& s)
{
- TNode parent = cursor.parent();
+ //TNode parent = cursor.parent();
TNode elem = doc.createI(s, nextId++);
cursor.replace(elem);
advance(elem);
};
std::stack<Frame> frames;
- std::list<TToken> buffer;
+ //std::list<TToken> buffer;
unsigned nextId;
TDocument doc;
TNode cursor;
+++ /dev/null
-
-DOM::Element
-getRightmostChild(const DOM::Element& p)
-{
- if (p)
- {
- if (DOM::Element last = g.get_lastChild())
- if (last.get_nodeName() == "g" && last.get_firstChild())
- return getRightmostChild(last);
- else
- return last;
- else
- return 0;
- }
- else
- return 0;
-}
-
-DOM::Element
-prevLinearSibling(const DOM::Element& p)
-{
- if (p)
- {
- DOM::Element prev = p.get_prevSibling();
- if (!prev) return 0;
- else if (prev.get_nodeName() != "g" && prev.get_firstChild()) return prev;
- else return prevLinearSibling(prev.get_lastChild());
- }
- else
- return 0;
-}
-
-DOM::Element
-getCore(const DOM::Element& p)
-{
- if (p)
- {
- if (p.get_nodeName() == "sb" || p.get_nodeName() == "sp")
- return getCore(p.get_firstChild());
- else return p;
- }
- else
- return 0;
-}
-
-void
-replace(const DOM::Element& p0, const DOM::Element& p1)
-{
- if (DOM::Element parent = p0.get_parentNode())
- parent.replaceChild(p0, p1);
-}
-
-bool
-isInferred(const DOM::Element& p)
-{
- if (p) return p.hasAttribute("id");
- else return false;
-}
-
-bool
-isMacro(const DOM::Element& p, const TString& s)
-{
- return p && p.get_nodeName() == "m" && p.getAttribute("name") == s;
-}
-
-bool
-isGroup(const DOM::Element& p)
-{
- return p && p.get_nodeName() == "g";
-}
-
-bool
-isSb(const DOM::Element& p)
-{
- return p && p.get_nodeName() == "sb";
-}
-
-bool
-isSp(const DOM::Element& p)
-{
- return p && p.get_nodeName() == "sp";
-}
-
-bool
-isPrimes(const DOM::Element& p)
-{
- return isGroup(p) && isMacro(p.get_lastChild, "prime");
-}
-
-bool
-isOperator(const DOM::Element& p)
-{
- if (DOM::Element core = getCore(p))
- return dictionary.isOperator(core.get_nodeName());
- else
- return false;
-}
-
-bool
-isDelimiter(const DOM::Element& p)
-{
- if (DOM::Element core = getCore(p))
- return dictionary.isDelimiter(core.get_nodeName());
- else
- return false;
-}
-
-bool
-isFunction(const DOM::Element& p)
-{
- if (DOM::Element core = getCore(p))
- return dictionary.isFunction(core.get_nodeName());
- else
- return false;
-}
+++ /dev/null
-
-#include <list>
-
-#include "dom.hh"
-#include "globals.hh"
-#include "TNode.hh"
-#include "TToken.hh"
-
-void finishG(const TNode&);
-
-void
-do_bgroup(const TNode& cursor)
-{
- TNode parent = cursor.parent();
- if (parent.isM("matrix") || parent.isM("pmatrix") ||
- parent.isM("bordermatrix") || parent.isM("cases"))
- {
- TNode row = cursor.create("row");
- TNode cell = cursor.create("cell");
- TNode g = cursor.createG();
- row.append(cell);
- cell.append(g);
- g.append(cursor);
- parent.append(row);
- }
- else
- {
- TNode g = cursor.createG();
- cursor.replace(g);
- g.append(cursor);
- }
-}
-
-
-
-
-void
-do_apostrophe(const TNode& cursor)
-{
-}
-
-void
-do_control(const TNode& cursor, const std::string& name)
-{
-}
-
-void
-do_other(const TNode& cursor, const std::string& s)
-{
- switch (s[0])
- {
- case '\'': do_apostrophe(cursor); break;
- default:
- if (isUnicodeDigit(s[0])) do_number(cursor, s);
- else do_control(cursor, s);
- }
-}
-
-void
-dispatch(const TNode& cursor, const TToken& token)
-{
-
+++ /dev/null
-
-#include "dom.hh"
-#include "TLexerPush.hh"
-
-main()
-{
- std::string s;
- while (getline(std::cin, s))
- {
- TLexerPush lexer;
- for (unsigned long i = 0; i < s.length(); i++)
- {
- lexer.push(s[i]);
- cout << "pending: " << lexer.pending()
- << " amb: " << lexer.ambiguous();
- if (!lexer.empty())
- {
- TToken tok = lexer.front();
- DOM::GdomeString v(tok.value);
- cout << " cat: " << tok.category << " value: " << v << " length: " << v.length();
- if (!lexer.ambiguous()) lexer.pop();
- }
- cout << endl;
- }
- }
-}
+++ /dev/null
-
-#ifndef __tokenzier_hh__
-#define __tokenzier_hh__
-
-#include <string>
-#include <vector>
-
-std::vector<TToken> tokenize(const std::string&);
-
-#endif // __tokenzier_hh__
#include <gtk/gtk.h>
#include <gdk/gdkkeysyms.h>
-#include "gtkmathview.h"
+#include <gtkmathview/gtkmathview.h>
#include "guiGTK.h"
#define XLINK_NS_URI "http://www.w3.org/1999/xlink"
#include <glib.h>
-#include "gtkmathview.h"
+#include <gtkmathview/gtkmathview.h>
#ifdef __cplusplus
extern "C" {