1 /**
2  *  Yudit Unicode Editor Source File
3  *
4  *  GNU Copyright (C) 1997-2006  Gaspar Sinai <gaspar@yudit.org>
5  *
6  *  This program is free software; you can redistribute it and/or modify
7  *  it under the terms of the GNU General Public License, version 2,
8  *  dated June 1991. See file COPYYING for details.
9  *
10  *  This program is distributed in the hope that it will be useful,
11  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  *  GNU General Public License for more details.
14  *
15  *  You should have received a copy of the GNU General Public License
16  *  along with this program; if not, write to the Free Software
17  *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18  */
19 
20 #ifndef SSyntaxMarker_h
21 #define SSyntaxMarker_h
22 
23 #include "stoolkit/STextData.h"
24 #include "stoolkit/SBinVector.h"
25 #include "stoolkit/SBinHashtable.h"
26 #include "stoolkit/SVector.h"
27 #include "stoolkit/SLineTracker.h"
28 #include "stoolkit/syntax/SMatcher.h"
29 #include "stoolkit/SBinHashtable.h"
30 
31 // The first 0xFFFF mask bytes are real syntax
32 // the 0xFFFF0000 mask bytes are shadow syntax
33 // the upper ones are free
34 #define SGC_BEGIN_MARK 0x10000
35 
36 class SSyntaxMarker : public SMatcherIterator, public SMatcherAction
37 {
38 public:
39   // lines is the syntax markup line
40   // textdata is the matching text
41   // around is from where sync happens
42   SSyntaxMarker (SSyntaxData& syntaxLines, const SUnicodeData& dataLines,
43      const STextIndex& around);
44 
45   virtual ~SSyntaxMarker ();
46   /* must be called at the end to get minModified and maxModified */
47 
48   // This only knows about positions that were read via getNextCharacter()
49   STextIndex position2Index (unsigned int position);
50   int getCharAt (const STextIndex& in) const;
51   int getSyntaxAt (const STextIndex& in) const;
52   bool setSyntaxAt (const STextIndex& in, int syn);
getCurrentIndex()53   STextIndex getCurrentIndex () const
54     { return STextIndex (currentIndex); }
55 
56   // you need to enclose applyAction statements with these,
57   // to get minModified and maxModified.
58   void beginActionBlock ();
59   void endActionBlock ();
60 
61   STextIndex               minModified;
62   STextIndex               maxModified;
63 
64 
65 private:
66   /* SMatcherIterator */
67   virtual int  getNextCharacter ();
68   /* SMatcherAction */
69   virtual void applyAction (const SString& name,
70     unsigned int markFrom, unsigned int  markTill);
71 
72   bool decrement (STextIndex* in);
73   bool increment (STextIndex* in);
74   unsigned int getLineSize  (unsigned int lineno) const;
75   bool isEOD (const STextIndex& idx) const;
76 
77   SSyntaxData&             syntaxLines;
78   const SUnicodeData&      dataLines;
79 
80   /* for SMatcherIterator */
81   STextIndex               startIndex;
82   STextIndex               currentIndex;
83   bool                     isStarted;
84 
85   /* for matcherMarkCurrentPosition */
86   SBinVector<unsigned int> lineSizes;
87   SBinHashtable<int>       actionMap;
88 
89 };
90 
91 #endif /* SSyntaxMarket_h */
92