Top Description Fields Constructors Methods
org.jparsec

public final Class Scanners

extends Object
Class Inheritance
Imports
org.jparsec.pattern.CharPredicate, .CharPredicates, .Pattern, .Patterns

Provides common 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.

Author
Ben Yu

Field Summary

Modifier and TypeField and Description
public static final Parser<Void>
ANY_CHAR

Matches any character in the input.

public static final Parser<String>
DEC_INTEGER

Scanner for a decimal number.

public static final Parser<String>
DECIMAL

Scanner for a decimal number.

public static final Parser<String>
DOUBLE_QUOTE_STRING

Scanner with a pattern for double quoted string literal.

public static final Parser<Void>
HASKELL_BLOCK_COMMENT

Scanner for haskell style block comment.

public static final Parser<Void>
HASKELL_DELIMITER

Scanner for the haskell style delimiter of tokens.

public static final Parser<Void>
HASKELL_LINE_COMMENT

Scanner for haskell style line comment.

public static final Parser<String>
HEX_INTEGER

Scanner for a hexadecimal number.

public static final 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.

public static final Parser<String>
INTEGER

Scanner for an integer.

public static final Parser<Void>
JAVA_BLOCK_COMMENT

Scanner for c++/java style block comment.

private static final Parser<Void>
public static final Parser<Void>
JAVA_DELIMITER

Scanner for the c++/java style delimiter of tokens.

public static final Parser<Void>
JAVA_LINE_COMMENT

Scanner for c++/java style line comment.

public static final Parser<String>
OCT_INTEGER

Scanner for a octal number.

public static final Parser<String>
SCIENTIFIC_NOTATION

Scanner for a scientific notation.

public static final Parser<String>
SINGLE_QUOTE_CHAR

Scanner for a c/c++/java style character literal.

public static final Parser<String>
SINGLE_QUOTE_STRING

Scanner with a pattern for SQL style string literal.

public static final Parser<Void>
SQL_BLOCK_COMMENT

Scanner for SQL style block comment.

public static final Parser<Void>
SQL_DELIMITER

Scanner for the SQL style delimiter of tokens.

public static final Parser<Void>
SQL_LINE_COMMENT

Scanner for SQL style line comment.

public static final Parser<Void>
WHITESPACES

A scanner that scans greedily for 1 or more whitespace characters.

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public static Parser<Void>

Returns:

the scanner.
among
(String
the characters.
chars
,
String
the name of what's expected logically. Is used in error message.
name
)
Deprecated Use Patterns.among(chars).toScanner(name).

A scanner that succeeds and consumes the current character if it equals to any character in chars.

public static Parser<Void>
among(String chars)

A scanner that succeeds and consumes the current character if it equals to any character in chars.

public static Parser<Void>
blockComment(String begin, String end)

A scanner for non-nested block comment that starts with begin and ends with end.

public static Parser<Void>

Returns:

the Scanner for the block comment.
blockComment
(String
begins a block comment
begin
,
String
ends a block comment
end
,
Pattern
the commented pattern.
commented
)

A scanner for a non-nestable block comment that starts with begin and ends with end.

public static Parser<Void>

Returns:

the Scanner for the block comment.
blockComment
(Parser<Void>
begins a block comment
begin
,
Parser<Void>
ends a block comment
end
,
Parser<?>
the commented pattern.
commented
)

A scanner for a non-nestable block comment that starts with begin and ends with end.

private static Pattern
escapedChar(char escape)

public static Parser<Void>

Returns:

the scanner.
isChar
(final CharPredicate
the predicate.
predicate
)

A scanner that succeeds and consumes the current character if it satisfies the given CharPredicate.

public static Parser<Void>

Returns:

the scanner.
isChar
(CharPredicate
the predicate.
predicate
,
String
the name of what's expected logically. Is used in error message.
name
)
Deprecated Implement Object#toString in the CharPredicate, or use Patterns.isChar(predicate).toScanner(name).

A scanner that succeeds and consumes the current character if it satisfies the given CharPredicate.

public static Parser<Void>

Returns:

the scanner.
isChar
(char
the expected character.
ch
,
String
the name of what's expected logically. Is used in error message.
name
)
Deprecated Use isChar(char) instead or use Patterns.isChar(ch).toScanner(name).

A scanner that succeeds and consumes the current character if it is equal to ch.

public static Parser<Void>

Returns:

the scanner.
isChar
(char
the expected character.
ch
)

A scanner that succeeds and consumes the current character if it is equal to ch.

public 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.

public static Parser<Void>

Returns:

the Parser object.
many
(CharPredicate
the predicate object.
predicate
)

A scanner that scans greedily for 0 or more characters that satisfies the given CharPredicate.

public static Parser<Void>

Returns:

the Parser object.
many
(Pattern
the pattern object.
pattern
,
String
the name of what's expected logically. Is used in error message.
name
)
Deprecated Use pattern.many().toScanner(name).

A scanner that scans greedily for 0 or more occurrences of the given pattern.

public static Parser<Void>

Returns:

the Parser object.
many1
(CharPredicate
the predicate object.
predicate
)

A scanner that scans greedily for 1 or more characters that satisfies the given CharPredicate.

public static Parser<Void>

Returns:

the Parser object.
many1
(Pattern
the pattern object.
pattern
,
String
the name of what's expected logically. Is used in error message.
name
)
Deprecated Use pattern.many1().toScanner(name).

A scanner that scans greedily for 1 or more occurrences of the given pattern.

public static Parser<Void>

Returns:

the block comment scanner.
nestableBlockComment
(String
begins a block comment
begin
,
String
ends a block comment
end
)

A scanner for a nestable block comment that starts with begin and ends with end.

public static Parser<Void>

Returns:

the block comment scanner.
nestableBlockComment
(String
begins a block comment
begin
,
String
ends a block comment
end
,
Pattern
the commented pattern except for nested comments.
commented
)

A scanner for a nestable block comment that starts with begin and ends with end.

public static Parser<Void>

Returns:

the block comment scanner.
nestableBlockComment
(Parser<?>
starts a block comment
begin
,
Parser<?>
ends a block comment
end
,
Parser<?>
the commented pattern except for nested comments.
commented
)

A scanner for a nestable block comment that starts with begin and ends with end.

public static Parser<Void>
nestedScanner(final Parser<?> outer, final Parser<Void> inner)

A scanner that after character level outer succeeds, subsequently feeds the recognized characters to inner for a nested scanning.

public static Parser<Void>

Returns:

the scanner.
notAmong
(String
the characters.
chars
,
String
the name of what's expected logically. Is used in error message.
name
)
Deprecated Use Patterns.among(chars).not().toScanner(name), or isChar(CharPredicates.notAmong(chars), name).

A scanner that succeeds and consumes the current character if it is not equal to any character in chars.

public 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.

public static Parser<Void>

Returns:

the scanner.
notChar
(char
the expected character.
ch
,
String
the name of what's expected logically. Is used in error message.
name
)
Deprecated Use notChar(char).

A scanner that succeeds and consumes the current character if it is equal to ch.

public static Parser<Void>

Returns:

the scanner.
notChar
(char
the expected character.
ch
)

A scanner that succeeds and consumes the current character if it is not equal to ch.

private static Pattern

Returns:

the Pattern object.
notChar2
(final char c1, final char c2)

Matches a character if the input has at least 1 character, or if the input has at least 2 characters with the first 2 characters not being c1 and c2.

public static Parser<Void>

Returns:

the Parser object.
pattern
(final Pattern
the pattern object.
pattern
,
final String
the name of what's expected logically. Is used in error message.
name
)
Deprecated Use pattern.toScanner(name).

A scanner that scans the input for an occurrence of a string pattern.

public static Parser<String>
quoted(char begin, char end)

A scanner for a quoted string that starts with character begin and ends with character end.

public static Parser<String>

Returns:

the scanner.
quoted
(Parser<Void>
begins a quote
begin
,
Parser<Void>
ends a quote
end
,
Parser<?>
the parser that recognizes the quoted pattern.
quoted
)
Deprecated Use Parsers.sequence(begin, quoted.skipMany(), end).source().

A scanner for a quoted string that starts with begin and ends with end.

private static Parser<Void>
quotedBy(Parser<Void> parser, Parser<?> quote)

public static Parser<Void>

Returns:

the scanner.
string
(String
the string to match
str
)

Matches the input against the specified string.

public static Parser<Void>

Returns:

the scanner.
string
(String
the string to match
str
,
String
the name of what's expected logically. Is used in error message.
name
)
Deprecated Use Patterns.string(str).toScanner(name).

Matches the input against the specified string.

public static Parser<Void>

Returns:

the scanner.
stringCaseInsensitive
(String
the string to match
str
,
String
the name of what's expected logically. Is used in error message.
name
)
Deprecated Use Patterns.stringCaseInsensitive(str).toScanner(name).

A scanner that matches the input against the specified string case insensitively.

public static Parser<Void>

Returns:

the scanner.
stringCaseInsensitive
(String
the string to match
str
)

A scanner that matches the input against the specified string case insensitively.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

ANY_CHARback to summary
public static final Parser<Void> ANY_CHAR

Matches any character in the input. Different from Parsers#always(), it fails on EOF. Also it consumes the current character in the input.

DEC_INTEGERback to summary
public static final Parser<String> DEC_INTEGER

Scanner for a decimal number. 0 is not allowed as the leading digit.

DECIMALback to summary
public static final Parser<String> DECIMAL

Scanner for a decimal number.

DOUBLE_QUOTE_STRINGback to summary
public static final Parser<String> DOUBLE_QUOTE_STRING

Scanner with a pattern for double quoted string literal. Backslash '\' is used as escape character.

HASKELL_BLOCK_COMMENTback to summary
public static final Parser<Void> HASKELL_BLOCK_COMMENT

Scanner for haskell style block comment. {- -}

HASKELL_DELIMITERback to summary
public static final Parser<Void> HASKELL_DELIMITER

Scanner for the haskell style delimiter of tokens. For example, whitespaces, line comment and block comment.

HASKELL_LINE_COMMENTback to summary
public static final Parser<Void> HASKELL_LINE_COMMENT

Scanner for haskell style line comment. (--)

HEX_INTEGERback to summary
public static final Parser<String> HEX_INTEGER

Scanner for a hexadecimal number. Has to start with 0x or 0X.

IDENTIFIERback to summary
public static final 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.

INTEGERback to summary
public static final Parser<String> INTEGER

Scanner for an integer.

JAVA_BLOCK_COMMENTback to summary
public static final Parser<Void> JAVA_BLOCK_COMMENT

Scanner for c++/java style block comment.

JAVA_BLOCK_COMMENTEDback to summary
private static final Parser<Void> JAVA_BLOCK_COMMENTED
JAVA_DELIMITERback to summary
public static final Parser<Void> JAVA_DELIMITER

Scanner for the c++/java style delimiter of tokens. For example, whitespaces, line comment and block comment.

JAVA_LINE_COMMENTback to summary
public static final Parser<Void> JAVA_LINE_COMMENT

Scanner for c++/java style line comment.

OCT_INTEGERback to summary
public static final Parser<String> OCT_INTEGER

Scanner for a octal number. 0 is the leading digit.

SCIENTIFIC_NOTATIONback to summary
public static final Parser<String> SCIENTIFIC_NOTATION

Scanner for a scientific notation.

SINGLE_QUOTE_CHARback to summary
public static final Parser<String> SINGLE_QUOTE_CHAR

Scanner for a c/c++/java style character literal. such as 'a' or '\\'.

SINGLE_QUOTE_STRINGback to summary
public static final Parser<String> SINGLE_QUOTE_STRING

Scanner with a pattern for SQL style string literal. A SQL string literal is a string quoted by single quote, a single quote character is escaped by 2 single quotes.

SQL_BLOCK_COMMENTback to summary
public static final Parser<Void> SQL_BLOCK_COMMENT

Scanner for SQL style block comment.

SQL_DELIMITERback to summary
public static final Parser<Void> SQL_DELIMITER

Scanner for the SQL style delimiter of tokens. For example, whitespaces and line comment.

SQL_LINE_COMMENTback to summary
public static final Parser<Void> SQL_LINE_COMMENT

Scanner for SQL style line comment.

WHITESPACESback to summary
public static final Parser<Void> WHITESPACES

A scanner that scans greedily for 1 or more whitespace characters.

Constructor Detail

Scannersback to summary
private Scanners()

Method Detail

amongback to summary
public static Parser<Void> among(String chars, String name)

Deprecated

Use Patterns.among(chars).toScanner(name).

A scanner that succeeds and consumes the current character if it equals to any character in chars.

Parameters
chars:String

the characters.

name:String

the name of what's expected logically. Is used in error message.

Returns:Parser<Void>

the scanner.

Annotations
@Deprecated
amongback to summary
public static Parser<Void> among(String chars)

A scanner that succeeds and consumes the current character if it equals to any character in chars.

blockCommentback to summary
public static Parser<Void> blockComment(String begin, String end)

A scanner for non-nested block comment that starts with begin and ends with end.

blockCommentback to summary
public 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.

Parameters
begin:String

begins a block comment

end:String

ends a block comment

commented:Pattern

the commented pattern.

Returns:Parser<Void>

the Scanner for the block comment.

blockCommentback to summary
public 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.

Parameters
begin:Parser<Void>

begins a block comment

end:Parser<Void>

ends a block comment

commented:Parser<?>

the commented pattern.

Returns:Parser<Void>

the Scanner for the block comment.

escapedCharback to summary
private static Pattern escapedChar(char escape)
isCharback to summary
public static Parser<Void> isChar(final CharPredicate predicate)

A scanner that succeeds and consumes the current character if it satisfies the given CharPredicate.

Parameters
predicate:CharPredicate

the predicate.

Returns:Parser<Void>

the scanner.

isCharback to summary
public static Parser<Void> isChar(CharPredicate predicate, String name)

Deprecated

Implement Object#toString in the CharPredicate, or use Patterns.isChar(predicate).toScanner(name).

A scanner that succeeds and consumes the current character if it satisfies the given CharPredicate.

Parameters
predicate:CharPredicate

the predicate.

name:String

the name of what's expected logically. Is used in error message.

Returns:Parser<Void>

the scanner.

Annotations
@Deprecated
isCharback to summary
public static Parser<Void> isChar(char ch, String name)

Deprecated

Use isChar(char) instead or use Patterns.isChar(ch).toScanner(name).

A scanner that succeeds and consumes the current character if it is equal to ch.

Parameters
ch:char

the expected character.

name:String

the name of what's expected logically. Is used in error message.

Returns:Parser<Void>

the scanner.

Annotations
@Deprecated
isCharback to summary
public static Parser<Void> isChar(char ch)

A scanner that succeeds and consumes the current character if it is equal to ch.

Parameters
ch:char

the expected character.

Returns:Parser<Void>

the scanner.

lineCommentback to summary
public 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. The '\n' character isn't consumed.

manyback to summary
public static Parser<Void> many(CharPredicate predicate)

A scanner that scans greedily for 0 or more characters that satisfies the given CharPredicate.

Parameters
predicate:CharPredicate

the predicate object.

Returns:Parser<Void>

the Parser object.

manyback to summary
public static Parser<Void> many(Pattern pattern, String name)

Deprecated

Use pattern.many().toScanner(name).

A scanner that scans greedily for 0 or more occurrences of the given pattern.

Parameters
pattern:Pattern

the pattern object.

name:String

the name of what's expected logically. Is used in error message.

Returns:Parser<Void>

the Parser object.

Annotations
@Deprecated
many1back to summary
public static Parser<Void> many1(CharPredicate predicate)

A scanner that scans greedily for 1 or more characters that satisfies the given CharPredicate.

Parameters
predicate:CharPredicate

the predicate object.

Returns:Parser<Void>

the Parser object.

many1back to summary
public static Parser<Void> many1(Pattern pattern, String name)

Deprecated

Use pattern.many1().toScanner(name).

A scanner that scans greedily for 1 or more occurrences of the given pattern.

Parameters
pattern:Pattern

the pattern object.

name:String

the name of what's expected logically. Is used in error message.

Returns:Parser<Void>

the Parser object.

Annotations
@Deprecated
nestableBlockCommentback to summary
public static Parser<Void> nestableBlockComment(String begin, String end)

A scanner for a nestable block comment that starts with begin and ends with end.

Parameters
begin:String

begins a block comment

end:String

ends a block comment

Returns:Parser<Void>

the block comment scanner.

nestableBlockCommentback to summary
public 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.

Parameters
begin:String

begins a block comment

end:String

ends a block comment

commented:Pattern

the commented pattern except for nested comments.

Returns:Parser<Void>

the block comment scanner.

nestableBlockCommentback to summary
public 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.

Parameters
begin:Parser<?>

starts a block comment

end:Parser<?>

ends a block comment

commented:Parser<?>

the commented pattern except for nested comments.

Returns:Parser<Void>

the block comment scanner.

nestedScannerback to summary
public static Parser<Void> nestedScanner(final Parser<?> outer, final Parser<Void> inner)

A scanner that after character level 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.

notAmongback to summary
public static Parser<Void> notAmong(String chars, String name)

Deprecated

Use Patterns.among(chars).not().toScanner(name), or isChar(CharPredicates.notAmong(chars), name).

A scanner that succeeds and consumes the current character if it is not equal to any character in chars.

Parameters
chars:String

the characters.

name:String

the name of what's expected logically. Is used in error message.

Returns:Parser<Void>

the scanner.

Annotations
@Deprecated
notAmongback to summary
public 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.

notCharback to summary
public static Parser<Void> notChar(char ch, String name)

Deprecated

Use notChar(char).

A scanner that succeeds and consumes the current character if it is equal to ch.

Parameters
ch:char

the expected character.

name:String

the name of what's expected logically. Is used in error message.

Returns:Parser<Void>

the scanner.

Annotations
@Deprecated
notCharback to summary
public static Parser<Void> notChar(char ch)

A scanner that succeeds and consumes the current character if it is not equal to ch.

Parameters
ch:char

the expected character.

Returns:Parser<Void>

the scanner.

notChar2back to summary
private static Pattern notChar2(final char c1, final char c2)

Matches a character if the input has at least 1 character, or if the input has at least 2 characters with the first 2 characters not being c1 and c2.

Returns:Pattern

the Pattern object.

patternback to summary
public static Parser<Void> pattern(final Pattern pattern, final String name)

Deprecated

Use pattern.toScanner(name).

A scanner that scans the input for an occurrence of a string pattern.

Parameters
pattern:Pattern

the pattern object.

name:String

the name of what's expected logically. Is used in error message.

Returns:Parser<Void>

the Parser object.

Annotations
@Deprecated
quotedback to summary
public static Parser<String> quoted(char begin, char end)

A scanner for a quoted string that starts with character begin and ends with character end.

quotedback to summary
public static Parser<String> quoted(Parser<Void> begin, Parser<Void> end, Parser<?> quoted)

Deprecated

Use Parsers.sequence(begin, quoted.skipMany(), end).source().

A scanner for a quoted string that starts with begin and ends with end.

Parameters
begin:Parser<Void>

begins a quote

end:Parser<Void>

ends a quote

quoted:Parser<?>

the parser that recognizes the quoted pattern.

Returns:Parser<String>

the scanner.

Annotations
@Deprecated
quotedByback to summary
private static Parser<Void> quotedBy(Parser<Void> parser, Parser<?> quote)
stringback to summary
public static Parser<Void> string(String str)

Matches the input against the specified string.

Parameters
str:String

the string to match

Returns:Parser<Void>

the scanner.

stringback to summary
public static Parser<Void> string(String str, String name)

Deprecated

Use Patterns.string(str).toScanner(name).

Matches the input against the specified string.

Parameters
str:String

the string to match

name:String

the name of what's expected logically. Is used in error message.

Returns:Parser<Void>

the scanner.

Annotations
@Deprecated
stringCaseInsensitiveback to summary
public static Parser<Void> stringCaseInsensitive(String str, String name)

Deprecated

Use Patterns.stringCaseInsensitive(str).toScanner(name).

A scanner that matches the input against the specified string case insensitively.

Parameters
str:String

the string to match

name:String

the name of what's expected logically. Is used in error message.

Returns:Parser<Void>

the scanner.

Annotations
@Deprecated
stringCaseInsensitiveback to summary
public static Parser<Void> stringCaseInsensitive(String str)

A scanner that matches the input against the specified string case insensitively.

Parameters
str:String

the string to match

Returns:Parser<Void>

the scanner.