public class ScannerFactory extends java.lang.Object
Every scanner is associated with an origin id that is attached to every token
created by this scanner. It identifies the resource the tokens stem from.
However, the factory does not interpret the content of the originId but
merely passes it on to the scanners (and thus ultimately to the tokens). The
caller of the factory methods in this class thus needs to make sure that the
originIds are sane.
This factory can construct strict scanners (interface IScanner
) and
lenient scanners (interface ILenientScanner
). Strict scanners throw
ScannerException
s if they encounter input they cannot recognize.
Lenient scanners do not throw ScannerException
s, but instead return
tokens with a token type of token class ETokenType.ETokenClass.ERROR
, specifying
the type of error encountered, and resume scanning.
Modifier and Type | Method and Description |
---|---|
static ILenientScanner |
newLenientScanner(ELanguage language,
java.io.File file)
Create a new lenient scanner for a file.
|
static ILenientScanner |
newLenientScanner(ELanguage language,
java.io.Reader reader,
java.lang.String originId)
Create a new lenient scanner that uses the specified reader.
|
static ILenientScanner |
newLenientScanner(ELanguage language,
java.lang.String input,
java.lang.String originId)
Create a new lenient scanner that scans a string.
|
static IScanner |
newScanner(ELanguage language,
java.io.File file)
Create a new strict scanner for a file.
|
static IScanner |
newScanner(ELanguage language,
java.io.Reader reader,
java.lang.String originId)
Create a new strict scanner that uses the specified reader.
|
static IScanner |
newScanner(ELanguage language,
java.lang.String input,
java.lang.String originId)
Create a new strict scanner that scans a string.
|
static IScanner |
strict(ILenientScanner scanner)
Wraps an
ILenientScanner scanner with a StrictScanner . |
public static IScanner newScanner(ELanguage language, java.io.File file) throws java.io.IOException
language
- implementation languagefile
- the file to scanjava.io.IOException
public static ILenientScanner newLenientScanner(ELanguage language, java.io.File file) throws java.io.IOException
language
- implementation languagefile
- the file to scanjava.io.IOException
public static IScanner newScanner(ELanguage language, java.lang.String input, java.lang.String originId)
language
- implementation languageinput
- the string to scanoriginId
- origin id that denotes the resource the tokens stem frompublic static ILenientScanner newLenientScanner(ELanguage language, java.lang.String input, java.lang.String originId)
language
- implementation languageinput
- the string to scanoriginId
- origin id that denotes the resource the tokens stem frompublic static IScanner newScanner(ELanguage language, java.io.Reader reader, java.lang.String originId)
language
- implementation languagereader
- the reader to read the input fromoriginId
- origin id that denotes the resource the tokens stem frompublic static ILenientScanner newLenientScanner(ELanguage language, java.io.Reader reader, java.lang.String originId)
language
- implementation languagereader
- the reader to read the input fromoriginId
- origin id that denotes the resource the tokens stem frompublic static IScanner strict(ILenientScanner scanner)
ILenientScanner
scanner with a StrictScanner
.