Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
python.cpp File Reference

(0eac2258042268282f6e86e6bbcf2442e1f65afa)

#include <translator.h>
#include "lupdate.h"
#include <QtCore/qhash.h>
#include <QtCore/qlist.h>
#include <QtCore/qstring.h>
#include <QtCore/qtextstream.h>
#include <QtCore/qstack.h>
#include <cctype>
#include <cerrno>
#include <cstdio>
#include <cstring>
+ Include dependency graph for python.cpp:

Go to the source code of this file.

Classes

struct  ExtraComment
 

Typedefs

using ContextPair = QPair<QByteArray, int>
 
using ContextStack = QStack<ContextPair>
 

Enumerations

enum  Token {
  Tok_Eof , Tok_class , Tok_def , Tok_return ,
  Tok_tr , Tok_trUtf8 , Tok_translate , Tok_Ident ,
  Tok_Comment , Tok_Dot , Tok_String , Tok_LeftParen ,
  Tok_RightParen , Tok_Comma , Tok_None , Tok_Integer ,
  Tok_Eof , Tok_class , Tok_def , Tok_return ,
  Tok_tr , Tok_trUtf8 , Tok_translate , Tok_Ident ,
  Tok_Comment , Tok_Dot , Tok_String , Tok_LeftParen ,
  Tok_RightParen , Tok_Comma , Tok_None , Tok_Integer
}
 
enum class  StringType {
  NoString , String , FormatString , RawString ,
  NoString , String , FormatString , RawString
}
 
enum  Token {
  Tok_Eof , Tok_class , Tok_def , Tok_return ,
  Tok_tr , Tok_trUtf8 , Tok_translate , Tok_Ident ,
  Tok_Comment , Tok_Dot , Tok_String , Tok_LeftParen ,
  Tok_RightParen , Tok_Comma , Tok_None , Tok_Integer ,
  Tok_Eof , Tok_class , Tok_def , Tok_return ,
  Tok_tr , Tok_trUtf8 , Tok_translate , Tok_Ident ,
  Tok_Comment , Tok_Dot , Tok_String , Tok_LeftParen ,
  Tok_RightParen , Tok_Comma , Tok_None , Tok_Integer
}
 
enum class  StringType {
  NoString , String , FormatString , RawString ,
  NoString , String , FormatString , RawString
}
 

Functions

static int getCharFromFile ()
 
static int peekCharFromFile ()
 
static void startTokenizer (const QString &fileName, int(*getCharFunc)(), int(*peekCharFunc)())
 
static bool parseStringEscape (int quoteChar, StringType stringType)
 
static Token parseString (StringType stringType=StringType::NoString)
 
static QByteArray readLine ()
 
static Token getToken (StringType stringType=StringType::NoString)
 
static bool match (Token t)
 
static bool matchStringStart ()
 
static bool matchString (QByteArray *s)
 
static bool matchEncoding (bool *utf8)
 
static bool matchStringOrNone (QByteArray *s)
 
static bool matchExpression ()
 
static bool parseTranslate (QByteArray *text, QByteArray *context, QByteArray *comment, bool *utf8, bool *plural)
 
static void setMessageParameters (TranslatorMessage *message, int lineNo)
 
static void parse (Translator &tor, ConversionData &cd, const QByteArray &initialContext={}, const QByteArray &defaultContext={})
 
bool loadPython (Translator &translator, const QString &fileName, ConversionData &cd)
 

Variables

static QT_BEGIN_NAMESPACE const char PythonMagicComment [] = "TRANSLATOR "
 
static QString yyFileName
 
static int yyCh
 
static QByteArray yyIdent
 
static char yyComment [65536]
 
static size_t yyCommentLen
 
static char yyString [65536]
 
static size_t yyStringLen
 
static int yyParenDepth
 
static int yyLineNo
 
static int yyCurLineNo
 
static QList< ExtraCommentextraComments
 
static QList< ExtraCommentids
 
QHash< QByteArray, Tokentokens
 
static FILE * yyInFile
 
static int yyInPos
 
static int buf
 
static int(* getChar )()
 
static int(* peekChar )()
 
static int yyIndentationSize
 
static int yyContinuousSpaceCount
 
static bool yyCountingIndentation
 
static ContextStack yyContextStack
 
static Token yyTok
 

Typedef Documentation

◆ ContextPair

typedef QPair< QByteArray, int > ContextPair = QPair<QByteArray, int>

Definition at line 91 of file python.cpp.

◆ ContextStack

Definition at line 93 of file python.cpp.

Enumeration Type Documentation

◆ StringType [1/2]

enum class StringType
strong
Enumerator
NoString 
String 
FormatString 
RawString 
NoString 
String 
FormatString 
RawString 

Definition at line 34 of file python.cpp.

◆ StringType [2/2]

enum class StringType
strong
Enumerator
NoString 
String 
FormatString 
RawString 
NoString 
String 
FormatString 
RawString 

Definition at line 34 of file python.cpp.

◆ Token [1/2]

enum Token
Enumerator
Tok_Eof 
Tok_class 
Tok_def 
Tok_return 
Tok_tr 
Tok_trUtf8 
Tok_translate 
Tok_Ident 
Tok_Comment 
Tok_Dot 
Tok_String 
Tok_LeftParen 
Tok_RightParen 
Tok_Comma 
Tok_None 
Tok_Integer 
Tok_Eof 
Tok_class 
Tok_def 
Tok_return 
Tok_tr 
Tok_trUtf8 
Tok_translate 
Tok_Ident 
Tok_Comment 
Tok_Dot 
Tok_String 
Tok_LeftParen 
Tok_RightParen 
Tok_Comma 
Tok_None 
Tok_Integer 

Definition at line 28 of file python.cpp.

◆ Token [2/2]

enum Token
Enumerator
Tok_Eof 
Tok_class 
Tok_def 
Tok_return 
Tok_tr 
Tok_trUtf8 
Tok_translate 
Tok_Ident 
Tok_Comment 
Tok_Dot 
Tok_String 
Tok_LeftParen 
Tok_RightParen 
Tok_Comma 
Tok_None 
Tok_Integer 
Tok_Eof 
Tok_class 
Tok_def 
Tok_return 
Tok_tr 
Tok_trUtf8 
Tok_translate 
Tok_Ident 
Tok_Comment 
Tok_Dot 
Tok_String 
Tok_LeftParen 
Tok_RightParen 
Tok_Comma 
Tok_None 
Tok_Integer 

Definition at line 28 of file python.cpp.

Function Documentation

◆ getCharFromFile()

static int getCharFromFile ( )
static

Definition at line 96 of file python.cpp.

References buf, yyContinuousSpaceCount, yyCountingIndentation, yyCurLineNo, and yyInFile.

Referenced by loadPython().

+ Here is the caller graph for this function:

◆ getToken()

static Token getToken ( StringType stringType = StringType::NoString)
static

Definition at line 293 of file python.cpp.

References getChar, parseString(), Tok_Comma, Tok_Dot, Tok_Eof, Tok_Ident, Tok_Integer, Tok_LeftParen, Tok_RightParen, yyCh, yyCommentLen, yyCurLineNo, yyIdent, yyLineNo, yyParenDepth, and yyStringLen.

Referenced by match(), matchEncoding(), matchExpression(), matchString(), matchStringStart(), and parseTranslate().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ loadPython()

bool loadPython ( Translator & translator,
const QString & fileName,
ConversionData & cd )

Definition at line 749 of file python.cpp.

References getCharFromFile(), parse(), peekCharFromFile(), Tok_tr, Tok_translate, Tok_trUtf8, tokens, and yyInFile.

+ Here is the call graph for this function:

◆ match()

static bool match ( Token t)
static

Definition at line 395 of file python.cpp.

References getToken(), and yyTok.

Referenced by matchExpression(), matchStringOrNone(), and parseTranslate().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ matchEncoding()

static bool matchEncoding ( bool * utf8)
static

Definition at line 433 of file python.cpp.

References getToken(), Tok_Dot, Tok_Ident, and yyTok.

Referenced by parseTranslate().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ matchExpression()

static bool matchExpression ( )
static

Definition at line 495 of file python.cpp.

References getToken(), match(), Tok_Ident, Tok_Integer, Tok_LeftParen, Tok_RightParen, and yyTok.

Referenced by parseTranslate().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ matchString()

static bool matchString ( QByteArray * s)
static

Definition at line 421 of file python.cpp.

References getToken(), matchStringStart(), yyString, and yyTok.

+ Here is the call graph for this function:

◆ matchStringOrNone()

static bool matchStringOrNone ( QByteArray * s)
static

Definition at line 472 of file python.cpp.

References match(), and Tok_None.

+ Here is the call graph for this function:

◆ matchStringStart()

static bool matchStringStart ( )
static

Definition at line 403 of file python.cpp.

References FormatString, getToken(), RawString, Tok_Ident, Tok_String, yyIdent, and yyTok.

Referenced by matchString().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ parse()

static void parse ( Translator & tor,
ConversionData & cd,
const QByteArray & initialContext = {},
const QByteArray & defaultContext = {} )
static

Definition at line 614 of file python.cpp.

Referenced by loadPython().

+ Here is the caller graph for this function:

◆ parseString()

static Token parseString ( StringType stringType = StringType::NoString)
static

Definition at line 212 of file python.cpp.

References getChar, parseStringEscape(), peekChar, Tok_Eof, Tok_String, yyCh, yyLineNo, yyString, and yyStringLen.

Referenced by getToken().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ parseStringEscape()

static bool parseStringEscape ( int quoteChar,
StringType stringType )
static

Definition at line 144 of file python.cpp.

References getChar, RawString, yyCh, and yyString.

Referenced by parseString().

+ Here is the caller graph for this function:

◆ parseTranslate()

static bool parseTranslate ( QByteArray * text,
QByteArray * context,
QByteArray * comment,
bool * utf8,
bool * plural )
static

Definition at line 523 of file python.cpp.

References getToken(), match(), matchEncoding(), matchExpression(), Tok_Comma, Tok_RightParen, and yyTok.

+ Here is the call graph for this function:

◆ peekCharFromFile()

static int peekCharFromFile ( )
static

Definition at line 118 of file python.cpp.

References buf, and yyInFile.

Referenced by loadPython().

+ Here is the caller graph for this function:

◆ readLine()

static QByteArray readLine ( )
static

Definition at line 281 of file python.cpp.

References getChar, and yyCh.

◆ setMessageParameters()

static void setMessageParameters ( TranslatorMessage * message,
int lineNo )
static

Definition at line 594 of file python.cpp.

◆ startTokenizer()

static void startTokenizer ( const QString & fileName,
int(* getCharFunc )(),
int(* peekCharFunc )() )
static

Variable Documentation

◆ buf

int buf
static

Definition at line 81 of file python.cpp.

Referenced by getCharFromFile(), peekCharFromFile(), and startTokenizer().

◆ extraComments

static QList< ExtraComment > extraComments
static

Definition at line 63 of file python.cpp.

◆ getChar

static int(* getChar)() ( )
static

Definition at line 83 of file python.cpp.

Referenced by getToken(), parseString(), parseStringEscape(), readLine(), and startTokenizer().

◆ ids

Definition at line 65 of file python.cpp.

◆ peekChar

static int(* peekChar)() ( )
static

Definition at line 84 of file python.cpp.

Referenced by parseString(), and startTokenizer().

◆ PythonMagicComment

static QT_BEGIN_NAMESPACE const char PythonMagicComment = "TRANSLATOR "
static

Definition at line 21 of file python.cpp.

◆ tokens

QHash< QByteArray, Token > tokens
Initial value:
= {
{"None", Tok_None},
{"class", Tok_class},
{"def", Tok_def},
{"return", Tok_return},
{"__tr", Tok_tr},
{"__trUtf8", Tok_trUtf8}
}
@ Tok_tr
Definition python.cpp:28
@ Tok_class
Definition python.cpp:28
@ Tok_return
Definition python.cpp:28
@ Tok_None
Definition python.cpp:32
@ Tok_trUtf8
Definition python.cpp:29
@ Tok_def
Definition python.cpp:28

Definition at line 67 of file python.cpp.

Referenced by loadPython().

◆ yyCh

static int yyCh
static

Definition at line 47 of file python.cpp.

Referenced by getToken(), parseString(), parseStringEscape(), readLine(), and startTokenizer().

◆ yyComment

static char yyComment
static

Definition at line 49 of file python.cpp.

◆ yyCommentLen

static size_t yyCommentLen
static

Definition at line 50 of file python.cpp.

Referenced by getToken().

◆ yyContextStack

static ContextStack yyContextStack
static

Definition at line 94 of file python.cpp.

Referenced by startTokenizer().

◆ yyContinuousSpaceCount

static int yyContinuousSpaceCount
static

Definition at line 87 of file python.cpp.

Referenced by getCharFromFile(), and startTokenizer().

◆ yyCountingIndentation

static bool yyCountingIndentation
static

Definition at line 88 of file python.cpp.

Referenced by getCharFromFile(), and startTokenizer().

◆ yyCurLineNo

static int yyCurLineNo
static

Definition at line 55 of file python.cpp.

Referenced by getCharFromFile(), getToken(), and startTokenizer().

◆ yyFileName

static QString yyFileName
static

Definition at line 46 of file python.cpp.

Referenced by startTokenizer().

◆ yyIdent

static QByteArray yyIdent
static

Definition at line 48 of file python.cpp.

Referenced by getToken(), and matchStringStart().

◆ yyIndentationSize

static int yyIndentationSize
static

Definition at line 86 of file python.cpp.

Referenced by startTokenizer().

◆ yyInFile

static FILE * yyInFile
static

Definition at line 77 of file python.cpp.

Referenced by getCharFromFile(), loadPython(), and peekCharFromFile().

◆ yyInPos

static int yyInPos
static

Definition at line 80 of file python.cpp.

Referenced by startTokenizer().

◆ yyLineNo

static int yyLineNo
static

Definition at line 54 of file python.cpp.

Referenced by getToken(), and parseString().

◆ yyParenDepth

static int yyParenDepth
static

Definition at line 53 of file python.cpp.

Referenced by getToken(), and startTokenizer().

◆ yyString

static char yyString
static

Definition at line 51 of file python.cpp.

Referenced by matchString(), parseString(), and parseStringEscape().

◆ yyStringLen

static size_t yyStringLen
static

Definition at line 52 of file python.cpp.

Referenced by getToken(), and parseString().

◆ yyTok

static Token yyTok
static