6#include <QtCore/QDebug>
8#include <QtCore/QStack>
9#include <QtCore/QStack>
10#include <QtCore/QString>
11#include <QtCore/QCoreApplication>
12#include <QtCore/QStringConverter>
13#include <QtCore/QTextStream>
21using namespace Qt::Literals::StringLiterals;
48
49
50
76 return std::cerr << qPrintable(yyFileName) <<
':' << (line ? line :
yyLineNo) <<
": ";
81 if (
yyInPos >= yyInStr.size()) {
93 const char tab[] =
"bfnrt\"\'\\";
94 const char backTab[] =
"\b\f\n\r\t\"\'\\";
103 if (
yyCh.isLetter() || yyCh.toLatin1() ==
'_' ) {
107 }
while ( yyCh.isLetterOrNumber() || yyCh.toLatin1() ==
'_' );
110 switch (
yyIdent.at(0).toLatin1() ) {
112 if (yyIdent ==
"return"_L1)
116 if (yyIdent ==
"class"_L1)
120 if (yyIdent ==
"null"_L1)
125 switch (
yyIdent.at(0).toLatin1() ) {
127 if (yyIdent ==
"package"_L1)
131 if (yyIdent ==
"tr"_L1)
133 if (yyIdent ==
"translate"_L1)
138 switch (
yyCh.toLatin1() ) {
148 }
while (yyCh != u'\n');
151 }
else if (
yyCh == u'*') {
152 bool metAster =
false;
153 bool metAsterSlash =
false;
155 while ( !metAsterSlash ) {
158 yyMsg() <<
"Unterminated Java comment.\n";
166 else if (metAster && yyCh == u'/')
167 metAsterSlash =
true;
180 while (!
yyEOF && yyCh != u'\n' && yyCh != u'"') {
187 for (
int i = 4; i > 0; --i) {
188 unicode = unicode << 4;
189 if(
yyCh.isDigit() ) {
190 unicode += yyCh.digitValue();
193 int sub(
yyCh.toLower().toLatin1() - 87);
194 if( sub > 15 || sub < 10) {
195 yyMsg() <<
"Invalid Unicode value.\n";
203 }
else if (
yyCh == u'\n') {
205 }
else if (
const char *p = strchr(tab, yyCh.toLatin1()); p) {
206 yyString.append(QLatin1Char(backTab[p - tab]));
209 yyMsg() <<
"Invalid escaped character \'\\" << qPrintable(yyCh)
220 yyMsg() <<
"Unterminated string.\n";
236 }
while (!
yyEOF && yyCh != u'\'');
289 ba += yyCh.toLatin1();
291 bool hex = yyCh == u'x';
293 ba += yyCh.toLatin1();
296 while ( hex ? isxdigit(yyCh.toLatin1()) : yyCh.isDigit() ) {
297 ba += yyCh.toLatin1();
315 bool matches = (
yyTok == t );
334 "String used in translation can contain only literals"
335 " concatenated with other literals, not expressions or numbers.\n";
345 bool matches = matchString(s);
355
356
357
358
359
360
361
362
363
364
365
366
367
377 if (parenlevel == 0)
break;
389 }
else if (parenlevel == 0) {
399 bool innerClass =
false;
400 for (
int i = 0; i <
yyScope.size(); ++i) {
403 context.append(
"$"_L1);
405 context.append(
"."_L1);
407 context.append(yyScope.at(i)->name);
415 Translator *tor,
const QString &context,
const QString &text,
const QString &comment,
419 context, text, comment, QString(),
420 yyFileName,
yyLineNo, QStringList(),
422 msg.setExtraComment(extracomment.simplified());
430 QString extracomment;
444 yyMsg() <<
"'class' must be followed by a class name.\n";
454 if ( match(Tok_LeftParen) && matchString(text) ) {
460 }
else if (match(Tok_Comma) && matchStringOrNull(com)) {
467 recordMessage(tor, context(), text, com, extracomment, plural, cd);
472 QString contextOverride;
474 if ( match(Tok_LeftParen) &&
475 matchString(contextOverride) &&
477 matchString(text) ) {
483 if ( match(Tok_Comma) && matchStringOrNull(com)) {
495 recordMessage(tor, contextOverride, text, com, extracomment, plural, cd);
507 extracomment.append(yyComment);
514 yyMsg() <<
"Excess closing brace.\n";
518 extracomment.clear();
528 extracomment.clear();
543 yyMsg() <<
"'package' must be followed by package name.\n";
555 if ( !yyScope.isEmpty() )
556 yyMsg(yyScope.top()->line) <<
"Unbalanced opening brace.\n";
564 QFile file(filename);
565 if (!file.open(QIODevice::ReadOnly)) {
566 cd.appendError(QStringLiteral(
"Cannot open %1: %2").arg(filename, file.errorString()));
579 QTextStream ts(&file);
580 ts.setEncoding(cd.m_sourceIsUtf16 ? QStringConverter::Utf16 : QStringConverter::Utf8);
581 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()
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
bool loadJava(Translator &translator, const QString &filename, ConversionData &cd)