Writing a DSL for PowerShell (Domain Specific Languages)

Slides:



Advertisements
Similar presentations
JavaScript I. JavaScript is an object oriented programming language used to add interactivity to web pages. Different from Java, even though bears some.
Advertisements

Analysis of programs with pointers. Simple example What are the dependences in this program? Problem: just looking at variable names will not give you.
VBA Modules, Functions, Variables, and Constants
Working with JavaScript. 2 Objectives Introducing JavaScript Inserting JavaScript into a Web Page File Writing Output to the Web Page Working with Variables.
14 Copyright © 2004, Oracle. All rights reserved. Producing Triggers.
1 Chapter 4 Macro Processors Professor Gwan-Hwan Hwang Dept. Computer Science and Information Engineering National Taiwan Normal University 9/17/2009.
CSC 8310 Programming Languages Meeting 2 September 2/3, 2014.
Review IDIA 619 Spring 2013 Bridget M. Blodgett. HTML A basic HTML document looks like this: Sample page Sample page This is a simple sample. HTML user.
INTRODUCTION TO JAVASCRIPT AND DOM Internet Engineering Spring 2012.
XP Tutorial 10New Perspectives on Creating Web Pages with HTML, XHTML, and XML 1 Working with JavaScript Creating a Programmable Web Page for North Pole.
A Little Language for Surveys: Constructing an Internal DSL in Ruby H. Conrad Cunningham Computer and Information Science University of Mississippi.
CMPS 1371 Introduction to Computing for Engineers CONDITIONAL STATEMENTS.
COMP An Introduction to Computer Programming : University of the West Indies COMP6015 An Introduction to Computer Programming Lecture 05.
Variables and ConstantstMyn1 Variables and Constants PHP stands for: ”PHP: Hypertext Preprocessor”, and it is a server-side programming language. Special.
Chapter 15 Introduction to PL/SQL. Chapter Objectives  Explain the benefits of using PL/SQL blocks versus several SQL statements  Identify the sections.
CS346 Javascript -3 Module 3 JavaScript Variables.
XP Tutorial 10New Perspectives on HTML and XHTML, Comprehensive 1 Working with JavaScript Creating a Programmable Web Page for North Pole Novelties Tutorial.
MuSL Builder Handcrafting custom Mu Scenarios. MuSL in the Mu Scenario Editor.
XP Tutorial 8 Adding Interactivity with ActionScript.
BMTRY 789 Lecture 10: SAS MACRO Facility Annie N. Simpson, MSc.
Corey Hynes HynesITe, Inc Session Code: SRV317 Objectives Let you walk out of here, being able to run a script against an OU of computers, to make some.
 Programming - the process of creating computer programs.
XP New Perspectives on XML, 2 nd Edition Tutorial 7 1 TUTORIAL 7 CREATING A COMPUTATIONAL STYLESHEET.
Python Let’s get started!.
 It is Microsoft's new task-based command- line shell and scripting language designed especially for system administration.  It helps Information Technology.
PHP Reusing Code and Writing Functions 1. Function = a self-contained module of code that: Declares a calling interface – prototype! Performs some task.
Text TCS INTERNAL Oracle PL/SQL – Introduction. TCS INTERNAL PL SQL Introduction PLSQL means Procedural Language extension of SQL. PLSQL is a database.
JavaScript Introduction and Background. 2 Web languages Three formal languages HTML JavaScript CSS Three different tasks Document description Client-side.
Java Server Pages. 2 Servlets The purpose of a servlet is to create a Web page in response to a client request Servlets are written in Java, with a little.
Introduction to Programming the WWW I CMSC Winter 2003 Lecture 17.
CSE 311 Foundations of Computing I Lecture 19 Recursive Definitions: Context-Free Grammars and Languages Autumn 2012 CSE
XP Tutorial 10New Perspectives on HTML, XHTML, and DHTML, Comprehensive 1 Working with JavaScript Creating a Programmable Web Page for North Pole Novelties.
1 Chapter 4 Macro Processors. 2 Introduction A macro instruction (abbreviated to macro) is simply a notational convenience for the programmer. A macro.
Clojure Macros. Homoiconicity All versions of Lisp, including Clojure, are homoiconic This means that there is no difference between the form of the data.
Introduction to Python for System Administrators Toshio Kuratomi May 2011.
Introduction to JavaScript MIS 3502, Fall 2016 Jeremy Shafer Department of MIS Fox School of Business Temple University 9/29/2016.
Web Database Programming Using PHP
Product Training Program
OOP - Object Oriented Programming
Pseudocode Key Revision Points.
Basic 1960s It was designed to emphasize ease of use. Became widespread on microcomputers It is relatively simple. Will make it easier for people with.
Chapter 16 UML Class Diagrams.
Web Database Programming Using PHP
Designing a DSL in KOTLIN
C Language By Sra Sontisirikit
Arrays and files BIS1523 – Lecture 15.
Von Neumann model - Memory
Functions Declarations, Function Expressions and IIFEs
Methods The real power of an object-oriented programming language takes place when you start to manipulate objects. A method defines an action that allows.
Azure Automation and Logic Apps:
Introduction to JavaScript
Server Management and Automation Windows Server 2012 R2
UNO Static Analysis With a Simple Twist.
Chapter 10 Programming Fundamentals with JavaScript
A second look at JavaScript
User Defined Functions
Chapter 4 Functions Objectives
Von Neumann model - Memory
Visual Basic – Decision Statements
Selection Statements.
04 | Advanced Functions Jeffrey Snover | Distinguished Engineer & Lead Architect Jason Helmick | Senior Technologist, Concentrated Technology.
CSE 307 Basics of Image Processing
Islamic University of Gaza
Introduction to JavaScript
CS 240 – Advanced Programming Concepts
Conformiq Input on TDL 3 Discussion
PHP an introduction.
Groovy.
CIS 136 Building Mobile Apps
Functions, Part 1 of 2 Topics Using Predefined Functions
Presentation transcript:

Writing a DSL for PowerShell (Domain Specific Languages) Kevin Marquette https://github.com/KevinMarquette/DSLPresentation

About Kevin Marquette Sr. DevOps Engineer at loanDepot SoCal PowerShell user group Modules PSGraph PSGraphPlus Chronometer PSHonolulu kmarquette.github.io @KevinMarquette #DSL #PSHSummit @KevinMarquette

#DSL #PSHSummit @KevinMarquette What is a DSL? A general-purpose language (GPL) is broadly applicable across domains, and lacks specialized features for a particular domain. A domain-specific language (DSL) is a computer language specialized to a particular application domain. -Wikipedia #DSL #PSHSummit @KevinMarquette

PowerShell DSL Examples DSC Pester InvokeBuild psake PSGraph PlasterDSL Gherkin PSHTML #DSL #PSHSummit @KevinMarquette

#DSL #PSHSummit @KevinMarquette PowerShell DSL code samples #DSL #PSHSummit @KevinMarquette

Syntax breakdown of Pester as a DSL Function Parameter ScriptBlock

#DSL #PSHSummit @KevinMarquette Deeper Pester deconstruction #DSL #PSHSummit @KevinMarquette

#DSL #PSHSummit @KevinMarquette DSL Commands DSL commands are functions Don’t follow community cmdlet best practices Named according to the problem domain Use positional and unnamed parameters String parameters are not placed in quotes Abuse ScriptBlocks for nesting or child elements Can also use arrays or multiline strings Use hashtable for arbitrary properties Usually parried with an “Invoke” command Invoke-Pester Invoke-Build Show-PSGraph #DSL #PSHSummit @KevinMarquette

#DSL #PSHSummit @KevinMarquette Planning a DSL Make sure a DSL is what you need 1 Prototype syntax before you code it 2 Build to the target domain 3 Focus on user experience 4 #DSL #PSHSummit @KevinMarquette

#DSL #PSHSummit @KevinMarquette Building a RDCMan DSL #DSL #PSHSummit @KevinMarquette

#DSL #PSHSummit @KevinMarquette Design Patterns Value passthrough Simple template Nested template Hashtable passthrough Hashtable builder Object collector #DSL #PSHSummit @KevinMarquette

#DSL #PSHSummit @KevinMarquette Restricted DSL Data statement Data -SupportedCommand $command {…} $ScriptBlock.CheckRestrictedLanguage  # $null for unrestricted # [string[]]@() for full restrictions [string[]]$commands = @('State','ServerDetails','RDCServer') [string[]]$variables = $null [bool]$allowEnvVariables = $true $scriptBlock.CheckRestrictedLanguage($commands, $variables, $allowEnvVariables) #DSL #PSHSummit @KevinMarquette

Internal Only Commands Defined inside parent function Get-PSCallStack #DSL #PSHSummit @KevinMarquette

#DSL #PSHSummit @KevinMarquette DynamicKeyword The method used by DSC Supports scriptblock or hashtable Name is optional Limitations: Must be loaded before script is parsed Can’t use any other function parameters #DSL #PSHSummit @KevinMarquette

Kevin Marquette SoCal PowerShell user group Modules PSGraph PSGraphPlus Chronometer PSHonolulu kmarquette.github.io @KevinMarquette https://github.com/KevinMarquette/DSLPresentation