SVN commit 685314 by apaku:
Adapt to the latest change in kdevelop-pg and provide char*
tokenText(std::size_t begin) functions in the ruby and
python parsers.
Along the way updated the ruby parser to use the kdev-pg-*
headers from
KDevelop-PG and also make the parser library a shared lib.
CC'ing kdevelop-devel to bring this to the attention of the
SoC students
(although they should only need a rebuild).
CCMAIL:kdevelop-devel kdevelop.org
M +8 -8 python/parser/decoder.h
M +13 -4 python/parser/python.g
M +4 -2 python/parser/python_io.cpp
M +6 -1 ruby/CMakeLists.txt
M +3 -4 ruby/parser/CMakeLists.txt
M +8 -8 ruby/parser/decoder.h
D ruby/parser/kdev-pg-allocator.h
D ruby/parser/kdev-pg-list.h
D ruby/parser/kdev-pg-location-table.h
D ruby/parser/kdev-pg-memory-pool.h
D ruby/parser/kdev-pg-replacement.h
D ruby/parser/kdev-pg-token-stream.h
M +1 -1 ruby/parser/main.cpp
M +2 -2 ruby/parser/parsesession.h
M +12 -0 ruby/parser/ruby.g
M +1 -1 ruby/parser/ruby_io.cpp
A ruby/parser/rubyparserexport.h [License:
GPL (v2+)]
---
trunk/playground/devtools/kdevelop4-extra-plugins/python/par
ser/decoder.h #685313:685314
 -34,28
+34,28 
class decoder
{
- parser::token_stream_type *_M_token_stream;
+ parser* _M_parser;
public:
- decoder(parser::token_stream_type *token_stream)
- : _M_token_stream(token_stream) {}
+ decoder(parser *parser)
+ : _M_parser(parser) {}
int decode_kind(std::size_t index) const
{
- parser::token_type const &tk =
_M_token_stream->token(index);
+ parser::token_type const &tk =
_M_parser->token_stream->token(index);
return tk.kind;
}
std::string decode_string(std::size_t index) const
{
- parser::token_type const &tk =
_M_token_stream->token(index);
- return std::string(&tk.text[tk.begin], tk.end -
tk.begin);
+ parser::token_type const &tk =
_M_parser->token_stream->token(index);
+ return std::string(_M_parser->tokenText(tk.begin),
tk.end - tk.begin);
}
long decode_number(std::size_t index) const
{
- parser::token_type const &tk =
_M_token_stream->token(index);
- return ::strtol(&tk.text[tk.begin], 0, 0);
+ parser::token_type const &tk =
_M_parser->token_stream->token(index);
+ return ::strtol(_M_parser->tokenText(tk.begin), 0,
0);
}
};
---
trunk/playground/devtools/kdevelop4-extra-plugins/python/par
ser/python.g #685313:685314
 -141,9
+141,15 
};
void report_problem( parser::problem_type type, const
char* message );
void report_problem( parser::problem_type type,
std::string message );
+ char* tokenText(std::size_t begin);
:]
+%parserclass (private declaration)
+[:
+ char* m_contents;
+:]
+
-----------------------------------------------------------
-- List of defined tokens
-----------------------------------------------------------
 -579,6
+585,7 
void parser::tokenize( char *contents )
{
+ m_contents = contents;
Lexer lexer( this, contents );
int kind = parser::Token_EOF;
 -593,7
+600,6 
t.kind = kind;
t.begin = lexer.tokenBegin();
t.end = lexer.tokenEnd();
- t.text = contents;
std::cerr<<t.kind<<std::endl;
while(lexer.dedentationLevel()>1)
{
 -601,7
+607,6 
t.kind = parser::Token_DEDENT;
t.begin = lexer.tokenBegin();
t.end = lexer.tokenEnd();
- t.text = contents;
std::cerr<<t.kind<<std::endl;
lexer.setDedentationLevel(lexer.dedentationLevel()-1);
}
 -616,7
+621,6 
t.kind = kind;
t.begin = lexer.tokenBegin();
t.end = lexer.tokenEnd();
- t.text = contents;
std::cerr<<t.kind<<std::endl;
kind = x;
}
 -630,7
+634,6 
t.kind = kind;
t.begin = lexer.tokenBegin();
t.end = lexer.tokenEnd();
- t.text = contents;
}
while ( kind != parser::Token_EOF );
 -638,6
+641,12 
}
+char* parser::tokenText(std::size_t begin)
+{
+ return &m_contents[begin];
+}
+
+
} // end of namespace cool
:]
---
trunk/playground/devtools/kdevelop4-extra-plugins/python/par
ser/python_io.cpp #685313:685314
 -43,7
+43,7 
if (done)
return; // don't print with each call when going up
the error path
- decoder dec(parser->token_stream);
+ decoder dec(parser);
int current_index = parser->token_stream->index()
- 1;
for (int i = current_index - 5; i < current_index +
5; i++)
 -115,7
+115,7 
token_stream->start_position(index, &line,
&col);
size_t tokenLength = token.end - token.begin;
char *tokenValue = new char[tokenLength+1];
- strncpy(tokenValue, token.text + token.begin,
tokenLength);
+ strncpy(tokenValue, tokenText(token.begin),
tokenLength);
tokenValue[tokenLength] = 0;
std::stringstream s;
s << " (current token: ""
<< (token.kind != 0 ? tokenValue : "EOF")
<<
 -127,6
+127,8 
+ "''" + s.str()
);
+ delete tokenValue;
+
}
} // end of namespace python
---
trunk/playground/devtools/kdevelop4-extra-plugins/ruby/CMake
Lists.txt #685313:685314
 -10,16
+10,21 
endif( KDEVPG_DATA_DIR )
find_package(KDE4 REQUIRED)
+find_package(KDevPlatform REQUIRED)
add_subdirectory(parser)
add_subdirectory(tests)
include_directories(
- $
+ $/interfaces
+ $/language
+ $/language/backgroundparser
+ $/language/interfaces
$
$/threadweaver
$/parser
$/parser
+ $
)
link_directories( $ )
---
trunk/playground/devtools/kdevelop4-extra-plugins/ruby/parse
r/CMakeLists.txt #685313:685314
 -1,10
+1,8 
find_package(KDevelop-PG)
-include_directories( $
$ )
+include_directories( $ $
$ $
$ )
-add_definitions(-fPIC)
-
########### next target ###############
set(kdevrubyparser_STAT_SRCS
 -154,7
+152,8 
kde4_automoc($)
-kde4_add_library(kdevrubyparser STATIC
$)
+kde4_add_library(kdevrubyparser SHARED
$)
+target_link_libraries(kdevrubyparser $)
# generate the command-line parser
add_executable(ruby-parser main.cpp)
---
trunk/playground/devtools/kdevelop4-extra-plugins/ruby/parse
r/decoder.h #685313:685314
 -34,28
+34,28 
class decoder
{
- parser::token_stream_type *_M_token_stream;
+ parser *_M_parser;
public:
- decoder(parser::token_stream_type *token_stream)
- : _M_token_stream(token_stream) {}
+ decoder(parser *parser)
+ : _M_parser(parser) {}
int decode_kind(std::size_t index) const
{
- parser::token_type const &tk =
_M_token_stream->token(index);
+ parser::token_type const &tk =
_M_parser->token_stream->token(index);
return tk.kind;
}
std::string decode_string(std::size_t index) const
{
- parser::token_type const &tk =
_M_token_stream->token(index);
- return std::string(&tk.text[tk.begin], tk.end -
tk.begin);
+ parser::token_type const &tk =
_M_parser->token_stream->token(index);
+ return std::string(_M_parser->tokenText(tk.begin),
tk.end - tk.begin);
}
long decode_number(std::size_t index) const
{
- parser::token_type const &tk =
_M_token_stream->token(index);
- return ::strtol(&tk.text[tk.begin], 0, 0);
+ parser::token_type const &tk =
_M_parser->token_stream->token(index);
+ return ::strtol(_M_parser->tokenText(tk.begin), 0,
0);
}
};
---
trunk/playground/devtools/kdevelop4-extra-plugins/ruby/parse
r/main.cpp #685313:685314
 -44,7
+44,7 
if (done)
return; // don't print with each call when going up
the error path
- decoder dec(parser->token_stream);
+ decoder dec(parser);
std::size_t current_index =
parser->token_stream->index() - 1;
for (std::size_t i = current_index - 5; i <
current_index + 5; i++)
---
trunk/playground/devtools/kdevelop4-extra-plugins/ruby/parse
r/parsesession.h #685313:685314
 -25,14
+25,14 
#include <QtCore/QByteArray>
#include "ruby_parser.h"
+#include "rubyparserexport.h"
-
namespace ruby
{
/// Contains everything needed to keep an AST useful once
the rest of the parser
/// has gone away.
-class ParseSession
+class KDEVRUBYPARSER_EXPORT ParseSession
{
public:
ParseSession();
---
trunk/playground/devtools/kdevelop4-extra-plugins/ruby/parse
r/ruby.g #685313:685314
 -56,6
+56,9 
-----------------------------------------------------------
-
[:
+
+#include "rubyparserexport.h"
+
namespace ruby
{
class Lexer;
 -84,6
+87,7 
void report_problem( parser::problem_type type, const
char* message );
void report_problem( parser::problem_type type,
std::string message );
+ char* tokenText(std::size_t begin);
:]
 -106,6
+110,7 
bool expect_array_or_block_arguments;
Lexer *m_lexer;
+ char* m_contents;
:]
 -1062,6
+1067,7 
void parser::tokenize( char *contents )
{
+ m_contents = contents;
m_lexer = new Lexer( this, contents );
int kind = parser::Token_EOF;
 -1098,6
+1104,12 
_M_state.ltCounter = state->ltCounter;
}
+
+char* parser::tokenText(std::size_t begin)
+{
+ return &m_contents[begin];
+}
+
} // end of namespace ruby
:]
---
trunk/playground/devtools/kdevelop4-extra-plugins/ruby/parse
r/ruby_io.cpp #685313:685314
 -72,7
+72,7 
token_stream->start_position(index, &line,
&col);
size_t tokenLength = token.end - token.begin;
char *tokenValue = new char[tokenLength+1];
- strncpy(tokenValue, token.text + token.begin,
tokenLength);
+ strncpy(tokenValue, tokenText(token.begin),
tokenLength);
tokenValue[tokenLength] = 0;
std::stringstream s;
s << " (current token: ""
<< (token.kind != 0 ? tokenValue : "EOF")
<<
_______________________________________________
KDevelop-devel mailing list
KDevelop-devel kdevelop.org
https://barney.cs.uni-potsdam.de/mailman/listinf
o/kdevelop-devel
|