Skip to main content

Domain-Specific Languages with Scala

  • Conference paper
  • First Online:

Part of the book series: Lecture Notes in Computer Science ((LNPSE,volume 9407))

Abstract

Domain-Specific Languages (DSLs) are often classified into external and internal DSLs. An external DSL is a stand-alone language with its own parser. An internal DSL is an extension of an existing programming language, the host language, offering the user of the DSL domain-specific constructs as well as the constructs of the host language, thus providing a richer language than the DSL itself. In this paper we report on experiences implementing external as well as internal formal modeling DSLs with the Scala programming language, known in particular for its support for defining DSLs. The modeling languages include monitoring logics, a testing language, and a general purpose SysML inspired modeling language. We present a systematic overview of advantages and disadvantages of each option.

Part of the work was supported by the Japanese Society for the Promotion of Science (kaken-hi grants 23240003 and 26280019), and by NSF Grant CCF-0926190. Part of the work was carried out at Jet Propulsion Laboratory, California Institute of Technology, under a contract with the National Aeronautics and Space Administration.

This is a preview of subscription content, log in via an institution.

Buying options

Chapter
USD   29.95
Price excludes VAT (USA)
  • Available as PDF
  • Read on any device
  • Instant download
  • Own it forever
eBook
USD   39.99
Price excludes VAT (USA)
  • Available as EPUB and PDF
  • Read on any device
  • Instant download
  • Own it forever
Softcover Book
USD   54.99
Price excludes VAT (USA)
  • Compact, lightweight edition
  • Dispatched in 3 to 5 business days
  • Free shipping worldwide - see info

Tax calculation will be finalised at checkout

Purchases are for personal use only

Learn about institutional subscriptions

Notes

  1. 1.

    The standard Scala library [26] originally included a parser combinator package. However, because it is rarely used, it was moved to an external library [24].

  2. 2.

    A case class in Scala is like a class with the additional properties that it supports pattern matching over objects of the class, that the new keyword is not needed to create objects of the class, and equality is pre-defined based on the arguments.

  3. 3.

    A trait in Scala is a module concept closely related to the notion of an abstract class, as for example found in Java. Traits, however, differ by allowing a more flexible way of composition called mixin composition, an alternative to multiple inheritance.

  4. 4.

    The apply method in Scala has special interpretation: if an object O defines a such, it can be applied to a list of arguments using function application syntax: O(...), equivalent to calling the apply method: O.apply(...).

References

  1. ANTLR: http://www.antlr.org

  2. Artho, C.V., Biere, A., Hagiya, M., Platon, E., Seidl, M., Tanabe, Y., Yamamoto, M.: Modbat: A model-based API tester for event-driven systems. In: Bertacco, V., Legay, A. (eds.) HVC 2013. LNCS, vol. 8244, pp. 112–128. Springer, Heidelberg (2013)

    Chapter  Google Scholar 

  3. Barringer, H., Groce, A., Havelund, K., Smith, M.: Formal analysis of log files. J. Aerosp. Comput. Inf. Commun. 7(11), 365–390 (2010)

    Article  Google Scholar 

  4. Barringer, H., Havelund, K.: TraceContract: A scala DSL for trace analysis. In: Butler, M., Schulte, W. (eds.) FM 2011. LNCS, vol. 6664, pp. 57–72. Springer, Heidelberg (2011)

    Chapter  Google Scholar 

  5. Barringer, H., Havelund, K., Kurklu, E., Morris, R.: Checking flight rules with TraceContract: Application of a Scala DSL for trace analysis. In: Scala Days 2011. Stanford University, California (2011)

    Google Scholar 

  6. Bodden, E.: MOPBox: A library approach to runtime verification. In: Khurshid, S., Sen, K. (eds.) RV 2011. LNCS, vol. 7186, pp. 365–369. Springer, Heidelberg (2012)

    Chapter  Google Scholar 

  7. Bray, T., Paoli, J., Sperberg-McQueen, M., Maler, E., Yergeau, F.: Extensible markup language (XML). World Wide Web Consortium Recommendation REC-xml-19980210 (1998)

    Google Scholar 

  8. Bruneton, E., Lenglet, R., Coupaye, T.: ASM: a code manipulation tool to implement adaptable systems. In: Adaptable and Extensible Component Systems, Grenoble, France (2002)

    Google Scholar 

  9. Forgy, C.: Rete: A fast algorithm for the many pattern/many object pattern match problem. Artif. Intell. 19, 17–37 (1982)

    Article  Google Scholar 

  10. Fowler, M., Parsons, R.: Domain-Specific Languages. Addison-Wesley, Boston (2010)

    Google Scholar 

  11. Fusco, M.: Hammurabi–a Scala rule engine. In: Scala Days 2011. Stanford University, California (2011)

    Google Scholar 

  12. Gansner, E., North, S.: An open graph visualization system and its applications to software engineering. Softw. Pract. Exper. 30(11), 1203–1233 (2000)

    Article  MATH  Google Scholar 

  13. GLL combinators: https://github.com/djspiewak/gll-combinators

  14. Havelund, K.: Data automata in Scala. In: Leucker, M., Wang, J. (eds.) Proceedings of 8th International Symposium on Theoretical Aspects of Software Engineering (TASE 2014), Changsha, China. IEEE Computer Society Press (2014)

    Google Scholar 

  15. Havelund, K.: Monitoring with data automata. In: Margaria, T., Steffen, B. (eds.) ISoLA 2014, Part II. LNCS, vol. 8803, pp. 254–273. Springer, Heidelberg (2014)

    Google Scholar 

  16. Havelund, K.: Rule-based runtime verification revisited. Softw. Tools Technol. Transf. (STTT) 17(2), 143–170 (2015)

    Article  Google Scholar 

  17. Havelund, K., Joshi, R.: Experience with rule-based analysis of spacecraft logs. In: Artho, C., Ölveczky, P.C. (eds.) FTSCS 2014. CCIS, vol. 476, pp. 1–16. Springer, Heidelberg (2015)

    Google Scholar 

  18. Hoare, C.: Communicating sequential processes. Commun. ACM 26(1), 100–106 (1983)

    Article  Google Scholar 

  19. Jakob, F.: SugarScala: Syntactic extensibility for Scala. Master’s thesis, Technische Universität Darmstadt (2014)

    Google Scholar 

  20. Link, J., Fröhlich, P.: Unit Testing in Java: How Tests Drive the Code. Morgan Kaufmann Publishers Inc., Sebastopol (2003)

    Google Scholar 

  21. Mernik, M., Heering, J., Sloane, A.: When and how to develop domain-specific languages. ACM Comput. Surv. 37(4), 316–344 (2005)

    Article  Google Scholar 

  22. Odersky, M., Spoon, L., Venners, B.: Programming in Scala: A Comprehensive Step-by-step Guide, 2nd edn. Artima Inc., USA (2010)

    Google Scholar 

  23. Parboiled: https://github.com/sirthias/parboiled2

  24. Parser combinators: https://github.com/scala/scala-parser-combinators

  25. Rompf, T., Amin, N., Moors, A., Haller, P., Odersky, M.: Scala-virtualized: linguistic reuse for deep embeddings. High. Order Symbolic Comput. 25, 1–43 (2013)

    Google Scholar 

  26. Scala: http://www.scala-lang.org

  27. ScalaBison: https://github.com/djspiewak/scala-bison

  28. Scala macros: http://scalamacros.org

  29. Stolz, V., Huch, F.: Runtime verification of concurrent Haskell programs. In: Proceedings of the 4th International Workshop on Runtime Verification (RV 2004), ENTCS, vol. 113, pp. 201–216. Elsevier (2005)

    Google Scholar 

  30. Venners, B.: ScalaTest (2014). http://www.scalatest.org

Download references

Author information

Authors and Affiliations

Authors

Corresponding author

Correspondence to Cyrille Artho .

Editor information

Editors and Affiliations

Rights and permissions

Reprints and permissions

Copyright information

© 2015 Springer International Publishing Switzerland

About this paper

Cite this paper

Artho, C., Havelund, K., Kumar, R., Yamagata, Y. (2015). Domain-Specific Languages with Scala. In: Butler, M., Conchon, S., Zaïdi, F. (eds) Formal Methods and Software Engineering. ICFEM 2015. Lecture Notes in Computer Science(), vol 9407. Springer, Cham. https://doi.org/10.1007/978-3-319-25423-4_1

Download citation

  • DOI: https://doi.org/10.1007/978-3-319-25423-4_1

  • Published:

  • Publisher Name: Springer, Cham

  • Print ISBN: 978-3-319-25422-7

  • Online ISBN: 978-3-319-25423-4

  • eBook Packages: Computer ScienceComputer Science (R0)

Publish with us

Policies and ethics