summaryrefslogtreecommitdiff
path: root/src/library/scala/util/parsing/combinator/token/Tokens.scala
blob: ff92802d771f7ce157a77615da825d29ac095f86 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
/*                     __                                               *\
**     ________ ___   / /  ___     Scala API                            **
**    / __/ __// _ | / /  / _ |    (c) 2006-2013, LAMP/EPFL             **
**  __\ \/ /__/ __ |/ /__/ __ |                                         **
** /____/\___/_/ |_/____/_/ | |                                         **
**                          |/                                          **
\*                                                                      */

package scala.util.parsing
package combinator
package token

/** This component provides the notion of `Token`, the unit of information that is passed from lexical
 * parsers in the `Lexical` component to the parsers in the `TokenParsers` component.
 *
 * @author Martin Odersky
 * @author Adriaan Moors
 */
trait Tokens {
  /** Objects of this type are produced by a lexical parser or ``scanner'', and consumed by a parser.
   *
   *  @see [[scala.util.parsing.combinator.syntactical.TokenParsers]]
   */
  abstract class Token {
    def chars: String
  }

  /** A class of error tokens. Error tokens are used to communicate
   *  errors detected during lexical analysis
   */
  case class ErrorToken(msg: String) extends Token {
    def chars = "*** error: "+msg
  }

  /** A class for end-of-file tokens */
  case object EOF extends Token {
    def chars = "<eof>"
  }

  /** This token is produced by a scanner `Scanner` when scanning failed. */
  def errorToken(msg: String): Token = new ErrorToken(msg)
}