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 183 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 1990 of file Nyquist.cpp.

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

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 186 of file Nyquist.h.

Referenced by Tokenize().

◆ q

bool NyquistEffect::Tokenizer::q { false }

Definition at line 185 of file Nyquist.h.

Referenced by Tokenize().

◆ sl

bool NyquistEffect::Tokenizer::sl { false }

Definition at line 184 of file Nyquist.h.

Referenced by Tokenize().

◆ tok

wxString NyquistEffect::Tokenizer::tok

Definition at line 187 of file Nyquist.h.

Referenced by Tokenize().

◆ tokens

wxArrayStringEx NyquistEffect::Tokenizer::tokens

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