Package org.jparsec
Class Scanners
java.lang.Object
org.jparsec.Scanners
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.
-
Field Summary
FieldsModifier and TypeFieldDescriptionMatches any character in the input.Scanner for a decimal number.Scanner for a decimal number.Scanner with a pattern for double quoted string literal.Scanner for haskell style block comment.Scanner for the haskell style delimiter of tokens.Scanner for haskell style line comment.Scanner for a hexadecimal number.Scanner for a regular identifier, that starts with either an underscore or an alpha character, followed by 0 or more alphanumeric characters.Scanner for an integer.Scanner for c++/java style block comment.Scanner for the c++/java style delimiter of tokens.Scanner for c++/java style line comment.Scanner for a octal number.Scanner for a scientific notation.Scanner for a c/c++/java style character literal.Scanner with a pattern for SQL style string literal.Scanner for SQL style block comment.Scanner for the SQL style delimiter of tokens.Scanner for SQL style line comment.A scanner that scans greedily for 1 or more whitespace characters. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionA scanner that succeeds and consumes the current character if it equals to any character inchars
.Deprecated.blockComment
(String begin, String end) A scanner for non-nested block comment that starts withbegin
and ends withend
.blockComment
(String begin, String end, Pattern commented) A scanner for a non-nestable block comment that starts withbegin
and ends withend
.A scanner for a non-nestable block comment that starts withbegin
and ends withend
.private static Pattern
escapedChar
(char escape) isChar
(char ch) A scanner that succeeds and consumes the current character if it is equal toch
.Deprecated.UseisChar(char)
instead or usePatterns.isChar(ch).toScanner(name)
.isChar
(CharPredicate predicate) A scanner that succeeds and consumes the current character if it satisfies the givenCharPredicate
.isChar
(CharPredicate predicate, String name) Deprecated.ImplementObject.toString()
in theCharPredicate
, or usePatterns.isChar(predicate).toScanner(name)
.lineComment
(String begin) A scanner that succeeds and consumes all the characters until the'\n'
character if the current input starts with the string literalbegin
.many
(CharPredicate predicate) A scanner that scans greedily for 0 or more characters that satisfies the given CharPredicate.Deprecated.Usepattern.many().toScanner(name)
.many1
(CharPredicate predicate) A scanner that scans greedily for 1 or more characters that satisfies the given CharPredicate.Deprecated.Usepattern.many1().toScanner(name)
.nestableBlockComment
(String begin, String end) A scanner for a nestable block comment that starts withbegin
and ends withend
.nestableBlockComment
(String begin, String end, Pattern commented) A scanner for a nestable block comment that starts withbegin
and ends withend
.nestableBlockComment
(Parser<?> begin, Parser<?> end, Parser<?> commented) A scanner for a nestable block comment that starts withbegin
and ends withend
.nestedScanner
(Parser<?> outer, Parser<Void> inner) A scanner that after character levelouter
succeeds, subsequently feeds the recognized characters toinner
for a nested scanning.A scanner that succeeds and consumes the current character if it is not equal to any character inchars
.Deprecated.UsePatterns.among(chars).not().toScanner(name)
, orisChar(CharPredicates.notAmong(chars), name)
.notChar
(char ch) A scanner that succeeds and consumes the current character if it is not equal toch
.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
.Deprecated.Usepattern.toScanner(name)
.quoted
(char begin, char end) A scanner for a quoted string that starts with characterbegin
and ends with characterend
.Deprecated.UseParsers.sequence(begin, quoted.skipMany(), end).source()
.Matches the input against the specified string.Deprecated.UsePatterns.string(str).toScanner(name)
.A scanner that matches the input against the specified string case insensitively.stringCaseInsensitive
(String str, String name) Deprecated.UsePatterns.stringCaseInsensitive(str).toScanner(name)
.
-
Field Details
-
WHITESPACES
A scanner that scans greedily for 1 or more whitespace characters. -
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
Scanner for c++/java style line comment. -
SQL_LINE_COMMENT
Scanner for SQL style line comment. -
HASKELL_LINE_COMMENT
Scanner for haskell style line comment. (--
) -
JAVA_BLOCK_COMMENTED
-
JAVA_BLOCK_COMMENT
Scanner for c++/java style block comment. -
SQL_BLOCK_COMMENT
Scanner for SQL style block comment. -
HASKELL_BLOCK_COMMENT
Scanner for haskell style block comment. {- -} -
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
Scanner with a pattern for double quoted string literal. Backslash '\' is used as escape character. -
SINGLE_QUOTE_CHAR
Scanner for a c/c++/java style character literal. such as 'a' or '\\'. -
JAVA_DELIMITER
Scanner for the c++/java style delimiter of tokens. For example, whitespaces, line comment and block comment. -
HASKELL_DELIMITER
Scanner for the haskell style delimiter of tokens. For example, whitespaces, line comment and block comment. -
SQL_DELIMITER
Scanner for the SQL style delimiter of tokens. For example, whitespaces and line comment. -
IDENTIFIER
Scanner for a regular identifier, that starts with either an underscore or an alpha character, followed by 0 or more alphanumeric characters. -
INTEGER
Scanner for an integer. -
DECIMAL
Scanner for a decimal number. -
DEC_INTEGER
Scanner for a decimal number. 0 is not allowed as the leading digit. -
OCT_INTEGER
Scanner for a octal number. 0 is the leading digit. -
HEX_INTEGER
Scanner for a hexadecimal number. Has to start with0x
or0X
. -
SCIENTIFIC_NOTATION
Scanner for a scientific notation.
-
-
Constructor Details
-
Scanners
private Scanners()
-
-
Method Details
-
many
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
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.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.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
Matches the input against the specified string.- Parameters:
str
- the string to match- Returns:
- the scanner.
-
string
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.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.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
A scanner that matches the input against the specified string case insensitively.- Parameters:
str
- the string to match- Returns:
- the scanner.
-
isChar
A scanner that succeeds and consumes the current character if it satisfies the givenCharPredicate
.- Parameters:
predicate
- the predicate.- Returns:
- the scanner.
-
isChar
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.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
A scanner that succeeds and consumes the current character if it is equal toch
.- Parameters:
ch
- the expected character.- Returns:
- the scanner.
-
notChar
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
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.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
A scanner that succeeds and consumes the current character if it equals to any character inchars
. -
notAmong
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
A scanner that succeeds and consumes the current character if it is not equal to any character inchars
. -
lineComment
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
A scanner for non-nested block comment that starts withbegin
and ends withend
. -
blockComment
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
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
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
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<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
A scanner for a quoted string that starts with characterbegin
and ends with characterend
. -
quoted
@Deprecated public static Parser<String> quoted(Parser<Void> begin, Parser<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
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
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
-
escapedChar
-
Patterns.among(chars).toScanner(name)
.