alvinalexander.com | career | drupal | java | mac | mysql | perl | scala | uml | unix  

Scala example source code file (Tokens.scala)

This example Scala source code file (Tokens.scala) is included in the DevDaily.com "Java Source Code Warehouse" project. The intent of this project is to help you "Learn Java by Example" TM.

Java - Scala tags/keywords

eof, eof, errortoken, errortoken, string, string, token, token, tokens

The Scala Tokens.scala source code

/*                     __                                               *\
**     ________ ___   / /  ___     Scala API                            **
**    / __/ __// _ | / /  / _ |    (c) 2006-2011, 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, 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 {@see Scanner} when scanning failed. */
  def errorToken(msg: String): Token = new ErrorToken(msg)  
}

Other Scala examples (source code examples)

Here is a short list of links related to this Scala Tokens.scala source code file:

... this post is sponsored by my books ...

#1 New Release!

FP Best Seller

 

new blog posts

 

Copyright 1998-2021 Alvin Alexander, alvinalexander.com
All Rights Reserved.

A percentage of advertising revenue from
pages under the /java/jwarehouse URI on this website is
paid back to open source projects.