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); } } }
private int readHexDigit() { int b = _inputStream.ReadByte(); if (Lexer.IsEOL(b)) { do { b = _inputStream.ReadByte(); } while (Lexer.IsEOL(b)); } if (b == -1 || b == '>') { _eof = true; return(-1); } else if (b >= '0' && b <= '9') { return(b - '0'); } else if (b >= 'a' && b <= 'f') { return(b - 'a' + 10); } else if (b >= 'A' && b <= 'F') { return(b - 'A' + 10); } _eof = true; return(-1); }
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); }
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)); } } }
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); }
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)); } } }
private int read5Symbols(byte[] buf) { if (_eof) { return(0); } long value = 0; int count = 0, b; for (; ;) { b = _inputStream.ReadByte(); if (b < 0) { _eof = true; break; } if (Lexer.IsEOL(b)) { continue; } if (b == '~') { _eof = true; break; } if (b == 'z') { buf[0] = 0; buf[1] = 0; buf[2] = 0; buf[3] = 0; return(4); } if (!('!' <= b && b <= 'u')) { _eof = true; break; } count++; value = value * 85 + (b - 33); if (count == 5) { buf[0] = (byte)((value >> 24) & 0xFF); buf[1] = (byte)((value >> 16) & 0xFF); buf[2] = (byte)((value >> 8) & 0xFF); buf[3] = (byte)(value & 0xFF); return(4); } } if (count == 2) { value = value * (85L * 85 * 85) + 0xFFFFFF; } else if (count == 3) { value = value * (85L * 85) + 0xFFFF; } else if (count == 4) { value = value * (85L) + 0xFF; } if (count >= 2) { buf[0] = (byte)((value >> 24) & 0xFF); } if (count >= 3) { buf[1] = (byte)((value >> 16) & 0xFF); } if (count >= 4) { buf[2] = (byte)((value >> 8) & 0xFF); } return(count - 1); }