private void ParseFieldValue_AlphaNumeric(BibTexLexerCallback callback)
        {
            int field_value_start = c;

            while (true)
            {
                {
                    if (false)
                    {
                    }
                    else if (Char.IsLetterOrDigit(bibtex[c]))
                    {
                        ++c;
                    }
                    else if ('.' == bibtex[c])
                    {
                        ++c;
                    }
                    else if ('-' == bibtex[c])
                    {
                        ++c;
                    }
                    else
                    {
                        break;
                    }
                }
            }
            int    field_value_end = c;
            string field_value     = bibtex.Substring(field_value_start, field_value_end - field_value_start);

            callback.RaiseFieldValue(field_value);
        }
Пример #2
0
        private void ParseFields(BibTexLexerCallback callback, char delim_close)
        {
            while (delim_close != bibtex[c])
            {
                // Parse whitespace
                ParseWhiteSpace();

                // Get the name
                if (ParseFieldName(callback))
                {
                    // Parse whitespace
                    ParseWhiteSpace();

                    // Get the equals
                    if ('=' != bibtex[c])
                    {
                        Exception(callback, "Expecting an = between the field name and the field value");
                        if (c >= MAX_C)
                        {
                            break;              // abort as we've hit EOF prematurely
                        }
                        continue;
                    }
                    else
                    {
                        ++c;
                    }

                    field_values.Clear();
                    while (c < MAX_C)
                    {
                        // Parse whitespace
                        ParseWhiteSpace();

                        // Remember `c` as broken (and thus infinitely running) field values
                        // are a common problem in BibTeX records...
                        int value_start = c;

                        if (!ParseFieldValue(callback))
                        {
                            break;
                        }

                        // Parse whitespace
                        ParseWhiteSpace();

                        // Get an optional comma or `#` concatenation operator
                        switch (bibtex[c])
                        {
                        case ',':
                            ++c;
                            break;

                        case '#':
                            // concatenation: keep adding to the field value!
                            ++c;
                            continue;

                        default:
                            break;
                        }
                        break;
                    }

                    callback.RaiseFieldValue(field_values);
                    field_values.Clear();
                }
                else
                {
                    if (c >= MAX_C)
                    {
                        Exception(callback, "Expecting a field name but nothing was acceptable until EOF: broken or truncated BibTeX?");
                        break;  // abort as we've hit EOF prematurely
                    }
                    else
                    {
                        Exception(callback, "Expecting a field name but nothing was acceptable, so moving onto next whitespace");
                        HuntForWhitespace();
                    }
                }

                // Parse whitespace
                ParseWhiteSpace();
            }
        }
        private void ParseFieldValue_Braces(BibTexLexerCallback callback)
        {
            // Check we have our {
            if ('{' != bibtex[c])
            {
                Exception(callback, "Braces field value should start with {0}", "{{");
                return;
            }
            else
            {
                ++c;
            }

            int brace_depth       = 0;
            int field_value_start = c;

            while (true)
            {
                {
                    if (false)
                    {
                    }
                    else if ('{' == bibtex[c] && '\\' != bibtex[c - 1])
                    {
                        ++brace_depth;
                        ++c;
                    }
                    else if ('}' == bibtex[c] && '\\' != bibtex[c - 1])
                    {
                        --brace_depth;

                        // Are we out of our delimeters yet?
                        if (0 <= brace_depth)
                        {
                            ++c;
                        }
                        else
                        {
                            break;
                        }
                    }
                    else
                    {
                        ++c;
                    }
                }
            }
            int    field_value_end = c;
            string field_value     = bibtex.Substring(field_value_start, field_value_end - field_value_start);

            callback.RaiseFieldValue(field_value);

            // Check we have our final }
            if ('}' != bibtex[c])
            {
                Exception(callback, "Braces field value should end with {0}", "}}");
                return;
            }
            else
            {
                ++c;
            }
        }