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 withbeginand ends withend.blockComment(String begin, String end, Pattern commented) A scanner for a non-nestable block comment that starts withbeginand ends withend.A scanner for a non-nestable block comment that starts withbeginand ends withend.private static PatternescapedChar(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 withbeginand ends withend.nestableBlockComment(String begin, String end, Pattern commented) A scanner for a nestable block comment that starts withbeginand ends withend.nestableBlockComment(Parser<?> begin, Parser<?> end, Parser<?> commented) A scanner for a nestable block comment that starts withbeginand ends withend.nestedScanner(Parser<?> outer, Parser<Void> inner) A scanner that after character leveloutersucceeds, subsequently feeds the recognized characters toinnerfor 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 PatternnotChar2(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 beingc1andc2.Deprecated.Usepattern.toScanner(name).quoted(char begin, char end) A scanner for a quoted string that starts with characterbeginand 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
-
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
-
SQL_LINE_COMMENT
-
HASKELL_LINE_COMMENT
-
JAVA_BLOCK_COMMENTED
-
JAVA_BLOCK_COMMENT
-
SQL_BLOCK_COMMENT
-
HASKELL_BLOCK_COMMENT
-
SINGLE_QUOTE_STRING
-
DOUBLE_QUOTE_STRING
-
SINGLE_QUOTE_CHAR
-
JAVA_DELIMITER
-
HASKELL_DELIMITER
-
SQL_DELIMITER
-
IDENTIFIER
-
INTEGER
-
DECIMAL
-
DEC_INTEGER
-
OCT_INTEGER
-
HEX_INTEGER
-
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
-
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
-
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
-
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
-
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
-
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
-
lineComment
-
blockComment
-
blockComment
A scanner for a non-nestable block comment that starts withbeginand 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 withbeginand ends withend.- Parameters:
begin- begins a block commentend- ends a block commentcommented- the commented pattern.- Returns:
- the Scanner for the block comment.
-
nestableBlockComment
-
nestableBlockComment
A scanner for a nestable block comment that starts withbeginand 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 withbeginand 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
-
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 withbeginand 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 leveloutersucceeds, subsequently feeds the recognized characters toinnerfor 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 beingc1andc2.- Returns:
- the Pattern object.
-
quotedBy
-
escapedChar
-
Patterns.among(chars).toScanner(name).