summaryrefslogtreecommitdiff
path: root/src/parser-combinators/scala/util/parsing/combinator/lexical/Lexical.scala
blob: d8029d068f124ca8d34f022f1a26e2a0baeccc44 (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
/*                     __                                               *\
**     ________ ___   / /  ___     Scala API                            **
**    / __/ __// _ | / /  / _ |    (c) 2006-2013, LAMP/EPFL             **
**  __\ \/ /__/ __ |/ /__/ __ |    http://scala-lang.org/               **
** /____/\___/_/ |_/____/_/ | |                                         **
**                          |/                                          **
\*                                                                      */



package scala
package util.parsing
package combinator
package lexical

import token._
import input.CharArrayReader.EofCh

/** This component complements the `Scanners` component with
 *  common operations for lexical parsers.
 *
 *  Refer to [[scala.util.parsing.combinator.lexical.StdLexical]]
 *  for a concrete implementation for a simple, Scala-like language.
 *
 * @author Martin Odersky, Adriaan Moors
 */
abstract class Lexical extends Scanners with Tokens {

  /** A character-parser that matches a letter (and returns it).*/
  def letter = elem("letter", _.isLetter)

  /** A character-parser that matches a digit (and returns it).*/
  def digit = elem("digit", _.isDigit)

  /** A character-parser that matches any character except the ones given in `cs` (and returns it).*/
  def chrExcept(cs: Char*) = elem("", ch => (cs forall (ch != _)))

  /** A character-parser that matches a white-space character (and returns it).*/
  def whitespaceChar = elem("space char", ch => ch <= ' ' && ch != EofCh)
}