summaryrefslogtreecommitdiffstats
path: root/languages/pascal/backgroundparser.cpp
blob: ff2023741eb4175e3c93d24e0937cb31880aa62a (plain)
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
/***************************************************************************
 *   Copyright (C) 2002 by Roberto Raggi                                   *
 *   roberto@kdevelop.org                                                 *
 *                                                                         *
 *   This program 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.                                   *
 *                                                                         *
 ***************************************************************************/

#include <sstream>

#include "backgroundparser.h"
#include "problemreporter.h"
#include "PascalLexer.hpp"
#include "PascalParser.hpp"
#include "PascalAST.hpp"
#include <kdebug.h>
#include <tqfile.h>
#include <antlr/ASTFactory.hpp>

BackgroundParser::BackgroundParser( ProblemReporter* reporter,
                                    const TQString& source,
                                    const TQString& filename )
    : m_reporter( reporter ),
      m_source( source.unicode(), source.length() ),
      m_fileName( filename )
{
}

BackgroundParser::~BackgroundParser()
{
}

void BackgroundParser::run()
{
    kdDebug() << "11" << endl;

    TQCString _fn = TQFile::encodeName(m_fileName);
    std::string fn( _fn.data() );

    TQCString text = m_source.utf8();
    std::istringstream stream( text.data() );

    kdDebug() << "12" << endl;

    PascalLexer lexer( stream );
    lexer.setFilename( fn );
    lexer.setProblemReporter( m_reporter );

    kdDebug() << "13" << endl;

    PascalParser parser( lexer );
    parser.setFilename( fn );
    parser.setProblemReporter( m_reporter );

        antlr::ASTFactory my_factory( "PascalAST", PascalAST::factory );
        parser.initializeASTFactory(my_factory);
        parser.setASTFactory( &my_factory );

    kdDebug() << "14" << endl;

    try{

        kdDebug() << "15" << endl;

        lexer.resetErrors();
        parser.resetErrors();

        kdDebug() << "16" << endl;

        parser.compilationUnit();

        kdDebug() << "17" << endl;

        int errors = lexer.numberOfErrors() + parser.numberOfErrors();

        kdDebug() << "18" << endl;
    } catch( antlr::ANTLRException& ex ){

        kdDebug() << "19" << endl;

        kdDebug() << "*exception*: " << ex.toString().c_str() << endl;
        m_reporter->reportError( ex.getMessage().c_str(),
            m_fileName,
            lexer.getLine(),
            lexer.getColumn() );
    }

    kdDebug(9013) << "FINISHED!!" << endl;
}