/[svn]/linuxsampler/trunk/src/scriptvm/editor/CodeScanner.cpp
ViewVC logotype

Contents of /linuxsampler/trunk/src/scriptvm/editor/CodeScanner.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 3729 - (show annotations) (download)
Fri Jan 31 10:57:53 2020 UTC (4 years, 2 months ago) by schoenebeck
File size: 2260 byte(s)
NKSP parser: track code locations also by raw byte position and length.

* NKSP VM API: Added member variables 'firstByte' and 'lengthBytes' to
  struct 'CodeBlock'.

* NKSP Editor API: Added methods firstByte() and lengthBytes() to
  class 'VMSourceToken'.

* NKSP VM language parser: track all positions also by raw byte offset
  and length (along to the already existing tracking by line/column).

* NKSP editor syntax highlighting scanner: track all positions also by
  raw byte offset and length (along to the already existing tracking by
  line/column).

* Bumped version (2.1.1.svn45).

1 /*
2 * Copyright (c) 2015-2020 Christian Schoenebeck
3 *
4 * http://www.linuxsampler.org
5 *
6 * This file is part of LinuxSampler and released under the same terms.
7 * See README file for details.
8 */
9
10 #include "CodeScanner.h"
11 #include "../../common/global_private.h"
12
13 namespace LinuxSampler {
14
15 CodeScanner::CodeScanner(std::istream* _is)
16 : scanner(NULL), is(_is), line(0), column(0), offset(0), length(0)
17 {
18 }
19
20 CodeScanner::~CodeScanner() {
21 }
22
23 SourceToken CodeScanner::processOneToken() {
24 processScanner();
25 token.line = line;
26 token.column = column;
27 token.offset = offset;
28 token.length = length;
29 return token;
30 }
31
32 void CodeScanner::processAll() {
33 for (SourceToken token = processOneToken(); token; token = processOneToken()) {
34 if (!m_tokens.empty() && token.equalsType(*(m_tokens.end()-1)) && !token.isNewLine())
35 (m_tokens.end()-1)->txt += token.text();
36 else
37 m_tokens.push_back(token);
38 }
39 //trim();
40 }
41
42 bool CodeScanner::isMultiLine() const {
43 for (int i = 0; i < m_tokens.size(); ++i)
44 if (m_tokens[i].isNewLine())
45 return true;
46 return false;
47 }
48
49 void CodeScanner::trim() {
50 // remove initial blank line(s)
51 {
52 std::vector<SourceToken>::iterator lineFeed = m_tokens.end();
53 for (std::vector<SourceToken>::iterator it = m_tokens.begin();
54 it != m_tokens.end(); ++it)
55 {
56 if (it->isNewLine()) {
57 lineFeed = it;
58 } else if (! ::trim(it->text()).empty()) {
59 if (lineFeed != m_tokens.end())
60 m_tokens.erase(m_tokens.begin(), lineFeed+1);
61 break;
62 }
63 }
64 }
65 // remove blank line(s) at end
66 {
67 std::vector<SourceToken>::reverse_iterator lineFeed = m_tokens.rend();
68 for (std::vector<SourceToken>::reverse_iterator it = m_tokens.rbegin();
69 it != m_tokens.rend(); ++it)
70 {
71 if (it->isNewLine()) {
72 lineFeed = it;
73 } else if (! ::trim(it->text()).empty()) {
74 if (lineFeed != m_tokens.rend())
75 m_tokens.erase(--(lineFeed.base()));
76 break;
77 }
78 }
79 }
80 }
81
82 } // namespace LinuxSampler

  ViewVC Help
Powered by ViewVC