Package org.jparsec
Class Scanners
- java.lang.Object
-
- org.jparsec.Scanners
-
public final class Scanners extends java.lang.Object
Provides commonParser
implementations that scan the source and match certain string patterns.Some scanners like
IDENTIFIER
andINTEGER
return the matched string, while others likeWHITESPACES
return nothing, as indicated by theVoid
type parameter. In case the matched string is still needed nonetheless, use theParser.source()
method.
-
-
Field Summary
Fields Modifier and Type Field Description static Parser<java.lang.Void>
ANY_CHAR
Matches any character in the input.static Parser<java.lang.String>
DEC_INTEGER
Scanner for a decimal number.static Parser<java.lang.String>
DECIMAL
Scanner for a decimal number.static Parser<java.lang.String>
DOUBLE_QUOTE_STRING
Scanner with a pattern for double quoted string literal.static Parser<java.lang.Void>
HASKELL_BLOCK_COMMENT
Scanner for haskell style block comment.static Parser<java.lang.Void>
HASKELL_DELIMITER
Scanner for the haskell style delimiter of tokens.static Parser<java.lang.Void>
HASKELL_LINE_COMMENT
Scanner for haskell style line comment.static Parser<java.lang.String>
HEX_INTEGER
Scanner for a hexadecimal number.static Parser<java.lang.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<java.lang.String>
INTEGER
Scanner for an integer.static Parser<java.lang.Void>
JAVA_BLOCK_COMMENT
Scanner for c++/java style block comment.private static Parser<java.lang.Void>
JAVA_BLOCK_COMMENTED
static Parser<java.lang.Void>
JAVA_DELIMITER
Scanner for the c++/java style delimiter of tokens.static Parser<java.lang.Void>
JAVA_LINE_COMMENT
Scanner for c++/java style line comment.static Parser<java.lang.String>
OCT_INTEGER
Scanner for a octal number.static Parser<java.lang.String>
SCIENTIFIC_NOTATION
Scanner for a scientific notation.static Parser<java.lang.String>
SINGLE_QUOTE_CHAR
Scanner for a c/c++/java style character literal.static Parser<java.lang.String>
SINGLE_QUOTE_STRING
Scanner with a pattern for SQL style string literal.static Parser<java.lang.Void>
SQL_BLOCK_COMMENT
Scanner for SQL style block comment.static Parser<java.lang.Void>
SQL_DELIMITER
Scanner for the SQL style delimiter of tokens.static Parser<java.lang.Void>
SQL_LINE_COMMENT
Scanner for SQL style line comment.static Parser<java.lang.Void>
WHITESPACES
A scanner that scans greedily for 1 or more whitespace characters.
-
Constructor Summary
Constructors Modifier Constructor Description private
Scanners()
-
Method Summary
All Methods Static Methods Concrete Methods Deprecated Methods Modifier and Type Method Description static Parser<java.lang.Void>
among(java.lang.String chars)
A scanner that succeeds and consumes the current character if it equals to any character inchars
.static Parser<java.lang.Void>
among(java.lang.String chars, java.lang.String name)
Deprecated.UsePatterns.among(chars).toScanner(name)
.static Parser<java.lang.Void>
blockComment(java.lang.String begin, java.lang.String end)
A scanner for non-nested block comment that starts withbegin
and ends withend
.static Parser<java.lang.Void>
blockComment(java.lang.String begin, java.lang.String end, Pattern commented)
A scanner for a non-nestable block comment that starts withbegin
and ends withend
.static Parser<java.lang.Void>
blockComment(Parser<java.lang.Void> begin, Parser<java.lang.Void> end, Parser<?> commented)
A scanner for a non-nestable block comment that starts withbegin
and ends withend
.private static Pattern
escapedChar(char escape)
static Parser<java.lang.Void>
isChar(char ch)
A scanner that succeeds and consumes the current character if it is equal toch
.static Parser<java.lang.Void>
isChar(char ch, java.lang.String name)
Deprecated.UseisChar(char)
instead or usePatterns.isChar(ch).toScanner(name)
.static Parser<java.lang.Void>
isChar(CharPredicate predicate)
A scanner that succeeds and consumes the current character if it satisfies the givenCharPredicate
.static Parser<java.lang.Void>
isChar(CharPredicate predicate, java.lang.String name)
Deprecated.ImplementObject.toString()
in theCharPredicate
, or usePatterns.isChar(predicate).toScanner(name)
.static Parser<java.lang.Void>
lineComment(java.lang.String begin)
A scanner that succeeds and consumes all the characters until the'\n'
character if the current input starts with the string literalbegin
.static Parser<java.lang.Void>
many(CharPredicate predicate)
A scanner that scans greedily for 0 or more characters that satisfies the given CharPredicate.static Parser<java.lang.Void>
many(Pattern pattern, java.lang.String name)
Deprecated.Usepattern.many().toScanner(name)
.static Parser<java.lang.Void>
many1(CharPredicate predicate)
A scanner that scans greedily for 1 or more characters that satisfies the given CharPredicate.static Parser<java.lang.Void>
many1(Pattern pattern, java.lang.String name)
Deprecated.Usepattern.many1().toScanner(name)
.static Parser<java.lang.Void>
nestableBlockComment(java.lang.String begin, java.lang.String end)
A scanner for a nestable block comment that starts withbegin
and ends withend
.static Parser<java.lang.Void>
nestableBlockComment(java.lang.String begin, java.lang.String end, Pattern commented)
A scanner for a nestable block comment that starts withbegin
and ends withend
.static Parser<java.lang.Void>
nestableBlockComment(Parser<?> begin, Parser<?> end, Parser<?> commented)
A scanner for a nestable block comment that starts withbegin
and ends withend
.static Parser<java.lang.Void>
nestedScanner(Parser<?> outer, Parser<java.lang.Void> inner)
A scanner that after character levelouter
succeeds, subsequently feeds the recognized characters toinner
for a nested scanning.static Parser<java.lang.Void>
notAmong(java.lang.String chars)
A scanner that succeeds and consumes the current character if it is not equal to any character inchars
.static Parser<java.lang.Void>
notAmong(java.lang.String chars, java.lang.String name)
Deprecated.UsePatterns.among(chars).not().toScanner(name)
, orisChar(CharPredicates.notAmong(chars), name)
.static Parser<java.lang.Void>
notChar(char ch)
A scanner that succeeds and consumes the current character if it is not equal toch
.static Parser<java.lang.Void>
notChar(char ch, java.lang.String name)
Deprecated.UsenotChar(char)
.private static Pattern
notChar2(char c1, 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 beingc1
andc2
.static Parser<java.lang.Void>
pattern(Pattern pattern, java.lang.String name)
Deprecated.Usepattern.toScanner(name)
.static Parser<java.lang.String>
quoted(char begin, char end)
A scanner for a quoted string that starts with characterbegin
and ends with characterend
.static Parser<java.lang.String>
quoted(Parser<java.lang.Void> begin, Parser<java.lang.Void> end, Parser<?> quoted)
Deprecated.UseParsers.sequence(begin, quoted.skipMany(), end).source()
.private static Parser<java.lang.Void>
quotedBy(Parser<java.lang.Void> parser, Parser<?> quote)
static Parser<java.lang.Void>
string(java.lang.String str)
Matches the input against the specified string.static Parser<java.lang.Void>
string(java.lang.String str, java.lang.String name)
Deprecated.UsePatterns.string(str).toScanner(name)
.static Parser<java.lang.Void>
stringCaseInsensitive(java.lang.String str)
A scanner that matches the input against the specified string case insensitively.static Parser<java.lang.Void>
stringCaseInsensitive(java.lang.String str, java.lang.String name)
Deprecated.UsePatterns.stringCaseInsensitive(str).toScanner(name)
.
-
-
-
Field Detail
-
WHITESPACES
public static final Parser<java.lang.Void> WHITESPACES
A scanner that scans greedily for 1 or more whitespace characters.
-
ANY_CHAR
public static final Parser<java.lang.Void> ANY_CHAR
Matches any character in the input. Different fromParsers.always()
, it fails on EOF. Also it consumes the current character in the input.
-
JAVA_LINE_COMMENT
public static final Parser<java.lang.Void> JAVA_LINE_COMMENT
Scanner for c++/java style line comment.
-
SQL_LINE_COMMENT
public static final Parser<java.lang.Void> SQL_LINE_COMMENT
Scanner for SQL style line comment.
-
HASKELL_LINE_COMMENT
public static final Parser<java.lang.Void> HASKELL_LINE_COMMENT
Scanner for haskell style line comment. (--
)
-
JAVA_BLOCK_COMMENTED
private static final Parser<java.lang.Void> JAVA_BLOCK_COMMENTED
-
JAVA_BLOCK_COMMENT
public static final Parser<java.lang.Void> JAVA_BLOCK_COMMENT
Scanner for c++/java style block comment.
-
SQL_BLOCK_COMMENT
public static final Parser<java.lang.Void> SQL_BLOCK_COMMENT
Scanner for SQL style block comment.
-
HASKELL_BLOCK_COMMENT
public static final Parser<java.lang.Void> HASKELL_BLOCK_COMMENT
Scanner for haskell style block comment. {- -}
-
SINGLE_QUOTE_STRING
public static final Parser<java.lang.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.
-
DOUBLE_QUOTE_STRING
public static final Parser<java.lang.String> DOUBLE_QUOTE_STRING
Scanner with a pattern for double quoted string literal. Backslash '\' is used as escape character.
-
SINGLE_QUOTE_CHAR
public static final Parser<java.lang.String> SINGLE_QUOTE_CHAR
Scanner for a c/c++/java style character literal. such as 'a' or '\\'.
-
JAVA_DELIMITER
public static final Parser<java.lang.Void> JAVA_DELIMITER
Scanner for the c++/java style delimiter of tokens. For example, whitespaces, line comment and block comment.
-
HASKELL_DELIMITER
public static final Parser<java.lang.Void> HASKELL_DELIMITER
Scanner for the haskell style delimiter of tokens. For example, whitespaces, line comment and block comment.
-
SQL_DELIMITER
public static final Parser<java.lang.Void> SQL_DELIMITER
Scanner for the SQL style delimiter of tokens. For example, whitespaces and line comment.
-
IDENTIFIER
public static final Parser<java.lang.String> IDENTIFIER
Scanner for a regular identifier, that starts with either an underscore or an alpha character, followed by 0 or more alphanumeric characters.
-
INTEGER
public static final Parser<java.lang.String> INTEGER
Scanner for an integer.
-
DECIMAL
public static final Parser<java.lang.String> DECIMAL
Scanner for a decimal number.
-
DEC_INTEGER
public static final Parser<java.lang.String> DEC_INTEGER
Scanner for a decimal number. 0 is not allowed as the leading digit.
-
OCT_INTEGER
public static final Parser<java.lang.String> OCT_INTEGER
Scanner for a octal number. 0 is the leading digit.
-
HEX_INTEGER
public static final Parser<java.lang.String> HEX_INTEGER
Scanner for a hexadecimal number. Has to start with0x
or0X
.
-
SCIENTIFIC_NOTATION
public static final Parser<java.lang.String> SCIENTIFIC_NOTATION
Scanner for a scientific notation.
-
-
Method Detail
-
many
public static Parser<java.lang.Void> many(CharPredicate predicate)
A scanner that scans greedily for 0 or more characters that satisfies the given CharPredicate.- Parameters:
predicate
- the predicate object.- Returns:
- the Parser object.
-
many1
public static Parser<java.lang.Void> many1(CharPredicate predicate)
A scanner that scans greedily for 1 or more characters that satisfies the given CharPredicate.- Parameters:
predicate
- the predicate object.- Returns:
- the Parser object.
-
many
@Deprecated public static Parser<java.lang.Void> many(Pattern pattern, java.lang.String name)
Deprecated.Usepattern.many().toScanner(name)
.A scanner that scans greedily for 0 or more occurrences of the given pattern.- Parameters:
pattern
- the pattern object.name
- the name of what's expected logically. Is used in error message.- Returns:
- the Parser object.
-
many1
@Deprecated public static Parser<java.lang.Void> many1(Pattern pattern, java.lang.String name)
Deprecated.Usepattern.many1().toScanner(name)
.A scanner that scans greedily for 1 or more occurrences of the given pattern.- Parameters:
pattern
- the pattern object.name
- the name of what's expected logically. Is used in error message.- Returns:
- the Parser object.
-
string
public static Parser<java.lang.Void> string(java.lang.String str)
Matches the input against the specified string.- Parameters:
str
- the string to match- Returns:
- the scanner.
-
string
@Deprecated public static Parser<java.lang.Void> string(java.lang.String str, java.lang.String name)
Deprecated.UsePatterns.string(str).toScanner(name)
.Matches the input against the specified string.- Parameters:
str
- the string to matchname
- the name of what's expected logically. Is used in error message.- Returns:
- the scanner.
-
pattern
@Deprecated public static Parser<java.lang.Void> pattern(Pattern pattern, java.lang.String name)
Deprecated.Usepattern.toScanner(name)
.A scanner that scans the input for an occurrence of a string pattern.- Parameters:
pattern
- the pattern object.name
- the name of what's expected logically. Is used in error message.- Returns:
- the Parser object.
-
stringCaseInsensitive
@Deprecated public static Parser<java.lang.Void> stringCaseInsensitive(java.lang.String str, java.lang.String name)
Deprecated.UsePatterns.stringCaseInsensitive(str).toScanner(name)
.A scanner that matches the input against the specified string case insensitively.- Parameters:
str
- the string to matchname
- the name of what's expected logically. Is used in error message.- Returns:
- the scanner.
-
stringCaseInsensitive
public static Parser<java.lang.Void> stringCaseInsensitive(java.lang.String str)
A scanner that matches the input against the specified string case insensitively.- Parameters:
str
- the string to match- Returns:
- the scanner.
-
isChar
public static Parser<java.lang.Void> isChar(CharPredicate predicate)
A scanner that succeeds and consumes the current character if it satisfies the givenCharPredicate
.- Parameters:
predicate
- the predicate.- Returns:
- the scanner.
-
isChar
@Deprecated public static Parser<java.lang.Void> isChar(CharPredicate predicate, java.lang.String name)
Deprecated.ImplementObject.toString()
in theCharPredicate
, or usePatterns.isChar(predicate).toScanner(name)
.A scanner that succeeds and consumes the current character if it satisfies the givenCharPredicate
.- Parameters:
predicate
- the predicate.name
- the name of what's expected logically. Is used in error message.- Returns:
- the scanner.
-
isChar
@Deprecated public static Parser<java.lang.Void> isChar(char ch, java.lang.String name)
Deprecated.UseisChar(char)
instead or usePatterns.isChar(ch).toScanner(name)
.A scanner that succeeds and consumes the current character if it is equal toch
.- Parameters:
ch
- the expected character.name
- the name of what's expected logically. Is used in error message.- Returns:
- the scanner.
-
isChar
public static Parser<java.lang.Void> isChar(char ch)
A scanner that succeeds and consumes the current character if it is equal toch
.- Parameters:
ch
- the expected character.- Returns:
- the scanner.
-
notChar
@Deprecated public static Parser<java.lang.Void> notChar(char ch, java.lang.String name)
Deprecated.UsenotChar(char)
.A scanner that succeeds and consumes the current character if it is equal toch
.- Parameters:
ch
- the expected character.name
- the name of what's expected logically. Is used in error message.- Returns:
- the scanner.
-
notChar
public static Parser<java.lang.Void> notChar(char ch)
A scanner that succeeds and consumes the current character if it is not equal toch
.- Parameters:
ch
- the expected character.- Returns:
- the scanner.
-
among
@Deprecated public static Parser<java.lang.Void> among(java.lang.String chars, java.lang.String name)
Deprecated.UsePatterns.among(chars).toScanner(name)
.A scanner that succeeds and consumes the current character if it equals to any character inchars
.- Parameters:
chars
- the characters.name
- the name of what's expected logically. Is used in error message.- Returns:
- the scanner.
-
among
public static Parser<java.lang.Void> among(java.lang.String chars)
A scanner that succeeds and consumes the current character if it equals to any character inchars
.
-
notAmong
@Deprecated public static Parser<java.lang.Void> notAmong(java.lang.String chars, java.lang.String name)
Deprecated.UsePatterns.among(chars).not().toScanner(name)
, orisChar(CharPredicates.notAmong(chars), name)
.A scanner that succeeds and consumes the current character if it is not equal to any character inchars
.- Parameters:
chars
- the characters.name
- the name of what's expected logically. Is used in error message.- Returns:
- the scanner.
-
notAmong
public static Parser<java.lang.Void> notAmong(java.lang.String chars)
A scanner that succeeds and consumes the current character if it is not equal to any character inchars
.
-
lineComment
public static Parser<java.lang.Void> lineComment(java.lang.String begin)
A scanner that succeeds and consumes all the characters until the'\n'
character if the current input starts with the string literalbegin
. The'\n'
character isn't consumed.
-
blockComment
public static Parser<java.lang.Void> blockComment(java.lang.String begin, java.lang.String end)
A scanner for non-nested block comment that starts withbegin
and ends withend
.
-
blockComment
public static Parser<java.lang.Void> blockComment(java.lang.String begin, java.lang.String end, Pattern commented)
A scanner for a non-nestable block comment that starts withbegin
and ends withend
.- Parameters:
begin
- begins a block commentend
- ends a block commentcommented
- the commented pattern.- Returns:
- the Scanner for the block comment.
-
blockComment
public static Parser<java.lang.Void> blockComment(Parser<java.lang.Void> begin, Parser<java.lang.Void> end, Parser<?> commented)
A scanner for a non-nestable block comment that starts withbegin
and ends withend
.- Parameters:
begin
- begins a block commentend
- ends a block commentcommented
- the commented pattern.- Returns:
- the Scanner for the block comment.
-
nestableBlockComment
public static Parser<java.lang.Void> nestableBlockComment(java.lang.String begin, java.lang.String end)
A scanner for a nestable block comment that starts withbegin
and ends withend
.- Parameters:
begin
- begins a block commentend
- ends a block comment- Returns:
- the block comment scanner.
-
nestableBlockComment
public static Parser<java.lang.Void> nestableBlockComment(java.lang.String begin, java.lang.String end, Pattern commented)
A scanner for a nestable block comment that starts withbegin
and ends withend
.- Parameters:
begin
- begins a block commentend
- ends a block commentcommented
- the commented pattern except for nested comments.- Returns:
- the block comment scanner.
-
nestableBlockComment
public static Parser<java.lang.Void> nestableBlockComment(Parser<?> begin, Parser<?> end, Parser<?> commented)
A scanner for a nestable block comment that starts withbegin
and ends withend
.- Parameters:
begin
- starts a block commentend
- ends a block commentcommented
- the commented pattern except for nested comments.- Returns:
- the block comment scanner.
-
quoted
public static Parser<java.lang.String> quoted(char begin, char end)
A scanner for a quoted string that starts with characterbegin
and ends with characterend
.
-
quoted
@Deprecated public static Parser<java.lang.String> quoted(Parser<java.lang.Void> begin, Parser<java.lang.Void> end, Parser<?> quoted)
Deprecated.UseParsers.sequence(begin, quoted.skipMany(), end).source()
.A scanner for a quoted string that starts withbegin
and ends withend
.- Parameters:
begin
- begins a quoteend
- ends a quotequoted
- the parser that recognizes the quoted pattern.- Returns:
- the scanner.
-
nestedScanner
public static Parser<java.lang.Void> nestedScanner(Parser<?> outer, Parser<java.lang.Void> inner)
A scanner that after character levelouter
succeeds, subsequently feeds the recognized characters toinner
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.
-
notChar2
private static Pattern notChar2(char c1, 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 beingc1
andc2
.- Returns:
- the Pattern object.
-
quotedBy
private static Parser<java.lang.Void> quotedBy(Parser<java.lang.Void> parser, Parser<?> quote)
-
escapedChar
private static Pattern escapedChar(char escape)
-
-