/
Extensible Type-Driven Parsing for Extensible Type-Driven Parsing for

Extensible Type-Driven Parsing for - PowerPoint Presentation

yoshiko-marsland
yoshiko-marsland . @yoshiko-marsland
Follow
393 views
Uploaded On 2016-06-13

Extensible Type-Driven Parsing for - PPT Presentation

Embedded DSLs in Wyvern Cyrus Omar Benjamin Chung Darya Kurilova Ligia Nistor Alex Potanin Victoria University of Wellington Jonathan Aldrich ParsingSLE 13 School of Computer Science ID: 360766

syntax type code language type syntax language code types dsl wyvern active libraries html parser def completion grammar programming features specific forms

Share:

Link:

Embed:

Download Presentation from below link

Download Presentation The PPT/PDF document "Extensible Type-Driven Parsing for" is the property of its rightful owner. Permission is granted to download and print the materials on this web site for personal, non-commercial use only, and to display it on your personal computer provided you do not modify the materials and that you retain all copyright notices contained in the materials. By downloading content from our website, you accept the terms of this agreement.


Presentation Transcript

Slide1

Extensible Type-Driven Parsing for Embedded DSLs in Wyvern

Cyrus OmarBenjamin ChungDarya KurilovaLigia NistorAlex Potanin (Victoria University of Wellington)Jonathan Aldrich

[Parsing@SLE ‘13]

School of Computer Science

Carnegie Mellon UniversitySlide2

Wyvern2

Goals:

Secure web and mobile programming within a single statically-typed language.Compile-time support for a variety of domains:Security policies and architecture specificationsClient-side programming (HTML, CSS)Server-side programming (Databases)Slide3

3Monolithic languages where domain-specific features must be anticipated and built in are unsustainable.

Features

LanguageSlide4

4

Better approach: an

internally-extensible language where compile-time features can be distributed in libraries.

Features

Language

LibrarySlide5

Expressivity vs. Safety5

Want

expressive (syntax) extensions.But if you give each DSL too much control, they may interfere with one another at link-time.Slide6

Example: SugarJ6

Libraries can extend the

base syntax of the languageThese extensions are imported transitivelyExtensions can interfere:Pairs vs. TuplesHTML vs. XMLDifferent implementations of the same syntax[Erdweg et al, 2010]Slide7

Our Solution7

Libraries

cannot extend the base syntax of the languageInstead, syntax is associated with types.This type-specific syntax can be used to create values of that type.Slide8

Examples:

HTML

and URLs

8Slide9

Type-Specific Literals (TSLs)9

Several inline forms are available

`dsl syntax here, \`inner backticks\` must be escaped`'dsl syntax here, \'inner single quotes\'

must

be escaped'

{

dsl

syntax here, {inner braces} must be balanced}

[

dsl

syntax here, [inner brackets] must be balanced]

others?

If you use the tilde (~) with whitespace, there are no restrictions

on the code inside. Layout determines the end of the block.Slide10

Phase I: Top-Level Parsing10

The top-level layout-sensitive syntax of Wyvern can be parsed first without involving the

typecheckerUseful for tools like documentation generatorsWyvern’s grammar can be written down declaratively using a layout-sensitive formalism [Erdweg et al. 2012; Adams 2013]TSL code (and Wyvern expressions inside it) is left

unparsed

during this phaseSlide11

Phase II: Typechecking and DSL Parsing11

When a TSL is encountered during typechecking, its

expected type is determined via:Explicit annotationsMethod signaturesType propagation into where clausesThe TSL is now parsed according to the type-associated syntax.Any internal Wyvern expressions are also parsed (I & II) and typechecked recursively during this phase.Slide12

12

type

HTML = … def tagName :

string

attributes

=

new

def

parser : Parser =

new

def

parse(s : TokenStream) : AST = … code to parse HTML …

type

Parser =

def

parse

(s :

TokenStream

)

: AST

Associating a

Parser

with a typeSlide13

13

type

HTML = … def tagName : string … attributes = new def

parser : Parser =

~

start

::= (“<“ tag “>”

start

“</” tag “>”)*

|

“{“

EXP

: HTML “}”

tag

::= ...Associating a grammar with a typeSlide14

Benefits14

Modularity and

Safe ComposabilityDSLs are distributed in libraries, along with typesNo link-time errorsIdentifiabilityCan easily see when a DSL is being usedCan determine which DSL is being used by identifying expected typeDSLs always generate a value of the corresponding typeSimplicitySingle mechanism that can be described in a few sentences

Specify a grammar in a natural manner within the type

Flexibility

Whitespace-delimited blocks can contain

arbitrary

syntaxSlide15

Types Organize Languages15

Types represent an organizational unit for programming language semantics.

Types are not only useful for traditional verification, but also safely-composable language-internal (syntax) extensions.Slide16

Examples16Slide17

Ongoing Work17Slide18

Are all forms equivalent?18

That is, these three forms could be exactly equivalent, assuming

f takes a single argument of type URLf(~) http://github.com/wyvernlang/wyvernf(`http://github.com/

wyvernlang

/wyvern`)

f([http://

github.com

/

wyvernlang

/wyvern])

f(“http://

github.com

/

wyvernlang

/wyvern

)(String literals are simply a DSL associated with the String type!)Alternatively, types could restrict the valid forms of identifier to allow the language itself to enforce conventions.Slide19

Keyword-Directed Invocation19

Most language extension mechanisms invoke DSLs using functions or keywords (e.g. macros), rather than types.

The keyword-directed invocation strategy can be considered a special case of the type-directed strategy.The keyword is simply a function taking one argument.The argument type specifies a grammar that captures one or more expressions.Slide20

Example: Control Flow20

if :

bool -> (unit -> a), (unit -> a) -> aIfBranches

if

(

in_france

, ~)

do_as_the_french_do

()

else

panic()if(in_france

) do_as_the_french_do

() else panic()Slide21

Interaction with Subtyping21

With subtyping, multiple subtypes may define a grammar.

Possible Approaches:Use only the declared type of functionsExplicit annotation on the tildeParse against all possible grammars, disambiguate as neededOther mechanisms? Slide22

Interaction with Tools22

Syntax interacts with syntax highlighters + editor features.

Still need to figure out how to support type-specific syntax in these contexts.Borrow ideas from language workbenches?Slide23

Related Work23Slide24

Active Libraries [Veldhuizen, 1998]Active libraries are not passive collections of routines or objects, as are traditional libraries, but take an active role in generating code.

24Slide25

Active Code Completion [Omar et al, ICSE 2012]Use types similarly to control the IDE’s code completion system.

25Slide26

26

Active Code Completion

with GRAPHITESlide27

27

Active Code Completion

with GRAPHITESlide28

28

Active Code Completion

with GRAPHITESlide29

29

Active Code Completion

with GRAPHITESlide30

Active Typechecking & Translation[Omar and Aldrich, presented at DSLDI 2013]Use types to control typechecking and translation.

Implemented in the Ace programming language.30