| 1 | tim | 770 | /* ANTLR Translator Generator | 
| 2 |  |  | * Project led by Terence Parr at http://www.jGuru.com | 
| 3 |  |  | * Software rights: http://www.antlr.org/license.html | 
| 4 |  |  | * | 
| 5 | gezelter | 1442 | * $Id$ | 
| 6 | tim | 770 | */ | 
| 7 |  |  |  | 
| 8 |  |  | #include "antlr/config.hpp" | 
| 9 |  |  | #include "antlr/InputBuffer.hpp" | 
| 10 | gezelter | 1610 | #include <iostream> | 
| 11 | tim | 770 |  | 
| 12 | gezelter | 1782 | #include <iostream> | 
| 13 | tim | 770 | #ifdef ANTLR_CXX_SUPPORTS_NAMESPACE | 
| 14 |  |  | namespace antlr { | 
| 15 |  |  | #endif | 
| 16 |  |  |  | 
| 17 |  |  | /** Ensure that the character buffer is sufficiently full */ | 
| 18 |  |  | void InputBuffer::fill(unsigned int amount) | 
| 19 |  |  | { | 
| 20 |  |  | syncConsume(); | 
| 21 |  |  | // Fill the buffer sufficiently to hold needed characters | 
| 22 |  |  | while (queue.entries() < amount + markerOffset) | 
| 23 |  |  | { | 
| 24 |  |  | // Append the next character | 
| 25 |  |  | queue.append(getChar()); | 
| 26 |  |  | } | 
| 27 |  |  | } | 
| 28 |  |  |  | 
| 29 |  |  | /** get the current lookahead characters as a string | 
| 30 |  |  | * @warning it may treat 0 and EOF values wrong | 
| 31 |  |  | */ | 
| 32 |  |  | ANTLR_USE_NAMESPACE(std)string InputBuffer::getLAChars( void ) const | 
| 33 |  |  | { | 
| 34 |  |  | ANTLR_USE_NAMESPACE(std)string ret; | 
| 35 |  |  |  | 
| 36 |  |  | for(unsigned int i = markerOffset; i < queue.entries(); i++) | 
| 37 |  |  | ret += queue.elementAt(i); | 
| 38 |  |  |  | 
| 39 |  |  | return ret; | 
| 40 |  |  | } | 
| 41 |  |  |  | 
| 42 |  |  | /** get the current marked characters as a string | 
| 43 |  |  | * @warning it may treat 0 and EOF values wrong | 
| 44 |  |  | */ | 
| 45 |  |  | ANTLR_USE_NAMESPACE(std)string InputBuffer::getMarkedChars( void ) const | 
| 46 |  |  | { | 
| 47 |  |  | ANTLR_USE_NAMESPACE(std)string ret; | 
| 48 |  |  |  | 
| 49 |  |  | for(unsigned int i = 0; i < markerOffset; i++) | 
| 50 |  |  | ret += queue.elementAt(i); | 
| 51 |  |  |  | 
| 52 |  |  | return ret; | 
| 53 |  |  | } | 
| 54 |  |  |  | 
| 55 |  |  | /** Return an integer marker that can be used to rewind the buffer to | 
| 56 |  |  | * its current state. | 
| 57 |  |  | */ | 
| 58 |  |  | unsigned int InputBuffer::mark() | 
| 59 |  |  | { | 
| 60 |  |  | syncConsume(); | 
| 61 |  |  | nMarkers++; | 
| 62 |  |  | return markerOffset; | 
| 63 |  |  | } | 
| 64 |  |  |  | 
| 65 |  |  | /** Rewind the character buffer to a marker. | 
| 66 |  |  | * @param mark Marker returned previously from mark() | 
| 67 |  |  | */ | 
| 68 |  |  | void InputBuffer::rewind(unsigned int mark) | 
| 69 |  |  | { | 
| 70 |  |  | syncConsume(); | 
| 71 |  |  | markerOffset = mark; | 
| 72 |  |  | nMarkers--; | 
| 73 |  |  | } | 
| 74 |  |  |  | 
| 75 |  |  | unsigned int InputBuffer::entries() const | 
| 76 |  |  | { | 
| 77 |  |  | //assert(queue.entries() >= markerOffset); | 
| 78 |  |  | return queue.entries() - markerOffset; | 
| 79 |  |  | } | 
| 80 |  |  |  | 
| 81 |  |  | #ifdef ANTLR_CXX_SUPPORTS_NAMESPACE | 
| 82 |  |  | } | 
| 83 |  |  | #endif |