Audacity 3.2.0
Public Member Functions | Public Attributes | List of all members
NyquistEffect::Tokenizer Struct Reference
Collaboration diagram for NyquistEffect::Tokenizer:
[legend]

Public Member Functions

bool Tokenize (const wxString &line, bool eof, size_t trimStart, size_t trimEnd)
 

Public Attributes

bool sl { false }
 
bool q { false }
 
int paren { 0 }
 
wxString tok
 
wxArrayStringEx tokens
 

Detailed Description

Definition at line 185 of file Nyquist.h.

Member Function Documentation

◆ Tokenize()

bool NyquistEffect::Tokenizer::Tokenize ( const wxString &  line,
bool  eof,
size_t  trimStart,
size_t  trimEnd 
)

Definition at line 1998 of file Nyquist.cpp.

2001{
2002 auto endToken = [&]{
2003 if (!tok.empty()) {
2004 tokens.push_back(tok);
2005 tok = wxT("");
2006 }
2007 };
2008
2009 for (auto c :
2010 make_iterator_range(line.begin() + trimStart, line.end() - trimEnd)) {
2011 if (q && !sl && c == wxT('\\')) {
2012 // begin escaped character, only within quotes
2013 sl = true;
2014 continue;
2015 }
2016
2017 if (!sl && c == wxT('"')) {
2018 // Unescaped quote
2019 if (!q) {
2020 // start of string
2021 if (!paren)
2022 // finish previous token
2023 endToken();
2024 // Include the delimiter in the token
2025 tok += c;
2026 q = true;
2027 }
2028 else {
2029 // end of string
2030 // Include the delimiter in the token
2031 tok += c;
2032 if (!paren)
2033 endToken();
2034 q = false;
2035 }
2036 }
2037 else if (!q && !paren && (c == wxT(' ') || c == wxT('\t')))
2038 // Unenclosed whitespace
2039 // Separate tokens; don't accumulate this character
2040 endToken();
2041 else if (!q && c == wxT(';'))
2042 // semicolon not in quotes, but maybe in parentheses
2043 // Lisp style comments with ; (but not with #| ... |#) are allowed
2044 // within a wrapped header multi-line, so that i18n hint comments may
2045 // be placed before strings and found by xgettext
2046 break;
2047 else if (!q && c == wxT('(')) {
2048 // Start of list or sublist
2049 if (++paren == 1)
2050 // finish previous token; begin list, including the delimiter
2051 endToken(), tok += c;
2052 else
2053 // defer tokenizing of nested list to a later pass over the token
2054 tok += c;
2055 }
2056 else if (!q && c == wxT(')')) {
2057 // End of list or sublist
2058 if (--paren == 0)
2059 // finish list, including the delimiter
2060 tok += c, endToken();
2061 else if (paren < 0)
2062 // forgive unbalanced right paren
2063 paren = 0, endToken();
2064 else
2065 // nested list; deferred tokenizing
2066 tok += c;
2067 }
2068 else {
2069 if (sl && paren)
2070 // Escaped character in string inside list, to be parsed again
2071 // Put the escape back for the next pass
2072 tok += wxT('\\');
2073 if (sl && !paren && c == 'n')
2074 // Convert \n to newline, the only special escape besides \\ or \"
2075 // But this should not be used if a string needs to localize.
2076 // Instead, simply put a line break in the string.
2077 c = '\n';
2078 tok += c;
2079 }
2080
2081 sl = false;
2082 }
2083
2084 if (eof || (!q && !paren)) {
2085 endToken();
2086 return true;
2087 }
2088 else {
2089 // End of line but not of file, and a string or list is yet unclosed
2090 // If a string, accumulate a newline character
2091 if (q)
2092 tok += wxT('\n');
2093 return false;
2094 }
2095}
wxT("CloseDown"))
IteratorRange< Iterator > make_iterator_range(const Iterator &i1, const Iterator &i2)
Definition: IteratorX.h:210
wxArrayStringEx tokens
Definition: Nyquist.h:190

References make_iterator_range(), paren, q, sl, tok, tokens, and wxT().

Referenced by NyquistEffect::Parse(), NyquistEffect::ParseChoice(), NyquistEffect::ParseFileExtensions(), NyquistEffect::ParseFileType(), NyquistEffect::ParseFileTypes(), and NyquistEffect::UnQuoteMsgid().

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

Member Data Documentation

◆ paren

int NyquistEffect::Tokenizer::paren { 0 }

Definition at line 188 of file Nyquist.h.

Referenced by Tokenize().

◆ q

bool NyquistEffect::Tokenizer::q { false }

Definition at line 187 of file Nyquist.h.

Referenced by Tokenize().

◆ sl

bool NyquistEffect::Tokenizer::sl { false }

Definition at line 186 of file Nyquist.h.

Referenced by Tokenize().

◆ tok

wxString NyquistEffect::Tokenizer::tok

Definition at line 189 of file Nyquist.h.

Referenced by Tokenize().

◆ tokens

wxArrayStringEx NyquistEffect::Tokenizer::tokens

The documentation for this struct was generated from the following files: