forked from digital-asset/daml
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Daml lf type safty (Party & PackageId) (digital-asset#761)
* daml-lf: split SimpleString into Party and PackageId * daml-lf remove parameter from DefinitionRef
- Loading branch information
1 parent
78bf1b8
commit 0489c6e
Showing
132 changed files
with
472 additions
and
466 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
daml-lf/data/src/main/scala/com/digitalasset/daml/lf/data/MatchingStringModule.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
// Copyright (c) 2019 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package com.digitalasset.daml.lf.data | ||
|
||
import scala.util.matching.Regex | ||
|
||
sealed abstract class MatchingStringModule { | ||
type T <: String | ||
|
||
def fromString(s: String): Either[String, T] | ||
|
||
@throws[IllegalArgumentException] | ||
def assertFromString(s: String): T = | ||
fromString(s).fold(e => throw new IllegalArgumentException(e), identity) | ||
|
||
def unapply(x: T): Some[String] = Some(x) | ||
} | ||
|
||
object MatchingStringModule extends (Regex => MatchingStringModule) { | ||
|
||
override def apply(regex: Regex): MatchingStringModule = new MatchingStringModule { | ||
type T = String | ||
|
||
private val pattern = regex.pattern | ||
|
||
def fromString(s: String): Either[String, T] = | ||
Either.cond(pattern.matcher(s).matches(), s, s"""string "$s" does not match regex "$regex"""") | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.