public final class Scanners extends Object
Parser
implementations that scan the source and match certain string
patterns.
Some scanners like IDENTIFIER
and INTEGER
return the matched string,
while others like WHITESPACES
return nothing, as indicated by the Void
type parameter. In case the matched string is still needed nonetheless,
use the Parser.source()
method.
Modifier and Type | Field and Description |
---|---|
static Parser<Void> |
ANY_CHAR
Matches any character in the input.
|
static Parser<String> |
DEC_INTEGER
Scanner for a decimal number.
|
static Parser<String> |
DECIMAL
Scanner for a decimal number.
|
static Parser<String> |
DOUBLE_QUOTE_STRING
Scanner with a pattern for double quoted string literal.
|
static Parser<Void> |
HASKELL_BLOCK_COMMENT
Scanner for haskell style block comment.
|
static Parser<Void> |
HASKELL_DELIMITER
Scanner for the haskell style delimiter of tokens.
|
static Parser<Void> |
HASKELL_LINE_COMMENT
Scanner for haskell style line comment.
|
static Parser<String> |
HEX_INTEGER
Scanner for a hexadecimal number.
|
static Parser<String> |
IDENTIFIER
Scanner for a regular identifier, that starts with either
an underscore or an alpha character, followed by 0 or more alphanumeric characters.
|
static Parser<String> |
INTEGER
Scanner for an integer.
|
static Parser<Void> |
JAVA_BLOCK_COMMENT
Scanner for c++/java style block comment.
|
static Parser<Void> |
JAVA_DELIMITER
Scanner for the c++/java style delimiter of tokens.
|
static Parser<Void> |
JAVA_LINE_COMMENT
Scanner for c++/java style line comment.
|
static Parser<String> |
OCT_INTEGER
Scanner for a octal number.
|
static Parser<String> |
SCIENTIFIC_NOTATION
Scanner for a scientific notation.
|
static Parser<String> |
SINGLE_QUOTE_CHAR
Scanner for a c/c++/java style character literal.
|
static Parser<String> |
SINGLE_QUOTE_STRING
Scanner with a pattern for SQL style string literal.
|
static Parser<Void> |
SQL_BLOCK_COMMENT
Scanner for SQL style block comment.
|
static Parser<Void> |
SQL_DELIMITER
Scanner for the SQL style delimiter of tokens.
|
static Parser<Void> |
SQL_LINE_COMMENT
Scanner for SQL style line comment.
|
static Parser<Void> |
WHITESPACES
A scanner that scans greedily for 1 or more whitespace characters.
|
Modifier and Type | Method and Description |
---|---|
static Parser<Void> |
among(String chars)
A scanner that succeeds and consumes the current character if it equals to any character in
chars . |
static Parser<Void> |
among(String chars,
String name)
Deprecated.
Use
Patterns.among(chars).toScanner(name) . |
static Parser<Void> |
blockComment(Parser<Void> begin,
Parser<Void> end,
Parser<?> commented)
A scanner for a non-nestable block comment that starts with
begin and ends with
end . |
static Parser<Void> |
blockComment(String begin,
String end)
A scanner for non-nested block comment that starts with
begin and ends with
end . |
static Parser<Void> |
blockComment(String begin,
String end,
Pattern commented)
A scanner for a non-nestable block comment that starts with
begin and ends with
end . |
static Parser<Void> |
isChar(char ch)
A scanner that succeeds and consumes the current character if it is equal to
ch . |
static Parser<Void> |
isChar(CharPredicate predicate)
A scanner that succeeds and consumes the current character if it satisfies the given
CharPredicate . |
static Parser<Void> |
isChar(CharPredicate predicate,
String name)
Deprecated.
Implement
Object.toString() in the CharPredicate ,
or use Patterns.isChar(predicate).toScanner(name) . |
static Parser<Void> |
isChar(char ch,
String name)
Deprecated.
Use
isChar(char) instead
or use Patterns.isChar(ch).toScanner(name) . |
static Parser<Void> |
lineComment(String begin)
A scanner that succeeds and consumes all the characters until the
'\n' character
if the current input starts with the string literal begin . |
static Parser<Void> |
many(CharPredicate predicate)
A scanner that scans greedily for 0 or more characters that satisfies the given CharPredicate.
|
static Parser<Void> |
many(Pattern pattern,
String name)
Deprecated.
Use
pattern.many().toScanner(name) . |
static Parser<Void> |
many1(CharPredicate predicate)
A scanner that scans greedily for 1 or more characters that satisfies the given CharPredicate.
|
static Parser<Void> |
many1(Pattern pattern,
String name)
Deprecated.
Use
pattern.many1().toScanner(name) . |
static Parser<Void> |
nestableBlockComment(Parser<?> begin,
Parser<?> end,
Parser<?> commented)
A scanner for a nestable block comment that starts with
begin and ends with
end . |
static Parser<Void> |
nestableBlockComment(String begin,
String end)
A scanner for a nestable block comment that starts with
begin and ends with
end . |
static Parser<Void> |
nestableBlockComment(String begin,
String end,
Pattern commented)
A scanner for a nestable block comment that starts with
begin and ends with
end . |
static Parser<Void> |
nestedScanner(Parser<?> outer,
Parser<Void> inner)
A scanner that after character level
outer succeeds,
subsequently feeds the recognized characters to inner for a nested scanning. |
static Parser<Void> |
notAmong(String chars)
A scanner that succeeds and consumes the current character if it is not equal to any character
in
chars . |
static Parser<Void> |
notAmong(String chars,
String name)
Deprecated.
Use
Patterns.among(chars).not().toScanner(name) ,
or isChar(CharPredicates.notAmong(chars), name) . |
static Parser<Void> |
notChar(char ch)
A scanner that succeeds and consumes the current character if it is not equal to
ch . |
static Parser<Void> |
notChar(char ch,
String name)
Deprecated.
Use
notChar(char) . |
static Parser<Void> |
pattern(Pattern pattern,
String name)
Deprecated.
Use
pattern.toScanner(name) . |
static Parser<String> |
quoted(char begin,
char end)
A scanner for a quoted string that starts with character
begin and ends with character
end . |
static Parser<String> |
quoted(Parser<Void> begin,
Parser<Void> end,
Parser<?> quoted)
Deprecated.
Use
Parsers.sequence(begin, quoted.skipMany(), end).source() . |
static Parser<Void> |
string(String str)
Matches the input against the specified string.
|
static Parser<Void> |
string(String str,
String name)
Deprecated.
Use
Patterns.string(str).toScanner(name) . |
static Parser<Void> |
stringCaseInsensitive(String str)
A scanner that matches the input against the specified string case insensitively.
|
static Parser<Void> |
stringCaseInsensitive(String str,
String name)
Deprecated.
Use
Patterns.stringCaseInsensitive(str).toScanner(name) . |
public static final Parser<Void> WHITESPACES
public static final Parser<Void> ANY_CHAR
Parsers.always()
,
it fails on EOF. Also it consumes the current character in the input.public static final Parser<Void> JAVA_LINE_COMMENT
public static final Parser<Void> SQL_LINE_COMMENT
public static final Parser<Void> HASKELL_LINE_COMMENT
--
)public static final Parser<Void> JAVA_BLOCK_COMMENT
public static final Parser<Void> SQL_BLOCK_COMMENT
public static final Parser<Void> HASKELL_BLOCK_COMMENT
public static final Parser<String> SINGLE_QUOTE_STRING
public static final Parser<String> DOUBLE_QUOTE_STRING
public static final Parser<String> SINGLE_QUOTE_CHAR
public static final Parser<Void> JAVA_DELIMITER
public static final Parser<Void> HASKELL_DELIMITER
public static final Parser<Void> SQL_DELIMITER
public static final Parser<String> IDENTIFIER
public static final Parser<String> DEC_INTEGER
public static final Parser<String> OCT_INTEGER
public static final Parser<String> HEX_INTEGER
0x
or 0X
.public static Parser<Void> many(CharPredicate predicate)
predicate
- the predicate object.public static Parser<Void> many1(CharPredicate predicate)
predicate
- the predicate object.@Deprecated public static Parser<Void> many(Pattern pattern, String name)
pattern.many().toScanner(name)
.pattern
- the pattern object.name
- the name of what's expected logically. Is used in error message.@Deprecated public static Parser<Void> many1(Pattern pattern, String name)
pattern.many1().toScanner(name)
.pattern
- the pattern object.name
- the name of what's expected logically. Is used in error message.public static Parser<Void> string(String str)
str
- the string to match@Deprecated public static Parser<Void> string(String str, String name)
Patterns.string(str).toScanner(name)
.str
- the string to matchname
- the name of what's expected logically. Is used in error message.@Deprecated public static Parser<Void> pattern(Pattern pattern, String name)
pattern.toScanner(name)
.pattern
- the pattern object.name
- the name of what's expected logically. Is used in error message.@Deprecated public static Parser<Void> stringCaseInsensitive(String str, String name)
Patterns.stringCaseInsensitive(str).toScanner(name)
.str
- the string to matchname
- the name of what's expected logically. Is used in error message.public static Parser<Void> stringCaseInsensitive(String str)
str
- the string to matchpublic static Parser<Void> isChar(CharPredicate predicate)
CharPredicate
.predicate
- the predicate.@Deprecated public static Parser<Void> isChar(CharPredicate predicate, String name)
Object.toString()
in the CharPredicate
,
or use Patterns.isChar(predicate).toScanner(name)
.CharPredicate
.predicate
- the predicate.name
- the name of what's expected logically. Is used in error message.@Deprecated public static Parser<Void> isChar(char ch, String name)
isChar(char)
instead
or use Patterns.isChar(ch).toScanner(name)
.ch
.ch
- the expected character.name
- the name of what's expected logically. Is used in error message.public static Parser<Void> isChar(char ch)
ch
.ch
- the expected character.@Deprecated public static Parser<Void> notChar(char ch, String name)
notChar(char)
.ch
.ch
- the expected character.name
- the name of what's expected logically. Is used in error message.public static Parser<Void> notChar(char ch)
ch
.ch
- the expected character.@Deprecated public static Parser<Void> among(String chars, String name)
Patterns.among(chars).toScanner(name)
.chars
.chars
- the characters.name
- the name of what's expected logically. Is used in error message.public static Parser<Void> among(String chars)
chars
.@Deprecated public static Parser<Void> notAmong(String chars, String name)
Patterns.among(chars).not().toScanner(name)
,
or isChar(CharPredicates.notAmong(chars), name)
.chars
.chars
- the characters.name
- the name of what's expected logically. Is used in error message.public static Parser<Void> notAmong(String chars)
chars
.public static Parser<Void> lineComment(String begin)
'\n'
character
if the current input starts with the string literal begin
. The '\n'
character
isn't consumed.public static Parser<Void> blockComment(String begin, String end)
begin
and ends with
end
.public static Parser<Void> blockComment(String begin, String end, Pattern commented)
begin
and ends with
end
.begin
- begins a block commentend
- ends a block commentcommented
- the commented pattern.public static Parser<Void> blockComment(Parser<Void> begin, Parser<Void> end, Parser<?> commented)
begin
and ends with
end
.begin
- begins a block commentend
- ends a block commentcommented
- the commented pattern.public static Parser<Void> nestableBlockComment(String begin, String end)
begin
and ends with
end
.begin
- begins a block commentend
- ends a block commentpublic static Parser<Void> nestableBlockComment(String begin, String end, Pattern commented)
begin
and ends with
end
.begin
- begins a block commentend
- ends a block commentcommented
- the commented pattern except for nested comments.public static Parser<Void> nestableBlockComment(Parser<?> begin, Parser<?> end, Parser<?> commented)
begin
and ends with
end
.begin
- starts a block commentend
- ends a block commentcommented
- the commented pattern except for nested comments.public static Parser<String> quoted(char begin, char end)
begin
and ends with character
end
.@Deprecated public static Parser<String> quoted(Parser<Void> begin, Parser<Void> end, Parser<?> quoted)
Parsers.sequence(begin, quoted.skipMany(), end).source()
.begin
and ends with end
.begin
- begins a quoteend
- ends a quotequoted
- the parser that recognizes the quoted pattern.public static Parser<Void> nestedScanner(Parser<?> outer, Parser<Void> inner)
outer
succeeds,
subsequently feeds the recognized characters to inner
for a nested scanning.
Is useful for scenarios like parsing string interpolation grammar, with parsing errors correctly pointing to the right location in the original source.
Copyright © 2013–2018 jparsec. All rights reserved.