8#include <QtCore/QDebug>
10#include <QtCore/QStack>
11#include <QtCore/QStack>
12#include <QtCore/QString>
13#include <QtCore/QCoreApplication>
14#include <QtCore/QStringConverter>
15#include <QtCore/QTextStream>
23using namespace Qt::Literals::StringLiterals;
50
51
52
78 return std::cerr << qPrintable(yyFileName) <<
':' << (line ? line :
yyLineNo) <<
": ";
83 if (
yyInPos >= yyInStr.size()) {
95 const char tab[] =
"bfnrt\"\'\\";
96 const char backTab[] =
"\b\f\n\r\t\"\'\\";
105 if (
yyCh.isLetter() || yyCh.toLatin1() ==
'_' ) {
109 }
while ( yyCh.isLetterOrNumber() || yyCh.toLatin1() ==
'_' );
112 switch (
yyIdent.at(0).toLatin1() ) {
114 if (yyIdent ==
"return"_L1)
118 if (yyIdent ==
"class"_L1)
122 if (yyIdent ==
"null"_L1)
127 switch (
yyIdent.at(0).toLatin1() ) {
129 if (yyIdent ==
"package"_L1)
133 if (yyIdent ==
"tr"_L1)
135 if (yyIdent ==
"translate"_L1)
140 switch (
yyCh.toLatin1() ) {
150 }
while (yyCh != u'\n');
153 }
else if (
yyCh == u'*') {
154 bool metAster =
false;
155 bool metAsterSlash =
false;
157 while ( !metAsterSlash ) {
160 yyMsg() <<
"Unterminated Java comment.\n";
168 else if (metAster && yyCh == u'/')
169 metAsterSlash =
true;
182 while (!
yyEOF && yyCh != u'\n' && yyCh != u'"') {
189 for (
int i = 4; i > 0; --i) {
190 unicode = unicode << 4;
191 if(
yyCh.isDigit() ) {
192 unicode += yyCh.digitValue();
195 int sub(
yyCh.toLower().toLatin1() - 87);
196 if( sub > 15 || sub < 10) {
197 yyMsg() <<
"Invalid Unicode value.\n";
205 }
else if (
yyCh == u'\n') {
207 }
else if (
const char *p = strchr(tab, yyCh.toLatin1()); p) {
208 yyString.append(QLatin1Char(backTab[p - tab]));
211 yyMsg() <<
"Invalid escaped character \'\\" << qPrintable(yyCh)
222 yyMsg() <<
"Unterminated string.\n";
238 }
while (!
yyEOF && yyCh != u'\'');
291 ba += yyCh.toLatin1();
293 bool hex = yyCh == u'x';
295 ba += yyCh.toLatin1();
298 while ( hex ? isxdigit(yyCh.toLatin1()) : yyCh.isDigit() ) {
299 ba += yyCh.toLatin1();
317 bool matches = (
yyTok == t );
336 "String used in translation can contain only literals"
337 " concatenated with other literals, not expressions or numbers.\n";
347 bool matches = matchString(s);
357
358
359
360
361
362
363
364
365
366
367
368
369
379 if (parenlevel == 0)
break;
391 }
else if (parenlevel == 0) {
401 bool innerClass =
false;
402 for (
int i = 0; i <
yyScope.size(); ++i) {
405 context.append(
"$"_L1);
407 context.append(
"."_L1);
409 context.append(yyScope.at(i)->name);
417 Translator *tor,
const QString &context,
const QString &text,
const QString &comment,
421 context, text, comment, QString(),
422 yyFileName,
yyLineNo, QStringList(),
424 msg.setExtraComment(extracomment.simplified());
432 QString extracomment;
446 yyMsg() <<
"'class' must be followed by a class name.\n";
456 if ( match(Tok_LeftParen) && matchString(text) ) {
462 }
else if (match(Tok_Comma) && matchStringOrNull(com)) {
469 recordMessage(tor, context(), text, com, extracomment, plural, cd);
474 QString contextOverride;
476 if ( match(Tok_LeftParen) &&
477 matchString(contextOverride) &&
479 matchString(text) ) {
485 if ( match(Tok_Comma) && matchStringOrNull(com)) {
497 recordMessage(tor, contextOverride, text, com, extracomment, plural, cd);
509 extracomment.append(yyComment);
516 yyMsg() <<
"Excess closing brace.\n";
520 extracomment.clear();
530 extracomment.clear();
542 yyPackage.append(
"."_L1);
545 yyMsg() <<
"'package' must be followed by package name.\n";
557 if ( !yyScope.isEmpty() )
558 yyMsg(yyScope.top()->line) <<
"Unbalanced opening brace.\n";
566 QFile file(filename);
567 if (!file.open(QIODevice::ReadOnly)) {
568 cd.appendError(QStringLiteral(
"Cannot open %1: %2").arg(filename, file.errorString()));
581 QTextStream ts(&file);
582 ts.setEncoding(cd.m_sourceIsUtf16 ? QStringConverter::Utf16 : QStringConverter::Utf8);
583 ts.setAutoDetectUnicode(
true);
Scope(const QString &name, Type type, int line)
void extend(const TranslatorMessage &msg, ConversionData &cd)
std::ostream & yyMsg(int line=0)
static bool matchString(QString &s)
static bool matchExpression()
bool loadJava(Translator &translator, const QString &filename, ConversionData &cd)
static void parse(Translator *tor, ConversionData &cd)
static QString yyFileName
static QStack< Scope * > yyScope
static bool matchStringOrNull(QString &s)
static const QString context()
static void recordMessage(Translator *tor, const QString &context, const QString &text, const QString &comment, const QString &extracomment, bool plural, ConversionData &cd)
static qlonglong yyInteger