File: SSyntax.h

package info (click to toggle)
yudit 3.1.0-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 18,472 kB
  • sloc: cpp: 76,344; perl: 5,630; makefile: 989; ansic: 823; sh: 441
file content (144 lines) | stat: -rw-r--r-- 4,621 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
/** 
 *  Yudit Unicode Editor Source File
 *
 *  GNU Copyright (C) 1997-2023  Gaspar Sinai <gaspar@yudit.org>  
 *
 *  This program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License, version 2,
 *  dated June 1991. See file COPYYING for details.
 *
 *  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, write to the Free Software
 *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 */
 
#ifndef SSyntax_h
#define SSyntax_h

#include "stoolkit/STextData.h"
#include "stoolkit/SBinVector.h"
#include "stoolkit/SBinHashtable.h"
#include "stoolkit/SVector.h"
#include "stoolkit/SString.h"
#include "stoolkit/SStringVector.h"
#include "stoolkit/SLineTracker.h"
#include "stoolkit/SEvent.h"
#include "stoolkit/syntax/SMatcher.h"
#include "stoolkit/syntax/SSyntaxMarker.h"

// This many characters are processed, or this many unit works
// are performed in each timer call.
#define SD_UNIT_WORK_COUNT 100

class SSyntaxListener
{
public:
  enum SS_EventType { SD_PARSING_STARTED, SD_PARSING_INSERT, SD_PARSING_DONE };
  SSyntaxListener (void) {}
  virtual ~SSyntaxListener () {}
  virtual void syntaxChanged (SS_EventType _evnt)=0;
};

class SSyntaxState
{
public:
  // Context will delete the objects in args when destructed
  SSyntaxState (SMatcher* _matcher, SSyntaxMarker* _marker, STimer* _timer)
    : matcher (_matcher), marker (_marker), timer (_timer) 
    {
    }
  ~SSyntaxState ()
    { delete timer; delete marker; delete matcher; }
  STextIndex getCurrentIndex  ()
    { return marker->getCurrentIndex (); }
  SMatcher*       matcher;
  SSyntaxMarker*  marker;
  STimer*         timer;
};

// SExentTarget is for crawling timeout
class SSyntax : public SLineTracker, public SEventTarget
{
public:
  // color is a precious resource, we have only 
  // a limited number of them here.
  // The number of charactrers that are cached are
  // determined by SAwt constructor cacheSize=2000

  // We have a shadow version of these in  SSyntaxMarker
  enum SS_Tag { SD_NONE=0, SD_ERROR, 
       SD_NUMBER, SD_STRING, SD_COMMENT, SD_KEYWORD, 
       SD_VARIABLE, SD_DEFINE, SD_CONTROL, SD_OTHER, SD_MAX };
  SSyntax (void);
  ~SSyntax ();

  bool setSyntax (const SString&  ps); 
  const SString& getParser () const; 

  void setTextData (const STextData* td); 

  /* by lines raw index */
  SS_Tag getTag (const STextIndex& index);
  /* get text data index */
  SS_Tag getTagByTDI (const STextIndex& index);

  virtual void lineRemoved (void* src, unsigned int index);
  virtual void lineInserted (void* src, unsigned int index);
  virtual void lineChanged (void* src, unsigned int index);

  // The patch for the syntax files.
  static void setPath(const SStringVector &p);
  static void guessPath();
  static const SStringVector& getPath();

  static bool isSupported (const SString& syn);

  // This will get called from time-to-time 
  // when this class crawls text and parses
  // Only whole lines will changed.
  void addTextDataListener (STextDataListener* _listener);
  void addSyntaxListener (SSyntaxListener* _listener);

  static SString       getMissingFile (const SString& name);
  static SString       getFolderFor (const SString& name);
  static SStringVector getCategories ();
  static SStringVector getAvaliableList (const SString& category);
  static SString       getLibraryLocation ();

private:
  STextDataListener*       listener;
  SSyntaxListener*         syntaxListener;
  const STextData*         textData;
  SSyntaxState*            syntaxState;

  void clear ();
  void clearIterator ();
  void lineGlobalChange ();
  void applyActions ();

  // do another iteration of syntax checking
  virtual bool timeout (const SEventSource* s);

  // if ndx is a move back restart parsing.
  // if parse is "" delete parsing
  // ndx is our index, not datamodel index.
  void updateSyntaxState (const STextIndex ndx);

  SString                 parser;
  SPattern*               pattern;

  // These two are in sync. They contain the full expanded line
  SSyntaxData             syntaxLines;
  SUnicodeData            dataLines;
  // for consecutive getTagByTDI
  STextIndex              iteratorSyntaxIndex;  // syntaxLines, dataLines
  STextIndex              iteratorDataIndex;    // textData
  
};

#endif /* SSyntax */