Exemplo n.º 1
0
        private void parse(Lexer lexer)
        {
            lexer.LastParsedByte = lexer.ReadByte();
            for (; ;)
            {
                if (Lexer.IsEOL(lexer.LastParsedByte))
                {
                    lexer.SkipEOL();
                }
                if (lexer.LastParsedByte == -1)
                {
                    return;
                }

                lexer.ReadLexemeWithLastParsedByte();
                if (lexer.CurrentLexemeEquals(Beginbfrange))
                {
                    loadRange(lexer);
                }
                else if (lexer.CurrentLexemeEquals(Beginbfchar))
                {
                    loadChar(lexer);
                }
            }
        }
Exemplo n.º 2
0
        private int getLigature(Lexer lexer, out string value)
        {
            value = null;
            if (lexer.LastParsedByte != '<')
            {
                return(-1);
            }

            int count = lexer.ReadHexValue();

            if (Lexer.IsEOL(lexer.LastParsedByte))
            {
                lexer.SkipEOL();
            }

            if (count == 1)
            {
                return(lexer.GetLexemeHexByte());
            }
            else if (count == 2)
            {
                return(lexer.GetLexemeHex2Bytes());
            }
            if (count % 2 != 0)
            {
                return(-1);
            }
            value = lexer.GetLexemeHexLigature();
            return(0);
        }
Exemplo n.º 3
0
        private void loadChar(Lexer lexer)
        {
            if (Lexer.IsEOL(lexer.LastParsedByte))
            {
                lexer.SkipEOL();
            }

            string tmp;

            for (; ;)
            {
                if (lexer.LastParsedByte == 'e')
                {
                    return;
                }

                int code = getChar(lexer);
                if (code < 0)
                {
                    return;
                }

                int value = getLigature(lexer, out tmp);
                if (value < 0)
                {
                    return;
                }

                if (tmp != null)
                {
                    initLigatures();
                    m_ligatures[(ushort)code] = tmp;
                }
                else
                {
                    m_chars.Add(new BfChar((char)value, (ushort)code));
                }
            }
        }
Exemplo n.º 4
0
        private int getChar(Lexer lexer)
        {
            if (lexer.LastParsedByte != '<')
            {
                return(-1);
            }

            int count = lexer.ReadHexValue();

            if (Lexer.IsEOL(lexer.LastParsedByte))
            {
                lexer.SkipEOL();
            }

            if (count == 1)
            {
                return(lexer.GetLexemeHexByte());
            }
            else if (count == 2)
            {
                return(lexer.GetLexemeHex2Bytes());
            }
            return(-1);
        }
Exemplo n.º 5
0
        private void loadRange(Lexer lexer)
        {
            if (Lexer.IsEOL(lexer.LastParsedByte))
            {
                lexer.SkipEOL();
            }
            for (; ;)
            {
                if (lexer.LastParsedByte == 'e')
                {
                    return;
                }

                int first = getChar(lexer);
                if (first < 0)
                {
                    return;
                }

                int second = getChar(lexer);
                if (second < 0)
                {
                    return;
                }

                if (lexer.LastParsedByte == '[')
                {
                    string tmp;
                    lexer.SkipEOL();
                    for (; ;)
                    {
                        if (lexer.LastParsedByte == ']')
                        {
                            lexer.SkipEOL();
                            break;
                        }

                        int code = getLigature(lexer, out tmp);
                        if (code < 0)
                        {
                            return;
                        }
                        if (tmp != null)
                        {
                            initLigatures();
                            m_ligatures[(ushort)code] = tmp;
                        }
                        else
                        {
                            m_chars.Add(new BfChar((char)code, (ushort)first));
                        }
                        ++first;
                    }
                }
                else
                {
                    int value = getChar(lexer);
                    if (value < 0)
                    {
                        return;
                    }
                    m_ranges.Add(new BfRange((char)value, (char)(value + second - first), (ushort)first, (ushort)second));
                }
            }
        }