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

Scala example source code file (Position.scala)

This example Scala source code file (Position.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

int, int, position, position, string, string

The Scala Position.scala source code

/*                     __                                               *\
**     ________ ___   / /  ___     Scala API                            **
**    / __/ __// _ | / /  / _ |    (c) 2006-2011, LAMP/EPFL             **
**  __\ \/ /__/ __ |/ /__/ __ |    http://scala-lang.org/               **
** /____/\___/_/ |_/____/_/ | |                                         **
**                          |/                                          **
\*                                                                      */

package scala.util.parsing.input

/** <p>
 *    <code>Position is the base trait for objects describing a
 *    position in a ``document''.
 *  </p>
 *  <p>
 *    It provides functionality for:
 *  </p>
    * <li> generating a visual representation of this position (`longString'); * <li> comparing two positions (`<'). * </ul> * <p> * To use this class for a concrete kind of ``document'', implement the * <code>lineContents method. * </p> * * @author Martin Odersky, Adriaan Moors */ trait Position { /** The line number referred to by the position; line numbers start at 1 */ def line: Int /** The column number referred to by the position; column numbers start at 1 */ def column: Int /** The contents of the line numbered `lnum' (must not contain a new-line character). * * @param lnum a 1-based integer index into the `document' * @return the line at `lnum' (not including a newline) */ protected def lineContents: String /** Returns a string representation of the `Position', of the form `line.column' */ override def toString = ""+line+"."+column /** Returns a more ``visual'' representation of this position. * More precisely, the resulting string consists of two lines: <ol> * <li> the line in the document referred to by this position * <li>a caret indicating the column * * Example: * *<pre> List(this, is, a, line, from, the, document) * ^</pre> */ def longString = lineContents+"\n"+lineContents.take(column-1).map{x => if (x == '\t') x else ' ' } + "^" /** Compare this position to another, by first comparing their line numbers, * and then -- if necessary -- using the columns to break a tie. * * @param `that' a `Position' to compare to this `Position' * @return true if this position's line or (in case of a tie wrt. line numbers) * its column is smaller than the corresponding components of `that' */ def <(that: Position) = { this.line < that.line || this.line == that.line && this.column < that.column } }

Other Scala examples (source code examples)

Here is a short list of links related to this Scala Position.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.