Package org.sonar.sslr.channel
Class CodeReader
- java.lang.Object
-
- org.sonar.sslr.channel.CodeBuffer
-
- org.sonar.sslr.channel.CodeReader
-
- All Implemented Interfaces:
CharSequence
public class CodeReader extends CodeBuffer
The CodeReader class provides some advanced features to read a source code. The most important one is the ability to try consuming the next characters in the stream according to a regular expression.
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class org.sonar.sslr.channel.CodeBuffer
CodeBuffer.Cursor
-
-
Constructor Summary
Constructors Constructor Description CodeReader(Reader code)CodeReader(Reader code, CodeReaderConfiguration configuration)Creates a code reader with specific configuration parameters.CodeReader(String code)CodeReader(String code, CodeReaderConfiguration configuration)Creates a code reader with specific configuration parameters.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description CodeBuffer.CursorgetPreviousCursor()char[]peek(int length)Read without consuming the next charactersvoidpeekTo(EndMatcher matcher, Appendable appendable)Read without consuming the next characters until a condition is reached (EndMatcher)voidpop(Appendable appendable)Read and consume the next characterintpopTo(Matcher matcher, Appendable appendable)Read and consume the next characters according to a given regular expressionintpopTo(Matcher matcher, Matcher afterMatcher, Appendable appendable)Read and consume the next characters according to a given regular expression.-
Methods inherited from class org.sonar.sslr.channel.CodeBuffer
charAt, getColumnPosition, getCursor, getLinePosition, intAt, lastChar, length, peek, pop, setColumnPosition, setLinePosition, startRecording, stopRecording, subSequence, toString
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface java.lang.CharSequence
chars, codePoints
-
-
-
-
Constructor Detail
-
CodeReader
public CodeReader(Reader code)
-
CodeReader
public CodeReader(String code)
-
CodeReader
public CodeReader(Reader code, CodeReaderConfiguration configuration)
Creates a code reader with specific configuration parameters. Note that this constructor will read everything from reader and will close it.- Parameters:
code- the Reader to read code fromconfiguration- the configuration parameters
-
CodeReader
public CodeReader(String code, CodeReaderConfiguration configuration)
Creates a code reader with specific configuration parameters.- Parameters:
code- the code itselfconfiguration- the configuration parameters
-
-
Method Detail
-
pop
public final void pop(Appendable appendable)
Read and consume the next character- Parameters:
appendable- the read character is appended to appendable
-
peek
public final char[] peek(int length)
Read without consuming the next characters- Parameters:
length- number of character to read- Returns:
- array of characters
-
peekTo
public final void peekTo(EndMatcher matcher, Appendable appendable)
Read without consuming the next characters until a condition is reached (EndMatcher)- Parameters:
matcher- the EndMatcher used to stop the readingappendable- the read characters is appended to appendable
-
popTo
public final int popTo(Matcher matcher, Appendable appendable)
Read and consume the next characters according to a given regular expression- Parameters:
matcher- the regular expression matcherappendable- the consumed characters are appended to this appendable- Returns:
- number of consumed characters or -1 if the next input sequence doesn't match this matcher's pattern
-
popTo
public final int popTo(Matcher matcher, Matcher afterMatcher, Appendable appendable)
Read and consume the next characters according to a given regular expression. Moreover the character sequence immediately following the desired characters must also match a given regular expression.- Parameters:
matcher- the Matcher used to try consuming next charactersafterMatcher- the Matcher used to check character sequence immediately following the consumed charactersappendable- the consumed characters are appended to this appendable- Returns:
- number of consumed characters or -1 if one of the two Matchers doesn't match
-
getPreviousCursor
public final CodeBuffer.Cursor getPreviousCursor()
-
-