safepickle

Configurable restrictions on Scala syntax and method calls for building DSLs.

License

License

Categories

Categories

Scala Languages
GroupId

GroupId

com.fsist
ArtifactId

ArtifactId

subscala_2.11
Last Version

Last Version

0.1.1
Release Date

Release Date

Type

Type

jar
Description

Description

safepickle
Configurable restrictions on Scala syntax and method calls for building DSLs.
Project URL

Project URL

https://github.com/fsist/safepickle
Project Organization

Project Organization

Sentrix
Source Code Management

Source Code Management

https://github.com/fsist/subscala

Download subscala_2.11

How to add to project

<!-- https://jarcasting.com/artifacts/com.fsist/subscala_2.11/ -->
<dependency>
    <groupId>com.fsist</groupId>
    <artifactId>subscala_2.11</artifactId>
    <version>0.1.1</version>
</dependency>
// https://jarcasting.com/artifacts/com.fsist/subscala_2.11/
implementation 'com.fsist:subscala_2.11:0.1.1'
// https://jarcasting.com/artifacts/com.fsist/subscala_2.11/
implementation ("com.fsist:subscala_2.11:0.1.1")
'com.fsist:subscala_2.11:jar:0.1.1'
<dependency org="com.fsist" name="subscala_2.11" rev="0.1.1">
  <artifact name="subscala_2.11" type="jar" />
</dependency>
@Grapes(
@Grab(group='com.fsist', module='subscala_2.11', version='0.1.1')
)
libraryDependencies += "com.fsist" % "subscala_2.11" % "0.1.1"
[com.fsist/subscala_2.11 "0.1.1"]

Dependencies

compile (3)

Group / Artifact Type Version
org.scala-lang : scala-reflect jar 2.11.7
org.scala-lang : scala-compiler jar 2.11.7
org.scala-lang : scala-library jar 2.11.7

test (4)

Group / Artifact Type Version
org.scalatest : scalatest_2.11 jar 2.2.1
com.chuusai : shapeless_2.11 jar 2.1.0
org.pegdown : pegdown jar 1.4.2
ch.qos.logback : logback-classic jar 1.1.2

Project Modules

There are no modules declared in this project.

subscala

A Scala library that restricts the syntax, types used, or methods called by the code passed to it.

Short overview

subscala.Restrict is a macro that fails compilation if the code passed to it doesn't match the given restrictions. It doesn't affect the result of the compilation if it succeeds.

It can restrict the methods that code may call:

object Test {
  import com.fsist.subscala._
  
  trait AllowLength extends CallTargets.MethodsOf[String] { def length(): Int }
   
  val len = Restrict.targets[Int, AllowLength] {
    "foo".length()
  }
}

This succeeds and val len receives the value 3. On the other hand, if we try this:

val size = Restrict.targets[Int, AllowLength] {
  "foo".size
}

Compilation will fail with error: Calling method scala.Predef.augmentString is disallowed. Let's add the missing methods:

import CallTargets.+
import collection.immutable.StringOps

trait AllowAugment extends CallTargets.MethodsOf[Predef.type] { def augmentString(x: String): StringOps }
trait AllowSize extends CallTargets.MethodsOf[StringOps] { def size: Int }

val size = Restrict.targets[Int, AllowAugment + AllowSize] {
  "foo".size
}

Use cases include:

  • Defining a DSL as a subset of the Scala language (i.e. without a separate parser).
  • Restricting scripts from accessing anything outside a set of interfaces meant for scripting a system.
  • Enforcing rules in a codebase such as not using a particular interface which cannot be marked @deprecated.

For usage examples, see the test code.

Artifacts

Artifacts are published on Maven Central; see the github 'releases' tag for the latest version and for changelogs. Add dependencies to com.fsist:subscala_2.11:VERSION (gradle) or com.fsist % subscala %% VERSION (sbt).

com.fsist

Foresight Security Information Technologies

Versions

Version
0.1.1
0.1.0