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 190 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 1945 of file Nyquist.cpp.

1948{
1949 auto endToken = [&]{
1950 if (!tok.empty()) {
1951 tokens.push_back(tok);
1952 tok = wxT("");
1953 }
1954 };
1955
1956 for (auto c :
1957 make_iterator_range(line.begin() + trimStart, line.end() - trimEnd)) {
1958 if (q && !sl && c == wxT('\\')) {
1959 // begin escaped character, only within quotes
1960 sl = true;
1961 continue;
1962 }
1963
1964 if (!sl && c == wxT('"')) {
1965 // Unescaped quote
1966 if (!q) {
1967 // start of string
1968 if (!paren)
1969 // finish previous token
1970 endToken();
1971 // Include the delimiter in the token
1972 tok += c;
1973 q = true;
1974 }
1975 else {
1976 // end of string
1977 // Include the delimiter in the token
1978 tok += c;
1979 if (!paren)
1980 endToken();
1981 q = false;
1982 }
1983 }
1984 else if (!q && !paren && (c == wxT(' ') || c == wxT('\t')))
1985 // Unenclosed whitespace
1986 // Separate tokens; don't accumulate this character
1987 endToken();
1988 else if (!q && c == wxT(';'))
1989 // semicolon not in quotes, but maybe in parentheses
1990 // Lisp style comments with ; (but not with #| ... |#) are allowed
1991 // within a wrapped header multi-line, so that i18n hint comments may
1992 // be placed before strings and found by xgettext
1993 break;
1994 else if (!q && c == wxT('(')) {
1995 // Start of list or sublist
1996 if (++paren == 1)
1997 // finish previous token; begin list, including the delimiter
1998 endToken(), tok += c;
1999 else
2000 // defer tokenizing of nested list to a later pass over the token
2001 tok += c;
2002 }
2003 else if (!q && c == wxT(')')) {
2004 // End of list or sublist
2005 if (--paren == 0)
2006 // finish list, including the delimiter
2007 tok += c, endToken();
2008 else if (paren < 0)
2009 // forgive unbalanced right paren
2010 paren = 0, endToken();
2011 else
2012 // nested list; deferred tokenizing
2013 tok += c;
2014 }
2015 else {
2016 if (sl && paren)
2017 // Escaped character in string inside list, to be parsed again
2018 // Put the escape back for the next pass
2019 tok += wxT('\\');
2020 if (sl && !paren && c == 'n')
2021 // Convert \n to newline, the only special escape besides \\ or \"
2022 // But this should not be used if a string needs to localize.
2023 // Instead, simply put a line break in the string.
2024 c = '\n';
2025 tok += c;
2026 }
2027
2028 sl = false;
2029 }
2030
2031 if (eof || (!q && !paren)) {
2032 endToken();
2033 return true;
2034 }
2035 else {
2036 // End of line but not of file, and a string or list is yet unclosed
2037 // If a string, accumulate a newline character
2038 if (q)
2039 tok += wxT('\n');
2040 return false;
2041 }
2042}
wxT("CloseDown"))
IteratorRange< Iterator > make_iterator_range(const Iterator &i1, const Iterator &i2)
Definition: MemoryX.h:448
wxArrayStringEx tokens
Definition: Nyquist.h:195

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

Referenced by Tokenize().

◆ q

bool NyquistEffect::Tokenizer::q { false }

Definition at line 192 of file Nyquist.h.

Referenced by Tokenize().

◆ sl

bool NyquistEffect::Tokenizer::sl { false }

Definition at line 191 of file Nyquist.h.

Referenced by Tokenize().

◆ tok

wxString NyquistEffect::Tokenizer::tok

Definition at line 194 of file Nyquist.h.

Referenced by Tokenize().

◆ tokens

wxArrayStringEx NyquistEffect::Tokenizer::tokens

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