本文整理汇总了Scala中scala.util.parsing.input.Positional类的典型用法代码示例。如果您正苦于以下问题:Scala Positional类的具体用法?Scala Positional怎么用?Scala Positional使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Positional类的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Scala代码示例。
示例1: ConcordanceParser
//设置package包名称以及导入依赖的类
package com.phasmid.concordance
import scala.util.parsing.combinator._
import scala.util.parsing.input.Positional
import scala.io.Source
import scala.collection.immutable.Map
class ConcordanceParser extends RegexParsers {
val rWord = """[\w’]+[,;\.\-\?\!\—]?""".r
def word: Parser[PositionalString] = positioned(regex(rWord) ^^ {w => PositionalString(w)})
def sentence: Parser[Seq[PositionalString]] = rep(word)
}
case class PositionalString(s: String) extends Positional
object ConcordanceParser {
def main(args: Array[String]): Unit = {
val docs = for (f <- args) yield Source.fromFile(f).mkString
val concordance = for (i <- 0 to docs.length-1) yield (args(i),parseDoc(docs(i)))
println(concordance)
// an alternative way of looking at the data (gives doc, page, line and char numbers with each string)
val q = for {(d,xxxx) <- concordance; (p,xxx) <- xxxx; (l,xx) <- xxx; (_,c,x) <- xx} yield (d, p,l,c,x)
println(q)
// yet another way to look at the data
val concordanceMap = concordance.toMap
println(concordanceMap)
}
def parseDoc(content: String) = {
val pages = for (p <- content.split("/p")) yield p
for (i <- 0 to pages.length-1) yield (i+1,parsePage(pages(i)))
}
def parsePage(content: String) = {
val lines = for (l <- content.split("\n")) yield l
for (i <- 0 to lines.length-1) yield (i+1,parseLine(lines(i)))
}
def parseLine(line: String): Seq[(Int,Int,String)] = {
def tidy(s: String) = s.replaceAll("""[,;\.\-\?\!\—]""", "")
val p = new ConcordanceParser
val r = p.parseAll(p.sentence,line) match {
case p.Success(ws,_) => ws
case p.Failure(e,_) => println(e); List()
case _ => println("PositionalParser: logic error"); List()
}
r map {case p @ PositionalString(s) => (p.pos.line,p.pos.column,tidy(s).toLowerCase)}
}
}
开发者ID:menezesl,项目名称:Scala-repo,代码行数:52,代码来源:ConcordanceParser.scala
示例2: Expression
//设置package包名称以及导入依赖的类
package inox
package parsing
import scala.util.parsing.input.Positional
trait IR {
type Identifier // Identifier of the language.
type Type // Types.
type Operator // Primitive operators.
type Value // Literal values.
type Field // Fields.
type Quantifier // Quantifiers.
abstract class Expression(pre: String) extends Positional with Product {
override def productPrefix = pos + "@" + pre
}
case class Variable(identifier: Identifier) extends Expression("Variable")
case class Application(callee: Expression, args: Seq[Expression]) extends Expression("Application")
case class Abstraction(quantifier: Quantifier, bindings: Seq[(Identifier, Option[Type])], body: Expression) extends Expression("Abstraction")
case class Operation(operator: Operator, args: Seq[Expression]) extends Expression("Operation")
case class Selection(structure: Expression, field: Field) extends Expression("Selection")
case class Literal(value: Value) extends Expression("Literal")
case class TypeApplication(callee: Expression, args: Seq[Type]) extends Expression("TypeApplication")
case class Let(bindings: Seq[(Identifier, Option[Type], Expression)], body: Expression) extends Expression("Let")
}
开发者ID:epfl-lara,项目名称:inox,代码行数:28,代码来源:IR.scala
示例3: AndThen
//设置package包名称以及导入依赖的类
package co.language.parser
import scala.util.parsing.input.Positional
sealed trait WorkflowAST extends Positional
case class AndThen(step1: WorkflowAST, step2: WorkflowAST) extends WorkflowAST
case class ReadInput(inputs: Seq[String]) extends WorkflowAST
case class CallService(serviceName: String) extends WorkflowAST
case class Choice(alternatives: Seq[ConditionThen]) extends WorkflowAST
case object Exit extends WorkflowAST
sealed trait ConditionThen extends Positional { def thenBlock: WorkflowAST }
case class IfThen(predicate: Condition, thenBlock: WorkflowAST) extends ConditionThen
case class OtherwiseThen(thenBlock: WorkflowAST) extends ConditionThen
sealed trait Condition extends Positional
case class Equals(factName: String, factValue: String) extends Condition
// BEGIN LANGUAGE DEFINITION
// case class Declarations(variables: Seq[WorkflowAST]) extends WorkflowAST
sealed trait Attribute extends Positional
case class AttributeToValue(attrName: String, attrValue: Value) extends Attribute
case class AttributeToList(attrName: String, attrValue: Seq[Value]) extends Attribute
case class Enum(enumType: String, value: String) extends WorkflowAST
sealed trait Declaration extends WorkflowAST
case class Variable(key: String, value: Value) extends Declaration
sealed trait Value extends Positional
case class StringValue(value: String) extends Value
case class EnumValue(value: Enum) extends Value
case class ConstructorValue(value: Constructor) extends Value
case class VariableValue(key: String) extends Value
// LANGUAGE KEYWORDS (CONSTRUCTORS)
sealed trait Constructor extends WorkflowAST
case class App(attributes: Seq[Attribute]) extends Constructor
case class Page(attributes: Seq[Attribute]) extends Constructor
case class Template(attributes: Seq[Attribute]) extends Constructor
case class Component(attributes: Seq[Attribute]) extends Constructor
case class Event(attributes: Seq[Attribute]) extends Constructor
case class Listener(attributes: Seq[Attribute]) extends Constructor
case class Filter(attributes: Seq[Attribute]) extends Constructor
case class Connective(attributes: Seq[Attribute]) extends Constructor
case class Expression(attributes: Seq[Attribute]) extends Constructor
case class Arg(attributes: Seq[Attribute]) extends Constructor
case class ReferenceArg(attributes: Seq[Attribute]) extends Constructor
case class PrimitiveArg(attributes: Seq[Attribute]) extends Constructor
case class Entity(attributes: Seq[Attribute]) extends Constructor
case class Property(attributes: Seq[Attribute]) extends Constructor
开发者ID:adityaviswanathan,项目名称:parser-combinator,代码行数:53,代码来源:WorkflowAST.scala
示例4: TypedElementProperty
//设置package包名称以及导入依赖的类
package de.dfki.cps.specific.sysml
import scala.util.parsing.input.Positional
sealed trait TypedElementProperty extends Positional
sealed trait OperationProperty extends TypedElementProperty
sealed trait AttributeProperty extends TypedElementProperty
sealed trait ReferenceProperty extends TypedElementProperty
object TypedElementProperty {
case class Ordered(value: Boolean) extends TypedElementProperty with AttributeProperty with OperationProperty with ReferenceProperty
case class Unique(value: Boolean) extends TypedElementProperty with AttributeProperty with OperationProperty with ReferenceProperty
}
object OperationProperty {
case class Query(value: Boolean) extends OperationProperty
}
object ReferenceProperty {
case class Subsets(ref: UnprocessedConstraint) extends ReferenceProperty
}
object AttributeProperty {
case class ReadOnly(value: Boolean) extends AttributeProperty
}
开发者ID:DFKI-CPS,项目名称:specific-sysml,代码行数:26,代码来源:ElementProperties.scala
示例5: at
//设置package包名称以及导入依赖的类
package de.dfki.cps.specific.sysml
import scala.util.parsing.input.Positional
import org.eclipse.uml2.uml.{ Element => UMLElement }
trait FilePositional extends Positional {
var file: String = "nosource://"
}
trait Element extends FilePositional {
private [sysml] var uml = Option.empty[UMLElement]
def at(position: FilePositional): this.type = {
this.setPos(position.pos)
this.file = position.file
this
}
}
trait NamedElement extends Element {
def name: String
}
开发者ID:DFKI-CPS,项目名称:specific-sysml,代码行数:23,代码来源:Element.scala
示例6: SysMLTokens
//设置package包名称以及导入依赖的类
package specific.sysml.parser
import de.dfki.cps.specific.ocl.parser.OclTokens
import scala.collection.SortedSet
import scala.util.parsing.combinator.token.Tokens
import scala.util.parsing.input.Positional
object SysMLTokens {
type Token = OclTokens.Token
type Delimiter = OclTokens.Delimiter
case class SysmlComment(chars: String) extends Token with Positional
sealed trait Indentation extends Token { val n: Int; val chars = "" }
object Indentation {
case object None extends Indentation { val n = 0 }
case class Tabs(n: Int) extends Indentation {
override def toString = s"$n tabs"
}
case class Spaces(n: Int) extends Indentation {
override def toString = s"$n spaces"
}
}
sealed trait IndentationToken extends Token { val chars = "" }
case object SEPARATOR extends IndentationToken {
override def toString = "end of line"
}
case object INDENT extends IndentationToken {
override def toString = "start of indented block"
}
case object DEDENT extends IndentationToken {
override def toString = "end of indented block"
}
case class UNMATCHED_DEDENT(indentation: Indentation) extends IndentationToken {
override def toString = s"unmatched dedentation (no previous line was indented with $indentation)"
}
case class INCONSISTENT_INDENTATION(before: Indentation, now: Indentation) extends IndentationToken {
override def toString = s"inconsistent indentation (started with $before and continued with $now)"
}
case class MIXED_INDENTATION(start: Indentation) extends IndentationToken {
override def toString = start match {
case Indentation.Spaces(n) => s"mixed indentation characters in one line (tab afer $n spaces)"
case Indentation.Tabs(n) => s"mixed indentation characters in one line (space afer $n tabs)"
case Indentation.None => sys.error("invalid indentation state")
}
}
val delimiters = OclTokens.delimiters ++ SortedSet[Delimiter](
ELIPSIS, HASH, LEFT_ARROW, TILDE
) (Ordering.by[Delimiter,(Int,String)](k => (k.chars.length, k.chars)).reverse)
case object ELIPSIS extends Delimiter("..")
case object HASH extends Delimiter("#")
case object LEFT_ARROW extends Delimiter("<-")
case object TILDE extends Delimiter("~")
}
开发者ID:DFKI-CPS,项目名称:specific-sysml,代码行数:61,代码来源:SysMLTokens.scala
示例7: at
//设置package包名称以及导入依赖的类
package de.dfki.cps.specific.sysml
import scala.util.parsing.input.Positional
sealed trait Name extends Positional {
val parts: Seq[String]
def at(pos: Positional): this.type = {
this.pos = pos.pos
this
}
}
case class SimpleName(name: String) extends Name {
override def toString = s"?$name"
val parts = Seq(name)
}
case class PathName(parts: Seq[String]) extends Name {
override def toString = "?" + parts.mkString("::")
}
case class ResolvedName[T <: NamedElement](element: T) extends Name {
val parts = Seq(element.name)
}
开发者ID:DFKI-CPS,项目名称:specific-sysml,代码行数:25,代码来源:Name.scala
示例8: Print
//设置package包名称以及导入依赖的类
package mur
import scala.collection.mutable
import scala.util.parsing.input.{Position, Positional}
sealed trait Stmt extends Positional
case class Print(str: String) extends Stmt
case class Out(expr: Expr) extends Stmt
case class VarDef(identifier: String, expr: Expr) extends Stmt
case class Program(stmts: Seq[Stmt])
object Program {
def positions(prog: Program, set: mutable.Set[Position]): Unit = {
prog.stmts foreach {stmt =>
set.add(stmt.pos)
stmt match {
case _: Print => ()
case Out(expr) =>
Expr.positions(expr, set)
case VarDef(_, expr) =>
Expr.positions(expr, set)
}
}
}
}
开发者ID:MaxGekk,项目名称:mur,代码行数:27,代码来源:IR.scala
示例9: IDENTIFIER
//设置package包名称以及导入依赖的类
package co.enear.parsercombinators.lexer
import scala.util.parsing.input.Positional
sealed trait WorkflowToken extends Positional
case class IDENTIFIER(str: String) extends WorkflowToken
case class LITERAL(str: String) extends WorkflowToken
case class INDENTATION(spaces: Int) extends WorkflowToken
case class EXIT() extends WorkflowToken
case class READINPUT() extends WorkflowToken
case class CALLSERVICE() extends WorkflowToken
case class SWITCH() extends WorkflowToken
case class OTHERWISE() extends WorkflowToken
case class COLON() extends WorkflowToken
case class ARROW() extends WorkflowToken
case class EQUALS() extends WorkflowToken
case class COMMA() extends WorkflowToken
case class INDENT() extends WorkflowToken
case class DEDENT() extends WorkflowToken
开发者ID:enear,项目名称:parser-combinators-tutorial,代码行数:21,代码来源:WorkflowToken.scala
示例10: AndThen
//设置package包名称以及导入依赖的类
package co.enear.parsercombinators.parser
import scala.util.parsing.input.Positional
sealed trait WorkflowAST extends Positional
case class AndThen(step1: WorkflowAST, step2: WorkflowAST) extends WorkflowAST
case class ReadInput(inputs: Seq[String]) extends WorkflowAST
case class CallService(serviceName: String) extends WorkflowAST
case class Choice(alternatives: Seq[ConditionThen]) extends WorkflowAST
case object Exit extends WorkflowAST
sealed trait ConditionThen extends Positional { def thenBlock: WorkflowAST }
case class IfThen(predicate: Condition, thenBlock: WorkflowAST) extends ConditionThen
case class OtherwiseThen(thenBlock: WorkflowAST) extends ConditionThen
sealed trait Condition extends Positional
case class Equals(factName: String, factValue: String) extends Condition
开发者ID:enear,项目名称:parser-combinators-tutorial,代码行数:18,代码来源:WorkflowAST.scala
示例11: AssignRelationStatement
//设置package包名称以及导入依赖的类
package xyz.hyperreal.rdb
import scala.util.parsing.input.{Positional, Position}
import xyz.hyperreal.lia.FunctionMap
trait AST
trait StatementAST extends AST
case class AssignRelationStatement( variable: Ident, relation: RelationExpression ) extends StatementAST
case class CreateBaseRelationStatement( base: Ident, columns: List[ColumnDef] ) extends StatementAST
case class DropTableStatement( base: Ident ) extends StatementAST
case class InsertRelationStatement( base: Ident, relation: RelationExpression ) extends StatementAST
case class InsertTupleseqStatement( base: Ident, tupleseq: TupleseqExpression ) extends StatementAST
case class InsertTupleStatement( base: Ident, tupl: TupleExpression ) extends StatementAST
case class DeleteStatement( base: Ident, condition: LogicalExpression ) extends StatementAST
case class UpdateStatement( base: Ident, condition: LogicalExpression, updates: List[(Ident, ValueExpression)] ) extends StatementAST
trait ValueExpression extends AST with Positional
case class FloatLit( n: String ) extends ValueExpression
case class IntegerLit( n: String ) extends ValueExpression
case class StringLit( s: String ) extends ValueExpression
case class MarkLit( m: Mark ) extends ValueExpression
case class ValueVariableExpression( name: Ident ) extends ValueExpression
case class ValueColumnExpression( table: Ident, column: Ident ) extends ValueExpression
case class TupleExpression( t: List[ValueExpression] ) extends ValueExpression
case class BinaryValueExpression( left: ValueExpression, oppos: Position, operation: String, func: FunctionMap, right: ValueExpression ) extends ValueExpression
case class ApplicativeValueExpression( func: ValueExpression, args: List[ValueExpression] ) extends ValueExpression
case class UnaryValueExpression( oppos: Position, operation: String, func: FunctionMap, expr: ValueExpression ) extends ValueExpression
case class LogicalValueExpression( logical: LogicalExpression ) extends ValueExpression
case class AliasValueExpression( expr: ValueExpression, alias: Ident ) extends ValueExpression
trait TupleCollectionExpression extends StatementAST
trait RelationExpression extends TupleCollectionExpression with Positional
case class RelationVariableExpression( name: Ident ) extends RelationExpression
case class ListRelationExpression( columns: List[ColumnSpec], data: List[TupleExpression] ) extends RelationExpression
case class ProjectionRelationExpression( relation: RelationExpression, columns: List[ValueExpression] ) extends RelationExpression
case class SelectionRelationExpression( relation: RelationExpression, condition: LogicalExpression ) extends RelationExpression
case class InnerJoinRelationExpression( left: RelationExpression, condition: LogicalExpression, right: RelationExpression ) extends RelationExpression
case class GroupingRelationExpression( relation: RelationExpression, discriminator: List[ValueExpression], filter: Option[LogicalExpression], cpos: Position, columns: List[ValueExpression] ) extends RelationExpression
trait TupleseqExpression extends TupleCollectionExpression with Positional
case class TupleseqLit( data: List[TupleExpression] ) extends TupleseqExpression
case class SortedTupleseqExpression( relation: RelationExpression, names: List[Ident], ascending: Boolean ) extends TupleseqExpression
trait LogicalExpression extends Positional
case class LiteralLogicalExpression( l: Logical ) extends LogicalExpression
case class ComparisonLogicalExpression( left: ValueExpression, comp: List[(String, FunctionMap, ValueExpression)] ) extends LogicalExpression
case class AndLogicalExpression( left: LogicalExpression, right: LogicalExpression ) extends LogicalExpression
case class OrLogicalExpression( left: LogicalExpression, right: LogicalExpression ) extends LogicalExpression
case class ExistsLogicalExpression( tuples: TupleCollectionExpression ) extends LogicalExpression
case class Ident( pos: Position, name: String )
case class ColumnSpec( name: Ident, typepos: Position, typ: Option[String] )
case class ColumnDef( name: Ident, typepos: Position, typ: Type, pkpos: Position, fkr: Ident, fkc: Ident, unmarkable: Boolean, auto: Boolean )
开发者ID:edadma,项目名称:rdb,代码行数:58,代码来源:AST.scala
示例12: IDENTIFIER
//设置package包名称以及导入依赖的类
package compiler.lexer
import scala.util.parsing.input.Positional
trait Token extends Positional
case class IDENTIFIER(name: String) extends Token
case class NUMBER(value: Int) extends Token
case class BOOLEAN_CONST(value: Boolean) extends Token
case class STRING_LITERAL(value: String) extends Token
case class SEMICOLON() extends Token
case class LEFT_PARENTHESIS() extends Token
case class RIGHT_PARENTHESIS() extends Token
case class DOT() extends Token
case class ASSIGN() extends Token
case class COMMA() extends Token
case class COLON() extends Token
case class EQUALS() extends Token
case class PLUS() extends Token
case class MINUS() extends Token
case class TIMES() extends Token
case class DIVISION() extends Token
case class MODULO() extends Token
case class LESS() extends Token
case class LESS_EQUALS() extends Token
case class GREATER() extends Token
case class GREATER_EQUALS() extends Token
case class NOT_EQUALS() extends Token
case class AND() extends Token
case class OR() extends Token
开发者ID:darthorimar,项目名称:pascalJvm,代码行数:32,代码来源:Token.scala
示例13: ArrayClose
//设置package包名称以及导入依赖的类
package compiler
import scala.util.parsing.input.Positional
case class ArrayClose() extends Positional
case class ArrayKeyword() extends Positional
case class ArrayOpen() extends Positional
case class CloseBrace() extends Positional
case class Equals() extends Positional
case class Identifier(id: String) extends Positional
case class IntegerLiteral(value: Int) extends Positional
case class JSONKey() extends Positional
case class LineEnd() extends Positional
case class OpenBrace() extends Positional
case class StringType() extends Positional
开发者ID:gatkin,项目名称:cDTO,代码行数:17,代码来源:ProtocolAST.scala
注:本文中的scala.util.parsing.input.Positional类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论