From c16e9f4ed97f65357e9986f46ad88ee9f2237997 Mon Sep 17 00:00:00 2001 From: Andras Timar Date: Fri, 15 Feb 2013 13:02:10 +0100 Subject: Move SyntaxHighlighter class from svtools to comphelper We use this class in helpcompiler, and it is not desirable to compile svtools (thus half of LibreOffice) for a build tool in cross-compiling environment. Change-Id: I5e6bc3e576af41eb03c1420dd347c542306f69fa --- comphelper/inc/comphelper/syntaxhighlight.hxx | 165 ++++++++++++++++++++++++++ 1 file changed, 165 insertions(+) create mode 100644 comphelper/inc/comphelper/syntaxhighlight.hxx (limited to 'comphelper/inc') diff --git a/comphelper/inc/comphelper/syntaxhighlight.hxx b/comphelper/inc/comphelper/syntaxhighlight.hxx new file mode 100644 index 000000000000..11a57db6ff05 --- /dev/null +++ b/comphelper/inc/comphelper/syntaxhighlight.hxx @@ -0,0 +1,165 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ +#ifndef _COMPHELPER_SYNTAXHIGHLIGHT_HXX +#define _COMPHELPER_SYNTAXHIGHLIGHT_HXX + +#include +#include + +#include + + +#if defined CDECL +#undef CDECL +#endif + +// for the bsearch +#ifdef WNT +#define CDECL _cdecl +#endif +#if defined(UNX) +#define CDECL +#endif +#ifdef UNX +#include +#endif + + +// Token-Typen TT_... +enum TokenTypes +{ + TT_UNKNOWN, + TT_IDENTIFIER, + TT_WHITESPACE, + TT_NUMBER, + TT_STRING, + TT_EOL, + TT_COMMENT, + TT_ERROR, + TT_OPERATOR, + TT_KEYWORDS, + TT_PARAMETER +}; + +struct HighlightPortion { sal_uInt16 nBegin; sal_uInt16 nEnd; TokenTypes tokenType; }; + + +typedef std::vector HighlightPortions; + +///////////////////////////////////////////////////////////////////////// +// Hilfsklasse zur Untersuchung von JavaScript-Modulen, zunaechst zum +// Heraussuchen der Funktionen, spaeter auch zum Syntax-Highlighting verwenden + +// Flags fuer Zeichen-Eigenschaften +#define CHAR_START_IDENTIFIER 0x0001 +#define CHAR_IN_IDENTIFIER 0x0002 +#define CHAR_START_NUMBER 0x0004 +#define CHAR_IN_NUMBER 0x0008 +#define CHAR_IN_HEX_NUMBER 0x0010 +#define CHAR_IN_OCT_NUMBER 0x0020 +#define CHAR_START_STRING 0x0040 +#define CHAR_OPERATOR 0x0080 +#define CHAR_SPACE 0x0100 +#define CHAR_EOL 0x0200 + +#define CHAR_EOF 0x00 + + +// Sprachmodus des HighLighters (spaeter eventuell feiner +// differenzieren mit Keyword-Liste, C-Kommentar-Flag) +enum HighlighterLanguage +{ + HIGHLIGHT_BASIC, + HIGHLIGHT_SQL +}; + +class SimpleTokenizer_Impl +{ + HighlighterLanguage aLanguage; + // Zeichen-Info-Tabelle + sal_uInt16 aCharTypeTab[256]; + + const sal_Unicode* mpStringBegin; + const sal_Unicode* mpActualPos; + + // Zeile und Spalte + sal_uInt32 nLine; + sal_uInt32 nCol; + + sal_Unicode peekChar( void ) { return *mpActualPos; } + sal_Unicode getChar( void ) { nCol++; return *mpActualPos++; } + + // Hilfsfunktion: Zeichen-Flag Testen + sal_Bool testCharFlags( sal_Unicode c, sal_uInt16 nTestFlags ); + + // Neues Token holen, Leerstring == nix mehr da + sal_Bool getNextToken( /*out*/TokenTypes& reType, + /*out*/const sal_Unicode*& rpStartPos, /*out*/const sal_Unicode*& rpEndPos ); + + const char** ppListKeyWords; + sal_uInt16 nKeyWordCount; + +public: + SimpleTokenizer_Impl( HighlighterLanguage aLang = HIGHLIGHT_BASIC ); + ~SimpleTokenizer_Impl( void ); + + sal_uInt16 parseLine( sal_uInt32 nLine, const OUString* aSource ); + void getHighlightPortions( sal_uInt32 nParseLine, const OUString& rLine, + /*out*/HighlightPortions& portions ); + void setKeyWords( const char** ppKeyWords, sal_uInt16 nCount ); +}; + + +//*** SyntaxHighlighter-Klasse *** +// Konzept: Der Highlighter wird ueber alle Aenderungen im Source +// informiert (notifyChange) und liefert dem Aufrufer jeweils die +// Information zurueck, welcher Zeilen-Bereich des Source-Codes +// aufgrund dieser Aenderung neu gehighlighted werden muss. +// Dazu merkt sich Highlighter intern fuer jede Zeile, ob dort +// C-Kommentare beginnen oder enden. +class COMPHELPER_DLLPUBLIC SyntaxHighlighter +{ + HighlighterLanguage eLanguage; + SimpleTokenizer_Impl* m_pSimpleTokenizer; + char* m_pKeyWords; + sal_uInt16 m_nKeyWordCount; + +// void initializeKeyWords( HighlighterLanguage eLanguage ); + +public: + SyntaxHighlighter( void ); + ~SyntaxHighlighter( void ); + + // HighLighter (neu) initialisieren, die Zeilen-Tabelle wird + // dabei komplett geloescht, d.h. im Abschluss wird von einem + // leeren Source ausgegangen. In notifyChange() kann dann + // nur Zeile 0 angegeben werden. + void initialize( HighlighterLanguage eLanguage_ ); + + void notifyChange( sal_uInt32 nLine, sal_Int32 nLineCountDifference, + const OUString* pChangedLines, sal_uInt32 nArrayLength); + + void getHighlightPortions( sal_uInt32 nLine, const OUString& rLine, + HighlightPortions& pPortions ); + + HighlighterLanguage GetLanguage() { return eLanguage;} +}; +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ -- cgit eoffice-7-3+backports LibreOffice 核心代码仓库文档基金会
summaryrefslogtreecommitdiff
AgeCommit message (Expand)Author
2018-07-16Add missing sal/log.hxx headersGabor Kelemen
2017-08-31Replace some lists by vectors (+rename vars)Julien Nabet
2017-02-15Drop :: prefix from std in c*/Tor Lillqvist
2016-12-13OSL_TRACE->SAL in chart2..ooxNoel Grandin
2016-07-04comphelper::OBaseMutex -> cppu::BaseMutexNoel Grandin
2016-05-30com::sun::star->css in connectivityNoel Grandin
2016-02-09Remove excess newlinesChris Sherlock
2015-10-30use uno::Reference::set method instead of assignmentNoel Grandin
2015-07-17tdf#88206 replace cppu::WeakImplHelper* etc.Takeshi Abe
2015-06-15cppcheck: noExplicitConstructorCaolán McNamara
2015-05-17Remove include stdio (part1)Julien Nabet
2015-04-15remove unnecessary use of void in function declarationsNoel Grandin
2014-11-06Revert "use the new OUString::fromUtf8 method"Stephan Bergmann
2014-11-06use the new OUString::fromUtf8 methodNoel Grandin
2014-10-06drop connectivity testmoz workbenCaolán McNamara
2014-09-22fdo#84086 Fix assorted use-after-free bugsMatthew J. Francis
2014-06-06fixincludeguards: fix include guardsThomas Arnhold
2014-06-05connectivity: remove SAL_THROW macroNoel Grandin
2014-06-04connectivity: fix includesThomas Arnhold
2014-04-30Many spelling fixes: directories a* - g*.Pedro Giffuni
2014-02-27Remove visual noise from connectivityAlexander Wilms
2013-11-11remove unnecessary use of OUString constructorNoel Grandin
2013-11-11remove unnecessary use of OUString constructor in CONNECTIVITY moduleNoel Grandin
2013-10-12Bin bogus use of UNX (in not compiled test code)Tor Lillqvist
2013-06-29remove OUString wrap for string literalsThomas Arnhold
2013-04-07mass removal of rtl:: prefixes for O(U)String*Luboš Luňák