| 
									
										
										
										
											2010-04-26 15:12:27 +02:00
										 |  |  | /**************************************************************************
 | 
					
						
							|  |  |  | ** | 
					
						
							|  |  |  | ** This file is part of Qt Creator | 
					
						
							|  |  |  | ** | 
					
						
							| 
									
										
										
										
											2011-01-11 16:28:15 +01:00
										 |  |  | ** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies). | 
					
						
							| 
									
										
										
										
											2010-04-26 15:12:27 +02:00
										 |  |  | ** | 
					
						
							| 
									
										
										
										
											2011-11-02 15:59:12 +01:00
										 |  |  | ** Contact: Nokia Corporation (qt-info@nokia.com) | 
					
						
							| 
									
										
										
										
											2010-04-26 15:12:27 +02:00
										 |  |  | ** | 
					
						
							|  |  |  | ** | 
					
						
							|  |  |  | ** GNU Lesser General Public License Usage | 
					
						
							|  |  |  | ** | 
					
						
							| 
									
										
										
										
											2011-04-13 08:42:33 +02:00
										 |  |  | ** This file may be used under the terms of the GNU Lesser General Public | 
					
						
							|  |  |  | ** License version 2.1 as published by the Free Software Foundation and | 
					
						
							|  |  |  | ** appearing in the file LICENSE.LGPL included in the packaging of this file. | 
					
						
							|  |  |  | ** Please review the following information to ensure the GNU Lesser General | 
					
						
							|  |  |  | ** Public License version 2.1 requirements will be met: | 
					
						
							|  |  |  | ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
 | 
					
						
							| 
									
										
										
										
											2010-04-26 15:12:27 +02:00
										 |  |  | ** | 
					
						
							| 
									
										
										
										
											2010-12-17 16:01:08 +01:00
										 |  |  | ** In addition, as a special exception, Nokia gives you certain additional | 
					
						
							| 
									
										
										
										
											2011-04-13 08:42:33 +02:00
										 |  |  | ** rights. These rights are described in the Nokia Qt LGPL Exception | 
					
						
							| 
									
										
										
										
											2010-12-17 16:01:08 +01:00
										 |  |  | ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. | 
					
						
							|  |  |  | ** | 
					
						
							| 
									
										
										
										
											2011-04-13 08:42:33 +02:00
										 |  |  | ** Other Usage | 
					
						
							|  |  |  | ** | 
					
						
							|  |  |  | ** Alternatively, this file may be used in accordance with the terms and | 
					
						
							|  |  |  | ** conditions contained in a signed written agreement between you and Nokia. | 
					
						
							|  |  |  | ** | 
					
						
							| 
									
										
										
										
											2010-12-17 16:01:08 +01:00
										 |  |  | ** If you have questions regarding the use of this file, please contact | 
					
						
							| 
									
										
										
										
											2011-11-02 15:59:12 +01:00
										 |  |  | ** Nokia at qt-info@nokia.com. | 
					
						
							| 
									
										
										
										
											2010-04-26 15:12:27 +02:00
										 |  |  | ** | 
					
						
							|  |  |  | **************************************************************************/ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #ifndef QMLJSLINEINFO_H
 | 
					
						
							|  |  |  | #define QMLJSLINEINFO_H
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include <qmljs/qmljs_global.h>
 | 
					
						
							|  |  |  | #include <qmljs/qmljsscanner.h>
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include <QtCore/QRegExp>
 | 
					
						
							|  |  |  | #include <QtGui/QTextBlock>
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | namespace QmlJS { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | class QMLJS_EXPORT LineInfo | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     Q_DISABLE_COPY(LineInfo) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | public: | 
					
						
							|  |  |  |     LineInfo(); | 
					
						
							|  |  |  |     virtual ~LineInfo(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     bool isUnfinishedLine(); | 
					
						
							|  |  |  |     bool isContinuationLine(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     void initialize(QTextBlock begin, QTextBlock end); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | protected: | 
					
						
							|  |  |  |     static const int SmallRoof; | 
					
						
							|  |  |  |     static const int BigRoof; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     QString trimmedCodeLine(const QString &t); | 
					
						
							|  |  |  |     QChar firstNonWhiteSpace(const QString &t) const; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     bool hasUnclosedParenOrBracket() const; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     /*
 | 
					
						
							|  |  |  |         The "linizer" is a group of functions and variables to iterate | 
					
						
							|  |  |  |         through the source code of the program to indent. The program is | 
					
						
							|  |  |  |         given as a list of strings, with the bottom line being the line | 
					
						
							|  |  |  |         to indent. The actual program might contain extra lines, but | 
					
						
							|  |  |  |         those are uninteresting and not passed over to us. | 
					
						
							|  |  |  |     */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     bool readLine(); | 
					
						
							|  |  |  |     void startLinizer(); | 
					
						
							|  |  |  |     bool bottomLineStartsInMultilineComment(); | 
					
						
							|  |  |  |     bool matchBracelessControlStatement(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     Token lastToken() const; | 
					
						
							|  |  |  |     QStringRef tokenText(const Token &token) const; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | protected: | 
					
						
							|  |  |  |     struct LinizerState | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         LinizerState() | 
					
						
							|  |  |  |             : braceDepth(0), | 
					
						
							|  |  |  |               leftBraceFollows(false), | 
					
						
							| 
									
										
										
										
											2010-04-30 14:22:55 +02:00
										 |  |  |               pendingRightBrace(false), | 
					
						
							|  |  |  |               insertedSemicolon(false) | 
					
						
							| 
									
										
										
										
											2010-04-26 15:12:27 +02:00
										 |  |  |         { } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         int braceDepth; | 
					
						
							|  |  |  |         bool leftBraceFollows; | 
					
						
							|  |  |  |         bool pendingRightBrace; | 
					
						
							| 
									
										
										
										
											2010-04-30 14:22:55 +02:00
										 |  |  |         bool insertedSemicolon; | 
					
						
							| 
									
										
										
										
											2010-04-26 15:12:27 +02:00
										 |  |  |         QString line; | 
					
						
							|  |  |  |         QList<Token> tokens; | 
					
						
							|  |  |  |         QTextBlock iter; | 
					
						
							|  |  |  |     }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     class Program | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |     public: | 
					
						
							|  |  |  |         Program() {} | 
					
						
							|  |  |  |         Program(QTextBlock begin, QTextBlock end) | 
					
						
							|  |  |  |             : begin(begin), end(end) {} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         QTextBlock firstBlock() const { return begin; } | 
					
						
							|  |  |  |         QTextBlock lastBlock() const { return end; } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     private: | 
					
						
							|  |  |  |         QTextBlock begin, end; | 
					
						
							|  |  |  |     }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     Program yyProgram; | 
					
						
							|  |  |  |     LinizerState yyLinizerState; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     // shorthands
 | 
					
						
							|  |  |  |     const QString *yyLine; | 
					
						
							|  |  |  |     const int *yyBraceDepth; | 
					
						
							|  |  |  |     const bool *yyLeftBraceFollows; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     QRegExp braceX; | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | } // namespace QmlJS
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #endif // QMLJSLINEINFO_H
 | 
					
						
							|  |  |  | 
 |