@szarnekow - eclipsecon

16
@szarnekow Best Practices

Upload: others

Post on 12-Feb-2022

8 views

Category:

Documents


0 download

TRANSCRIPT

@szarnekow

Best Practices

Anatomy of a Language Implementation

• Grammar• Scoping• Validation• Execution• Editor

Sample Files

Unit Tests

Feedback

Antlr Annoyances

warning(200): Decision can match input such as "{EOF, RULE_ID, '('}" using multiple alternatives: 1, 2As a result, alternative(s) 2 were disabled for that input

function funnyError() { return 1 +}

mismatched input '}' expecting RULE_INT

Backtracking?

#1 - Grammar Tips

• Favor Syntactic Predicates over Backtracking

• Data Types Instead of Terminals• Use Keywords Wisely

Function:! {Max} 'max' .. |! {Min} 'min' .. |! {Avg} 'avg' ..;

FunctionCall:! function=[Function] ..;

/* Documentation */max: (int, int):int

Generalize It

#2 - Modularity

• Concise Grammars and Library Files• Design For Multiple Files

Local / Global Scoping

• Local Scoping - Model Navigation• Scopes are Computed By Traversing

the Model• Global Scoping - Index Queries

• Scope Content is Backed By Index Data

#3 - Scoping

• Use the Index• #getAllContents Is Not Your Friend• Loading Resources Does Not Hurt

#4 - Validation

• Loose Grammar, Loose Scoping,Strict Validation

• Specify the Location of Errors and Warnings

• Avoid Follow-Up Errors

#5 - User Interface

• Filtered Content ProposalsInstead of Strict Scoping

• Use Styled Strings To Prettify the UI

#6 - To Xbase Or Not To Xbase

• DSL Used in Java Environment?• Target Audience Developers?• Behavior and Logic?

Developers Want That!

#7 - Embrace Injection

• @Inject Is Key To Success• Avoid StandaloneSetup in Equinox• ProTip: ExecutableExtensionFactory• e4: Don’t Confuse @Inject With @Inject

!

Measure, Don’t Guess

All Time Classics

Tests, Tests, Tests

Read Code & Ask Questions

Thank You.