Lexer
Attributes
- Graph
-
- Supertypes
- Self type
-
Lexer.type
Members list
Type members
Inherited classlikes
Tokenizes an input source with respect to a sequence of token producers.
Tokenizes an input source with respect to a sequence of token producers.
Attributes
- Inherited from:
- Lexers
- Supertypes
-
class Objecttrait Matchableclass Any
Contains utilities to build lexers.
Contains utilities to build lexers.
Attributes
- Inherited from:
- Lexers
- Supertypes
-
class Objecttrait Matchableclass Any
Associates a regular expression with a token generator.
Associates a regular expression with a token generator.
Attributes
- Inherited from:
- Lexers
- Supertypes
-
trait Serializabletrait Producttrait Equalsclass Objecttrait Matchableclass AnyShow all
Adds methods to build a Producer
from a RegExp
.
Adds methods to build a Producer
from a RegExp
.
Attributes
- Inherited from:
- Lexers
- Supertypes
-
class Objecttrait Matchableclass Any
Regular expressions over characters.
Regular expressions over characters.
Attributes
- Inherited from:
- RegExps
- Supertypes
-
class Objecttrait Matchableclass Any
Types
Tiny Silex reference: ============================== Silex's lexer essentially allows you to define a list of regular expressions in their order of priority. To tokenize a given input stream of characters, each individual regular expression is applied in turn. If a given expression matches, it is used to produce a token of maximal length. Whenever a regular expression does not match, the expression of next-highest priority is tried. The result is a stream of tokens.
Tiny Silex reference: ============================== Silex's lexer essentially allows you to define a list of regular expressions in their order of priority. To tokenize a given input stream of characters, each individual regular expression is applied in turn. If a given expression matches, it is used to produce a token of maximal length. Whenever a regular expression does not match, the expression of next-highest priority is tried. The result is a stream of tokens.
Regular expressions r
can be built using the following operators:
word("abc")
matches the sequence "abc" exactlyr1 | r2
matches either expressionr1
or expressionr2
r1 ~ r2
matchesr1
followed byr2
oneOf("xy")
matches either "x" or "y" (i.e., it is a shorthand ofword
and|
for single characters)elem(c)
matches characterc
elem(f)
matches any character for which the boolean predicatef
holdsopt(r)
matchesr
or nothing at allmany(r)
matches any number of repetitions ofr
(including none at all)many1(r)
matches any non-zero number of repetitions ofr
To define the token that should be output for a given expression, one can use the |>
combinator with an expression on the left-hand side and a function producing the token on the right. The function is given the sequence of matched characters and the source-position range as arguments.
For instance,
elem(_.isDigit) ~ word("kg") |> { (cs, range) => WeightLiteralToken(cs.mkString).setPos(range._1)) }
will match a single digit followed by the characters "kg" and turn them into a "WeightLiteralToken" whose value will be the full string matched (e.g. "1kg").
Attributes
Type of positions.
Type of positions.
Attributes
Inherited types
Type of functions that create tokens.
Type of functions that create tokens.
Attributes
- Inherited from:
- Lexers
Value members
Inherited methods
Attributes
- Inherited from:
- Pipeline
Regular expression that accepts only the single character char
.
Regular expression that accepts only the single character char
.
Attributes
- Inherited from:
- RegExps
Regular expression that accepts single characters based on a predicate
.
Regular expression that accepts single characters based on a predicate
.
Attributes
- Inherited from:
- RegExps
Regular expression that accepts zero or more repetitions of regExp
.
Regular expression that accepts zero or more repetitions of regExp
.
Attributes
- Inherited from:
- RegExps
Regular expression that accepts one or more repetitions of regExp
.
Regular expression that accepts one or more repetitions of regExp
.
Attributes
- Inherited from:
- RegExps
Regular expression that accepts any of the characters in chars
.
Regular expression that accepts any of the characters in chars
.
Attributes
- Inherited from:
- RegExps
Regular expression that accepts zero or one instances of regExp
.
Regular expression that accepts zero or one instances of regExp
.
Attributes
- Inherited from:
- RegExps