SlideShare a Scribd company logo
redefine.digital.design: Helping you deal with complexity in VHDL and Verilog.
Xtending our VHDL Xtext
formatter with the formatter2 API
ir. Titouan Vervack
EclipseCon France
2017-06-21
redefine.digital.design: Helping you deal with complexity in VHDL and Verilog.
Xtending our VHDL Xtext
formatter with the formatter2 API
ir. Titouan Vervack
EclipseCon France, Toulouse
2017-06-21
Ghent
2
What do we do?
VHDL & SV IDE
3
What do we do?
Advanced analysis and linting
4
What do we do?
Visualisation
5
What do we do?
Visualisation
6
What do we do?
Eat cake
7
What do we do?
And cookies...
8
What do we do?
And occasionally… formatting
9
What do we do?
And occasionally… formatting
9
Our formatter problems
10
Our formatter problems
● Big grammar
○ ~1.2k LoC
○ ~200 rules
10
Our formatter problems
● Big grammar
○ ~1.2k LoC
○ ~200 rules
● Hard to fix bugs
10
Our formatter problems
● Big grammar
○ ~1.2k LoC
○ ~200 rules
● Hard to fix bugs
● Near impossible to add new features
10
Formatter 1.0 vs Formatter 2.0
11
Formatter 1.0 Formatter 2.0
● No access to
○ Node model
○ AST
○ Text
● => Specify everything purely on the grammar
● => Lots of hacks
● Access to
○ Node model
○ AST
○ Grammar
● Can’t take context into account
○ Can’t adjust to the user
● Context aware formatting
○ Conditional formatting
○ Table formatting
● Not customizable ● Very customizable
Formatter 2.0 region example
variable _ foo _ : _ bit _ ; _-- barn
variable foo : bit; -- bar
= ISemanticRegion
= IHiddenRegion
_ -- bar n
= IHiddenRegionPart
12
https://de.slideshare.net/meysholdt/xtexts-new-formatter-api
Formatting 2.0 usage example
https://de.slideshare.net/meysholdt/xtexts-new-formatter-api
13
Formatting 2.0 usage example
https://de.slideshare.net/meysholdt/xtexts-new-formatter-api
class AwesomO4000 extends AbstractFormatter2 {
}
13
Formatting 2.0 usage example
https://de.slideshare.net/meysholdt/xtexts-new-formatter-api
class AwesomO4000 extends AbstractFormatter2 {
def dispatch void format(FunctionDecl fd, extension IFormattableDocument d) {
}
}
13
Formatting 2.0 usage example
https://de.slideshare.net/meysholdt/xtexts-new-formatter-api
class AwesomO4000 extends AbstractFormatter2 {
def dispatch void format(FunctionDecl fd, extension IFormattableDocument d) {
interior(fd.regionFor.keyword(“{”), fd.regionFor.keyword(“}”))[indent]
}
}
13
Formatting 2.0 usage example
https://de.slideshare.net/meysholdt/xtexts-new-formatter-api
class AwesomO4000 extends AbstractFormatter2 {
def dispatch void format(FunctionDecl fd, extension IFormattableDocument d) {
interior(fd.regionFor.keyword(“{”), fd.regionFor.keyword(“}”))[indent]
fd.declarations.forEach[format]
}
}
13
Formatting 2.0 usage example
https://de.slideshare.net/meysholdt/xtexts-new-formatter-api
class AwesomO4000 extends AbstractFormatter2 {
def dispatch void format(FunctionDecl fd, extension IFormattableDocument d) {
interior(fd.regionFor.keyword(“{”), fd.regionFor.keyword(“}”))[indent]
fd.declarations.forEach[format]
fd.regionFor.keyword(“;”)
}
}
13
Formatting 2.0 usage example
https://de.slideshare.net/meysholdt/xtexts-new-formatter-api
class AwesomO4000 extends AbstractFormatter2 {
def dispatch void format(FunctionDecl fd, extension IFormattableDocument d) {
interior(fd.regionFor.keyword(“{”), fd.regionFor.keyword(“}”))[indent]
fd.declarations.forEach[format]
fd.regionFor.keyword(“;”)
.prepend[noSpace highPriority]
}
}
13
Formatting 2.0 usage example
https://de.slideshare.net/meysholdt/xtexts-new-formatter-api
class AwesomO4000 extends AbstractFormatter2 {
def dispatch void format(FunctionDecl fd, extension IFormattableDocument d) {
interior(fd.regionFor.keyword(“{”), fd.regionFor.keyword(“}”))[indent]
fd.declarations.forEach[format]
fd.regionFor.keyword(“;”)
.prepend[noSpace highPriority]
.append[setNewlines(1, 1, 2)]
}
}
13
Time for a plan
14
Time for a plan
1. Make tests compatible
14
Time for a plan
1. Make tests compatible
2. Start out easy: only indentation
14
Time for a plan
1. Make tests compatible
2. Start out easy: only indentation
3. Fix tests one by one
14
Time for a plan
1. Make tests compatible
2. Start out easy: only indentation
3. Fix tests one by one
4. Fix old bugs
14
Time for a plan
1. Make tests compatible
2. Start out easy: only indentation
3. Fix tests one by one
4. Fix old bugs
5. Do not introduce new bugs
14
Time for a plan
1. Make tests compatible
2. Start out easy: only indentation
3. Fix tests one by one
4. Fix old bugs
5. Do not introduce new bugs
6. Feature parity & extend with new features
14
Time for a plan
1. Make tests compatible
2. Start out easy: only indentation
3. Fix tests one by one
4. Fix old bugs
5. Do not introduce new bugs
6. Feature parity & extend with new features
7. Performance tweaking to same or better level than old
14
Actual timeline
formatter.format(node, node.offset, node.length).formattedText
1. Make tests compatible
15
Actual timeline
formatter.format(node, node.offset, node.length).formattedText
1. Make tests compatible
15
Actual timeline
formatter.format(node, node.offset, node.length).formattedText
1. Make tests compatible
val request = new FormatterRequest()
val parsed = new XtextResource()
parsed.contents.add(parseResult.rootASTElement)
parsed.setParseResult(parseResult)
val access = builder.forNodeModel(resource).create()
request.setTextRegionAccess(access)
val replacements = formatter.format(request)
access.rewriter.renderToString(replacements)
15
interior(entity.regionFor.keyword(“is”), entity.regionFor.keyword(“end”))[indent]
Actual timeline
2. Start out easy: only indentation
16
interior(entity.regionFor.keyword(“is”), entity.regionFor.keyword(“end”))[indent]
Actual timeline
2. Start out easy: only indentation
● Indentation requires newline definitions
16
interior(entity.regionFor.keyword(“is”), entity.regionFor.keyword(“end”))[indent]
Actual timeline
2. Start out easy: only indentation
● Indentation requires newline definitions
● => replace all newlines with… the same amount of newlines
16
Actual timeline
3. Fix tests one by one
4. Fix old bugs
17
Actual timeline
3. Fix tests one by one
4. Fix old bugs
17
Actual timeline
5. Do not introduce new bugs
18
Actual timeline
5. Do not introduce new bugs
18
Actual timeline
6. Feature parity & extend formatter with new features
19
Actual timeline
6. Feature parity & extend formatter with new features
● Parity:
19
Actual timeline
6. Feature parity & extend formatter with new features
● Parity:
○ Keyword casing
19
Actual timeline
6. Feature parity & extend formatter with new features
● Parity:
○ Keyword casing
○ Comment alignment to columns
19
Actual timeline
6. Feature parity & extend formatter with new features
● Parity:
○ Keyword casing
○ Comment alignment to columns
○ Vertical alignment on keywords “:”, “:=”,...
19
Actual timeline
6. Feature parity & extend formatter with new features
● Parity:
○ Keyword casing
○ Comment alignment to columns
○ Vertical alignment on keywords “:”, “:=”,...
○ Preserve newline
19
Actual timeline
6. Feature parity & extend formatter with new features
● Parity:
○ Keyword casing
○ Comment alignment to columns
○ Vertical alignment on keywords “:”, “:=”,...
○ Preserve newline
● New features:
19
Actual timeline
6. Feature parity & extend formatter with new features
● Parity:
○ Keyword casing
○ Comment alignment to columns
○ Vertical alignment on keywords “:”, “:=”,...
○ Preserve newline
● New features:
○ Correct indentation
19
Actual timeline
6. Feature parity & extend formatter with new features
● Parity:
○ Keyword casing
○ Comment alignment to columns
○ Vertical alignment on keywords “:”, “:=”,...
○ Preserve newline
● New features:
○ Correct indentation
○ Formatter tags
19
Actual timeline
6. Feature parity & extend formatter with new features
● Parity:
○ Keyword casing
○ Comment alignment to columns
○ Vertical alignment on keywords “:”, “:=”,...
○ Preserve newline
● New features:
○ Correct indentation
○ Formatter tags
Easy once we have alignment
19
Alignment?
20
Alignment?
20
Alignment?
● Replacements are added in random order, applied in correct order
21
Alignment?
● Replacements are added in random order, applied in correct order
● Alignment needs to be done on post-formatted input
21
Alignment?
● Replacements are added in random order, applied in correct order
● Alignment needs to be done on post-formatted input
● How do I know which region to format?
21
Alignment!
22
Alignment!
22
Alignment!
22
Alignment!
22
Alignment!
start end
22
Alignment!
start end
22
Alignment!
Find smallest encapsulating object that
formats region between start and end
start end
22
Alignment!
Find smallest encapsulating object that
formats region between start and end
start end
22
Alignment!
clk : in std_logic := ‘X’;
23
Alignment!
clk : in std_logic := ‘X’;
start end
23
PortDeclaration
Alignment!
clk : in std_logic := ‘X’;
start end
name direction type value
end.getSemanticElement()
PortDeclaration
PortList
23
PortDeclaration
Alignment!
clk : in std_logic := ‘X’;
start end
name direction type value
offset x
x + 4
end.getSemanticElement()
PortDeclaration
PortList
23
val rule = portDecl.getParserRule()
val oldAccess = createTextRegionAccess(rule, portDecl.text)
val formatted = portDecl.format()
Alignment!
Format smallest encapsulating object
24
val rule = portDecl.getParserRule()
val oldAccess = createTextRegionAccess(rule, portDecl.text)
val formatted = portDecl.format()
Alignment!
val newAccess = createTextRegionAccess(rule, formatted.text)
val oldIndices = oldAccess.getIndices(start, end)
val length = newAccess.countBetween(oldIndices)
Format smallest encapsulating object
Map unformatted string to formatted string
24
Align on first parameter?
→return (
→→foo((5,
→→·····6),
→→····3));
25
Align on first parameter?
→return (
→→foo((5,
→→·····6),
→→····3));
25
Align on first parameter?
→return (
→→foo((5,
→→·····6),
→→····3));
→return (5,
→········foo((5,
→·············6),
→············3));
25
Align on first parameter?
→return (
→→foo((5,
→→·····6),
→→····3));
→return (5,
→········foo((5,
→·············6),
→············3));
25
Align on first parameter?
→return (
→→foo((5,
→→·····6),
→→····3));
→return (5,
→········foo((5,
→·············6),
→············3));
→return foo((5,
→············6),
→···········3));
25
Align on first parameter?
→return (
→→foo((5,
→→·····6),
→→····3));
→return (5,
→········foo((5,
→·············6),
→············3));
→return foo((5,
→············6),
→···········3));
25
Align on first parameter?
→return (
→→foo((5,
→→·····6),
→→····3));
→return (5,
→········foo((5,
→·············6),
→············3));
→return foo((5,
→············6),
→···········3));
→return foo(
→→(5,
→→·6),
→→3));
25
Align on first parameter?
→return (
→→foo((5,
→→·····6),
→→····3));
→return (5,
→········foo((5,
→·············6),
→············3));
→return foo((5,
→············6),
→···········3));
→return foo(
→→(5,
→→·6),
→→3));
25
Align on first parameter?
→return (
→→foo((5,
→→·····6),
→→····3));
→return (5,
→········foo((5,
→·············6),
→············3));
→return foo((5,
→············6),
→···········3));
→return foo(
→→(5,
→→·6),
→→3));
Find largest encapsulating element on same line
25
Actual timeline
6. Feature parity & extend formatter with new features
Correct indentation
26
Actual timeline
6. Feature parity & extend formatter with new features
Correct indentation
val replacements = formatter.format(request)
26
Actual timeline
6. Feature parity & extend formatter with new features
Correct indentation
val replacements = formatter.format(request)
replacements
.filter[ r|
]
26
Actual timeline
6. Feature parity & extend formatter with new features
Correct indentation
val replacements = formatter.format(request)
replacements
.filter[ r|
r.lineCount > 1
]
26
Actual timeline
6. Feature parity & extend formatter with new features
Correct indentation
val replacements = formatter.format(request)
replacements
.filter[ r|
r.lineCount > 1 &&
r.replacementText.newlines + 1 == r.lineCount
]
26
Actual timeline
6. Feature parity & extend formatter with new features
Formatter tags
27
Actual timeline
6. Feature parity & extend formatter with new features
Formatter tags
-- @formatter:off Turns formatter off
-- @formatter:on Turns formatter on
27
Actual timeline
6. Feature parity & extend formatter with new features
Formatter tags
-- @formatter:off Turns formatter off
-- @formatter:on Turns formatter on
val originalRegions = request.getRegions() ?: document.region
27
Actual timeline
6. Feature parity & extend formatter with new features
Formatter tags
-- @formatter:off Turns formatter off
-- @formatter:on Turns formatter on
val originalRegions = request.getRegions() ?: document.region
val betweenRegions = document.findRegionsBetween(off, on)
27
Actual timeline
6. Feature parity & extend formatter with new features
Formatter tags
-- @formatter:off Turns formatter off
-- @formatter:on Turns formatter on
val originalRegions = request.getRegions() ?: document.region
val betweenRegions = document.findRegionsBetween(off, on)
.addAll(document.findRegionsBetween(off, EOF))
27
Actual timeline
6. Feature parity & extend formatter with new features
Formatter tags
-- @formatter:off Turns formatter off
-- @formatter:on Turns formatter on
val originalRegions = request.getRegions() ?: document.region
val betweenRegions = document.findRegionsBetween(off, on)
.addAll(document.findRegionsBetween(off, EOF))
val newRegions = originalRegions.removeRegions(betweenRegions)
27
Actual timeline
6. Feature parity & extend formatter with new features
Formatter tags
-- @formatter:off Turns formatter off
-- @formatter:on Turns formatter on
val originalRegions = request.getRegions() ?: document.region
val betweenRegions = document.findRegionsBetween(off, on)
.addAll(document.findRegionsBetween(off, EOF))
val newRegions = originalRegions.removeRegions(betweenRegions)
request.setRegions(newRegions)
27
Performance
7. Performance tweaking to same or better level than old
28
Performance
7. Performance tweaking to same or better level than old
● Cache ITextRegionAccess in subformats
28
Performance
7. Performance tweaking to same or better level than old
● Cache ITextRegionAccess in subformats
● Cache IParser.createAllRules(Grammar)
28
Performance
7. Performance tweaking to same or better level than old
● Cache ITextRegionAccess in subformats
● Cache IParser.createAllRules(Grammar)
● Merge all replacements into one big replacement
28
Performance
7. Performance tweaking to same or better level than old
emacs/xtend > 25m
29
Performance
7. Performance tweaking to same or better level than old
emacs/xtend > 25m
30
Biggest problems in hindsight
31
Biggest problems in hindsight
● Tests pass, close enough?
31
Biggest problems in hindsight
● Tests pass, close enough?
○ Nope, old testset isn’t nearly enough
31
Biggest problems in hindsight
● Tests pass, close enough?
○ Nope, old testset isn’t nearly enough
● Comments are an enormous pain: eat newlines, add spaces, eat
spaces, fake empty lines
31
Biggest problems in hindsight
● Tests pass, close enough?
○ Nope, old testset isn’t nearly enough
● Comments are an enormous pain: eat newlines, add spaces, eat
spaces, fake empty lines
● Alignment interactions with normal and first param alignments and
comments
31
Biggest problems in hindsight
● Tests pass, close enough?
○ Nope, old testset isn’t nearly enough
● Comments are an enormous pain: eat newlines, add spaces, eat
spaces, fake empty lines
● Alignment interactions with normal and first param alignments and
comments
31
Biggest problems in hindsight
● Tests pass, close enough?
○ Nope, old testset isn’t nearly enough
● Comments are an enormous pain: eat newlines, add spaces, eat
spaces, fake empty lines
● Alignment interactions with normal and first param alignments and
comments
31
Biggest problems in hindsight
● Tests pass, close enough?
○ Nope, old testset isn’t nearly enough
● Comments are an enormous pain: eat newlines, add spaces, eat
spaces, fake empty lines
● Alignment interactions with normal and first param alignments and
comments
31
Biggest problems in hindsight
● Tests pass, close enough?
○ Nope, old testset isn’t nearly enough
● Comments are an enormous pain: eat newlines, add spaces, eat
spaces, fake empty lines
● Alignment interactions with normal and first param alignments and
comments
3031
Biggest problems in hindsight
● Tests pass, close enough?
○ Nope, old testset isn’t nearly enough
● Comments are an enormous pain: eat newlines, add spaces, eat
spaces, fake empty lines
● Alignment interactions with normal and first param alignments and
comments
3031
Biggest problems in hindsight
● Tests pass, close enough?
○ Nope, old testset isn’t nearly enough
● Comments are an enormous pain: eat newlines, add spaces, eat
spaces, fake empty lines
● Alignment interactions with normal and first param alignments and
comments
3031
Warning to Xtext users
Default ExceptionHandler logs DSL source code to stderr
32
Sigasi future work
33
Sigasi future work
● Smooth out remaining bugs
33
Sigasi future work
● Smooth out remaining bugs
● Some more context awareness
33
Sigasi future work
● Smooth out remaining bugs
● Some more context awareness
● Autowrap
33
Sigasi future work
● Smooth out remaining bugs
● Some more context awareness
● Autowrap
● Performance
33
Sigasi future work
● Smooth out remaining bugs
● Some more context awareness
● Autowrap
● Performance
● Upstream features
33
Sigasi future work
● Smooth out remaining bugs
● Some more context awareness
● Autowrap
● Performance
● Upstream features
○ Formatter tags
33
Sigasi future work
● Smooth out remaining bugs
● Some more context awareness
● Autowrap
● Performance
● Upstream features
○ Formatter tags
○ Correct indentation
33
Sigasi future work
● Smooth out remaining bugs
● Some more context awareness
● Autowrap
● Performance
● Upstream features
○ Formatter tags
○ Correct indentation
○ Performance optimizations
33
Xtext wish list
34
Xtext wish list
● Accept my PRs (tags, correct indent, performance)
34
Xtext wish list
● Accept my PRs (tags, correct indent, performance)
● Fix/discuss my issues
34
Xtext wish list
● Accept my PRs (tags, correct indent, performance)
● Fix/discuss my issues
● Fix Xtend formatter issues
34
Xtext wish list
● Accept my PRs (tags, correct indent, performance)
● Fix/discuss my issues
● Fix Xtend formatter issues
● Very slow Xtend formatter source file
34
Xtext wish list
● Accept my PRs (tags, correct indent, performance)
● Fix/discuss my issues
● Fix Xtend formatter issues
● Very slow Xtend formatter source file
● Add pre- and post format hooks in format(FormatterRequest)
34
Conclusion
35
Conclusion
● Context aware
35
Conclusion
● Context aware
● Debugable
35
Conclusion
● Context aware
● Debugable
● Good performance
35
Conclusion
● Context aware
● Debugable
● Good performance
● Very customizable
35
Conclusion
● Context aware
● Debugable
● Good performance
● Very customizable
● User friendly
35
Conclusion
● Context aware
● Debugable
● Good performance
● Very customizable
● User friendly
○ Done in 2 months (base in 2 weeks) while first task and not used to Xtend
35
Conclusion
● Context aware
● Debugable
● Good performance
● Very customizable
● User friendly
○ Done in 2 months (base in 2 weeks) while first task and not used to Xtend
● Happy with the switch
35
Conclusion
● Context aware
● Debugable
● Good performance
● Very customizable
● User friendly
○ Done in 2 months (base in 2 weeks) while first task and not used to Xtend
● Happy with the switch
○ New features
35
Conclusion
● Context aware
● Debugable
● Good performance
● Very customizable
● User friendly
○ Done in 2 months (base in 2 weeks) while first task and not used to Xtend
● Happy with the switch
○ New features
○ Very readable
35
Conclusion
● Context aware
● Debugable
● Good performance
● Very customizable
● User friendly
○ Done in 2 months (base in 2 weeks) while first task and not used to Xtend
● Happy with the switch
○ New features
○ Very readable
○ Conditional formatting
35
Evaluate the Sessions
-1 0 +1
Sign in and vote at eclipsecon.org

More Related Content

What's hot

PHP to Hack at Slack
PHP to Hack at SlackPHP to Hack at Slack
PHP to Hack at Slack
Scott Sandler
 
Fscons scalable appplication transfers
Fscons scalable appplication transfersFscons scalable appplication transfers
Fscons scalable appplication transfers
Daniel Stenberg
 
Run Go applications on Pico using TinyGo
Run Go applications on Pico using TinyGo Run Go applications on Pico using TinyGo
Run Go applications on Pico using TinyGo
Yu-Shuan Hsieh
 
PSR7 - interoperabilità HTTP
PSR7 - interoperabilità HTTPPSR7 - interoperabilità HTTP
PSR7 - interoperabilità HTTP
Massimiliano Arione
 
Scala for Everything: From Frontend to Backend Applications - Scala Matsuri 2020
Scala for Everything: From Frontend to Backend Applications - Scala Matsuri 2020Scala for Everything: From Frontend to Backend Applications - Scala Matsuri 2020
Scala for Everything: From Frontend to Backend Applications - Scala Matsuri 2020
Taro L. Saito
 
Stream Processing in the Cloud - Athens Kubernetes Meetup 16.07.2019
Stream Processing in the Cloud - Athens Kubernetes Meetup 16.07.2019Stream Processing in the Cloud - Athens Kubernetes Meetup 16.07.2019
Stream Processing in the Cloud - Athens Kubernetes Meetup 16.07.2019
Rafał Leszko
 
A Case for Relativistic Programming
A Case for Relativistic ProgrammingA Case for Relativistic Programming
A Case for Relativistic Programming
racesworkshop
 
24 uses for perl6
24 uses for perl624 uses for perl6
24 uses for perl6
Simon Proctor
 
Kostiantyn Grygoriev "Wrapping C++ for Python"
Kostiantyn Grygoriev "Wrapping C++ for Python"Kostiantyn Grygoriev "Wrapping C++ for Python"
Kostiantyn Grygoriev "Wrapping C++ for Python"
LogeekNightUkraine
 
PHP & MySQL: PDO x MySQLi
PHP & MySQL: PDO x MySQLiPHP & MySQL: PDO x MySQLi
PHP & MySQL: PDO x MySQLi
Marcos Marcolin
 

What's hot (10)

PHP to Hack at Slack
PHP to Hack at SlackPHP to Hack at Slack
PHP to Hack at Slack
 
Fscons scalable appplication transfers
Fscons scalable appplication transfersFscons scalable appplication transfers
Fscons scalable appplication transfers
 
Run Go applications on Pico using TinyGo
Run Go applications on Pico using TinyGo Run Go applications on Pico using TinyGo
Run Go applications on Pico using TinyGo
 
PSR7 - interoperabilità HTTP
PSR7 - interoperabilità HTTPPSR7 - interoperabilità HTTP
PSR7 - interoperabilità HTTP
 
Scala for Everything: From Frontend to Backend Applications - Scala Matsuri 2020
Scala for Everything: From Frontend to Backend Applications - Scala Matsuri 2020Scala for Everything: From Frontend to Backend Applications - Scala Matsuri 2020
Scala for Everything: From Frontend to Backend Applications - Scala Matsuri 2020
 
Stream Processing in the Cloud - Athens Kubernetes Meetup 16.07.2019
Stream Processing in the Cloud - Athens Kubernetes Meetup 16.07.2019Stream Processing in the Cloud - Athens Kubernetes Meetup 16.07.2019
Stream Processing in the Cloud - Athens Kubernetes Meetup 16.07.2019
 
A Case for Relativistic Programming
A Case for Relativistic ProgrammingA Case for Relativistic Programming
A Case for Relativistic Programming
 
24 uses for perl6
24 uses for perl624 uses for perl6
24 uses for perl6
 
Kostiantyn Grygoriev "Wrapping C++ for Python"
Kostiantyn Grygoriev "Wrapping C++ for Python"Kostiantyn Grygoriev "Wrapping C++ for Python"
Kostiantyn Grygoriev "Wrapping C++ for Python"
 
PHP & MySQL: PDO x MySQLi
PHP & MySQL: PDO x MySQLiPHP & MySQL: PDO x MySQLi
PHP & MySQL: PDO x MySQLi
 

Similar to EclipseCon France 2017 - Xtending Our Vhdl Xtext Formatter With The Formatter2 API

The Ring programming language version 1.9 book - Part 9 of 210
The Ring programming language version 1.9 book - Part 9 of 210The Ring programming language version 1.9 book - Part 9 of 210
The Ring programming language version 1.9 book - Part 9 of 210
Mahmoud Samir Fayed
 
Building DSLs with the Spoofax Language Workbench
Building DSLs with the Spoofax Language WorkbenchBuilding DSLs with the Spoofax Language Workbench
Building DSLs with the Spoofax Language Workbench
Eelco Visser
 
Introduction to Griffon
Introduction to GriffonIntroduction to Griffon
Introduction to Griffon
James Williams
 
Writing DSL with Applicative Functors
Writing DSL with Applicative FunctorsWriting DSL with Applicative Functors
Writing DSL with Applicative Functors
David Galichet
 
PDF made easy with iText 7
PDF made easy with iText 7PDF made easy with iText 7
PDF made easy with iText 7
iText Group nv
 
Lightweight Xtext Editors as SWT Widgets
Lightweight Xtext Editors as SWT WidgetsLightweight Xtext Editors as SWT Widgets
Lightweight Xtext Editors as SWT Widgets
meysholdt
 
New Indexing and Aggregation Pipeline Capabilities in MongoDB 4.2
New Indexing and Aggregation Pipeline Capabilities in MongoDB 4.2New Indexing and Aggregation Pipeline Capabilities in MongoDB 4.2
New Indexing and Aggregation Pipeline Capabilities in MongoDB 4.2
Antonios Giannopoulos
 
What’s new in .NET
What’s new in .NETWhat’s new in .NET
What’s new in .NET
Doommaker
 
Qt for beginners part 2 widgets
Qt for beginners part 2   widgetsQt for beginners part 2   widgets
Qt for beginners part 2 widgets
ICS
 
Visual Studio 2010 and .NET 4.0 Overview
Visual Studio 2010 and .NET 4.0 OverviewVisual Studio 2010 and .NET 4.0 Overview
Visual Studio 2010 and .NET 4.0 Overviewbwullems
 
Nested subqueries and subquery chaining in openCypher
Nested subqueries and subquery chaining in openCypherNested subqueries and subquery chaining in openCypher
Nested subqueries and subquery chaining in openCypher
openCypher
 
Metaprogramming, Metaobject Protocols, Gradual Type Checks: Optimizing the "U...
Metaprogramming, Metaobject Protocols, Gradual Type Checks: Optimizing the "U...Metaprogramming, Metaobject Protocols, Gradual Type Checks: Optimizing the "U...
Metaprogramming, Metaobject Protocols, Gradual Type Checks: Optimizing the "U...
Stefan Marr
 
compose_speaker_session.pdf
compose_speaker_session.pdfcompose_speaker_session.pdf
compose_speaker_session.pdf
AnkurAgarwal151093
 
New Features of SQL Server 2016
New Features of SQL Server 2016New Features of SQL Server 2016
New Features of SQL Server 2016Mir Mahmood
 
Functions in c++
Functions in c++Functions in c++
Functions in c++
Abdullah Turkistani
 
Advance Map reduce - Apache hadoop Bigdata training by Design Pathshala
Advance Map reduce - Apache hadoop Bigdata training by Design PathshalaAdvance Map reduce - Apache hadoop Bigdata training by Design Pathshala
Advance Map reduce - Apache hadoop Bigdata training by Design Pathshala
Desing Pathshala
 
The Ring programming language version 1.8 book - Part 14 of 202
The Ring programming language version 1.8 book - Part 14 of 202The Ring programming language version 1.8 book - Part 14 of 202
The Ring programming language version 1.8 book - Part 14 of 202
Mahmoud Samir Fayed
 
Effective CMake
Effective CMakeEffective CMake
Effective CMake
Daniel Pfeifer
 
The Ring programming language version 1.9 book - Part 16 of 210
The Ring programming language version 1.9 book - Part 16 of 210The Ring programming language version 1.9 book - Part 16 of 210
The Ring programming language version 1.9 book - Part 16 of 210
Mahmoud Samir Fayed
 
The Ring programming language version 1.9 book - Part 17 of 210
The Ring programming language version 1.9 book - Part 17 of 210The Ring programming language version 1.9 book - Part 17 of 210
The Ring programming language version 1.9 book - Part 17 of 210
Mahmoud Samir Fayed
 

Similar to EclipseCon France 2017 - Xtending Our Vhdl Xtext Formatter With The Formatter2 API (20)

The Ring programming language version 1.9 book - Part 9 of 210
The Ring programming language version 1.9 book - Part 9 of 210The Ring programming language version 1.9 book - Part 9 of 210
The Ring programming language version 1.9 book - Part 9 of 210
 
Building DSLs with the Spoofax Language Workbench
Building DSLs with the Spoofax Language WorkbenchBuilding DSLs with the Spoofax Language Workbench
Building DSLs with the Spoofax Language Workbench
 
Introduction to Griffon
Introduction to GriffonIntroduction to Griffon
Introduction to Griffon
 
Writing DSL with Applicative Functors
Writing DSL with Applicative FunctorsWriting DSL with Applicative Functors
Writing DSL with Applicative Functors
 
PDF made easy with iText 7
PDF made easy with iText 7PDF made easy with iText 7
PDF made easy with iText 7
 
Lightweight Xtext Editors as SWT Widgets
Lightweight Xtext Editors as SWT WidgetsLightweight Xtext Editors as SWT Widgets
Lightweight Xtext Editors as SWT Widgets
 
New Indexing and Aggregation Pipeline Capabilities in MongoDB 4.2
New Indexing and Aggregation Pipeline Capabilities in MongoDB 4.2New Indexing and Aggregation Pipeline Capabilities in MongoDB 4.2
New Indexing and Aggregation Pipeline Capabilities in MongoDB 4.2
 
What’s new in .NET
What’s new in .NETWhat’s new in .NET
What’s new in .NET
 
Qt for beginners part 2 widgets
Qt for beginners part 2   widgetsQt for beginners part 2   widgets
Qt for beginners part 2 widgets
 
Visual Studio 2010 and .NET 4.0 Overview
Visual Studio 2010 and .NET 4.0 OverviewVisual Studio 2010 and .NET 4.0 Overview
Visual Studio 2010 and .NET 4.0 Overview
 
Nested subqueries and subquery chaining in openCypher
Nested subqueries and subquery chaining in openCypherNested subqueries and subquery chaining in openCypher
Nested subqueries and subquery chaining in openCypher
 
Metaprogramming, Metaobject Protocols, Gradual Type Checks: Optimizing the "U...
Metaprogramming, Metaobject Protocols, Gradual Type Checks: Optimizing the "U...Metaprogramming, Metaobject Protocols, Gradual Type Checks: Optimizing the "U...
Metaprogramming, Metaobject Protocols, Gradual Type Checks: Optimizing the "U...
 
compose_speaker_session.pdf
compose_speaker_session.pdfcompose_speaker_session.pdf
compose_speaker_session.pdf
 
New Features of SQL Server 2016
New Features of SQL Server 2016New Features of SQL Server 2016
New Features of SQL Server 2016
 
Functions in c++
Functions in c++Functions in c++
Functions in c++
 
Advance Map reduce - Apache hadoop Bigdata training by Design Pathshala
Advance Map reduce - Apache hadoop Bigdata training by Design PathshalaAdvance Map reduce - Apache hadoop Bigdata training by Design Pathshala
Advance Map reduce - Apache hadoop Bigdata training by Design Pathshala
 
The Ring programming language version 1.8 book - Part 14 of 202
The Ring programming language version 1.8 book - Part 14 of 202The Ring programming language version 1.8 book - Part 14 of 202
The Ring programming language version 1.8 book - Part 14 of 202
 
Effective CMake
Effective CMakeEffective CMake
Effective CMake
 
The Ring programming language version 1.9 book - Part 16 of 210
The Ring programming language version 1.9 book - Part 16 of 210The Ring programming language version 1.9 book - Part 16 of 210
The Ring programming language version 1.9 book - Part 16 of 210
 
The Ring programming language version 1.9 book - Part 17 of 210
The Ring programming language version 1.9 book - Part 17 of 210The Ring programming language version 1.9 book - Part 17 of 210
The Ring programming language version 1.9 book - Part 17 of 210
 

Recently uploaded

Explore Modern SharePoint Templates for 2024
Explore Modern SharePoint Templates for 2024Explore Modern SharePoint Templates for 2024
Explore Modern SharePoint Templates for 2024
Sharepoint Designs
 
Dominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdf
Dominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdfDominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdf
Dominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdf
AMB-Review
 
Into the Box 2024 - Keynote Day 2 Slides.pdf
Into the Box 2024 - Keynote Day 2 Slides.pdfInto the Box 2024 - Keynote Day 2 Slides.pdf
Into the Box 2024 - Keynote Day 2 Slides.pdf
Ortus Solutions, Corp
 
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...
Juraj Vysvader
 
How Does XfilesPro Ensure Security While Sharing Documents in Salesforce?
How Does XfilesPro Ensure Security While Sharing Documents in Salesforce?How Does XfilesPro Ensure Security While Sharing Documents in Salesforce?
How Does XfilesPro Ensure Security While Sharing Documents in Salesforce?
XfilesPro
 
Quarkus Hidden and Forbidden Extensions
Quarkus Hidden and Forbidden ExtensionsQuarkus Hidden and Forbidden Extensions
Quarkus Hidden and Forbidden Extensions
Max Andersen
 
Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...
Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...
Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...
informapgpstrackings
 
OpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoam
OpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoamOpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoam
OpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoam
takuyayamamoto1800
 
Developing Distributed High-performance Computing Capabilities of an Open Sci...
Developing Distributed High-performance Computing Capabilities of an Open Sci...Developing Distributed High-performance Computing Capabilities of an Open Sci...
Developing Distributed High-performance Computing Capabilities of an Open Sci...
Globus
 
Prosigns: Transforming Business with Tailored Technology Solutions
Prosigns: Transforming Business with Tailored Technology SolutionsProsigns: Transforming Business with Tailored Technology Solutions
Prosigns: Transforming Business with Tailored Technology Solutions
Prosigns
 
Visitor Management System in India- Vizman.app
Visitor Management System in India- Vizman.appVisitor Management System in India- Vizman.app
Visitor Management System in India- Vizman.app
NaapbooksPrivateLimi
 
Understanding Globus Data Transfers with NetSage
Understanding Globus Data Transfers with NetSageUnderstanding Globus Data Transfers with NetSage
Understanding Globus Data Transfers with NetSage
Globus
 
top nidhi software solution freedownload
top nidhi software solution freedownloadtop nidhi software solution freedownload
top nidhi software solution freedownload
vrstrong314
 
De mooiste recreatieve routes ontdekken met RouteYou en FME
De mooiste recreatieve routes ontdekken met RouteYou en FMEDe mooiste recreatieve routes ontdekken met RouteYou en FME
De mooiste recreatieve routes ontdekken met RouteYou en FME
Jelle | Nordend
 
Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...
Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...
Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...
Globus
 
Vitthal Shirke Microservices Resume Montevideo
Vitthal Shirke Microservices Resume MontevideoVitthal Shirke Microservices Resume Montevideo
Vitthal Shirke Microservices Resume Montevideo
Vitthal Shirke
 
Cracking the code review at SpringIO 2024
Cracking the code review at SpringIO 2024Cracking the code review at SpringIO 2024
Cracking the code review at SpringIO 2024
Paco van Beckhoven
 
Strategies for Successful Data Migration Tools.pptx
Strategies for Successful Data Migration Tools.pptxStrategies for Successful Data Migration Tools.pptx
Strategies for Successful Data Migration Tools.pptx
varshanayak241
 
Multiple Your Crypto Portfolio with the Innovative Features of Advanced Crypt...
Multiple Your Crypto Portfolio with the Innovative Features of Advanced Crypt...Multiple Your Crypto Portfolio with the Innovative Features of Advanced Crypt...
Multiple Your Crypto Portfolio with the Innovative Features of Advanced Crypt...
Hivelance Technology
 
Enhancing Research Orchestration Capabilities at ORNL.pdf
Enhancing Research Orchestration Capabilities at ORNL.pdfEnhancing Research Orchestration Capabilities at ORNL.pdf
Enhancing Research Orchestration Capabilities at ORNL.pdf
Globus
 

Recently uploaded (20)

Explore Modern SharePoint Templates for 2024
Explore Modern SharePoint Templates for 2024Explore Modern SharePoint Templates for 2024
Explore Modern SharePoint Templates for 2024
 
Dominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdf
Dominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdfDominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdf
Dominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdf
 
Into the Box 2024 - Keynote Day 2 Slides.pdf
Into the Box 2024 - Keynote Day 2 Slides.pdfInto the Box 2024 - Keynote Day 2 Slides.pdf
Into the Box 2024 - Keynote Day 2 Slides.pdf
 
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...
 
How Does XfilesPro Ensure Security While Sharing Documents in Salesforce?
How Does XfilesPro Ensure Security While Sharing Documents in Salesforce?How Does XfilesPro Ensure Security While Sharing Documents in Salesforce?
How Does XfilesPro Ensure Security While Sharing Documents in Salesforce?
 
Quarkus Hidden and Forbidden Extensions
Quarkus Hidden and Forbidden ExtensionsQuarkus Hidden and Forbidden Extensions
Quarkus Hidden and Forbidden Extensions
 
Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...
Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...
Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...
 
OpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoam
OpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoamOpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoam
OpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoam
 
Developing Distributed High-performance Computing Capabilities of an Open Sci...
Developing Distributed High-performance Computing Capabilities of an Open Sci...Developing Distributed High-performance Computing Capabilities of an Open Sci...
Developing Distributed High-performance Computing Capabilities of an Open Sci...
 
Prosigns: Transforming Business with Tailored Technology Solutions
Prosigns: Transforming Business with Tailored Technology SolutionsProsigns: Transforming Business with Tailored Technology Solutions
Prosigns: Transforming Business with Tailored Technology Solutions
 
Visitor Management System in India- Vizman.app
Visitor Management System in India- Vizman.appVisitor Management System in India- Vizman.app
Visitor Management System in India- Vizman.app
 
Understanding Globus Data Transfers with NetSage
Understanding Globus Data Transfers with NetSageUnderstanding Globus Data Transfers with NetSage
Understanding Globus Data Transfers with NetSage
 
top nidhi software solution freedownload
top nidhi software solution freedownloadtop nidhi software solution freedownload
top nidhi software solution freedownload
 
De mooiste recreatieve routes ontdekken met RouteYou en FME
De mooiste recreatieve routes ontdekken met RouteYou en FMEDe mooiste recreatieve routes ontdekken met RouteYou en FME
De mooiste recreatieve routes ontdekken met RouteYou en FME
 
Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...
Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...
Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...
 
Vitthal Shirke Microservices Resume Montevideo
Vitthal Shirke Microservices Resume MontevideoVitthal Shirke Microservices Resume Montevideo
Vitthal Shirke Microservices Resume Montevideo
 
Cracking the code review at SpringIO 2024
Cracking the code review at SpringIO 2024Cracking the code review at SpringIO 2024
Cracking the code review at SpringIO 2024
 
Strategies for Successful Data Migration Tools.pptx
Strategies for Successful Data Migration Tools.pptxStrategies for Successful Data Migration Tools.pptx
Strategies for Successful Data Migration Tools.pptx
 
Multiple Your Crypto Portfolio with the Innovative Features of Advanced Crypt...
Multiple Your Crypto Portfolio with the Innovative Features of Advanced Crypt...Multiple Your Crypto Portfolio with the Innovative Features of Advanced Crypt...
Multiple Your Crypto Portfolio with the Innovative Features of Advanced Crypt...
 
Enhancing Research Orchestration Capabilities at ORNL.pdf
Enhancing Research Orchestration Capabilities at ORNL.pdfEnhancing Research Orchestration Capabilities at ORNL.pdf
Enhancing Research Orchestration Capabilities at ORNL.pdf
 

EclipseCon France 2017 - Xtending Our Vhdl Xtext Formatter With The Formatter2 API

  • 1. redefine.digital.design: Helping you deal with complexity in VHDL and Verilog. Xtending our VHDL Xtext formatter with the formatter2 API ir. Titouan Vervack EclipseCon France 2017-06-21
  • 2. redefine.digital.design: Helping you deal with complexity in VHDL and Verilog. Xtending our VHDL Xtext formatter with the formatter2 API ir. Titouan Vervack EclipseCon France, Toulouse 2017-06-21
  • 4. What do we do? VHDL & SV IDE 3
  • 5. What do we do? Advanced analysis and linting 4
  • 6. What do we do? Visualisation 5
  • 7. What do we do? Visualisation 6
  • 8. What do we do? Eat cake 7
  • 9. What do we do? And cookies... 8
  • 10. What do we do? And occasionally… formatting 9
  • 11. What do we do? And occasionally… formatting 9
  • 13. Our formatter problems ● Big grammar ○ ~1.2k LoC ○ ~200 rules 10
  • 14. Our formatter problems ● Big grammar ○ ~1.2k LoC ○ ~200 rules ● Hard to fix bugs 10
  • 15. Our formatter problems ● Big grammar ○ ~1.2k LoC ○ ~200 rules ● Hard to fix bugs ● Near impossible to add new features 10
  • 16. Formatter 1.0 vs Formatter 2.0 11 Formatter 1.0 Formatter 2.0 ● No access to ○ Node model ○ AST ○ Text ● => Specify everything purely on the grammar ● => Lots of hacks ● Access to ○ Node model ○ AST ○ Grammar ● Can’t take context into account ○ Can’t adjust to the user ● Context aware formatting ○ Conditional formatting ○ Table formatting ● Not customizable ● Very customizable
  • 17. Formatter 2.0 region example variable _ foo _ : _ bit _ ; _-- barn variable foo : bit; -- bar = ISemanticRegion = IHiddenRegion _ -- bar n = IHiddenRegionPart 12 https://de.slideshare.net/meysholdt/xtexts-new-formatter-api
  • 18. Formatting 2.0 usage example https://de.slideshare.net/meysholdt/xtexts-new-formatter-api 13
  • 19. Formatting 2.0 usage example https://de.slideshare.net/meysholdt/xtexts-new-formatter-api class AwesomO4000 extends AbstractFormatter2 { } 13
  • 20. Formatting 2.0 usage example https://de.slideshare.net/meysholdt/xtexts-new-formatter-api class AwesomO4000 extends AbstractFormatter2 { def dispatch void format(FunctionDecl fd, extension IFormattableDocument d) { } } 13
  • 21. Formatting 2.0 usage example https://de.slideshare.net/meysholdt/xtexts-new-formatter-api class AwesomO4000 extends AbstractFormatter2 { def dispatch void format(FunctionDecl fd, extension IFormattableDocument d) { interior(fd.regionFor.keyword(“{”), fd.regionFor.keyword(“}”))[indent] } } 13
  • 22. Formatting 2.0 usage example https://de.slideshare.net/meysholdt/xtexts-new-formatter-api class AwesomO4000 extends AbstractFormatter2 { def dispatch void format(FunctionDecl fd, extension IFormattableDocument d) { interior(fd.regionFor.keyword(“{”), fd.regionFor.keyword(“}”))[indent] fd.declarations.forEach[format] } } 13
  • 23. Formatting 2.0 usage example https://de.slideshare.net/meysholdt/xtexts-new-formatter-api class AwesomO4000 extends AbstractFormatter2 { def dispatch void format(FunctionDecl fd, extension IFormattableDocument d) { interior(fd.regionFor.keyword(“{”), fd.regionFor.keyword(“}”))[indent] fd.declarations.forEach[format] fd.regionFor.keyword(“;”) } } 13
  • 24. Formatting 2.0 usage example https://de.slideshare.net/meysholdt/xtexts-new-formatter-api class AwesomO4000 extends AbstractFormatter2 { def dispatch void format(FunctionDecl fd, extension IFormattableDocument d) { interior(fd.regionFor.keyword(“{”), fd.regionFor.keyword(“}”))[indent] fd.declarations.forEach[format] fd.regionFor.keyword(“;”) .prepend[noSpace highPriority] } } 13
  • 25. Formatting 2.0 usage example https://de.slideshare.net/meysholdt/xtexts-new-formatter-api class AwesomO4000 extends AbstractFormatter2 { def dispatch void format(FunctionDecl fd, extension IFormattableDocument d) { interior(fd.regionFor.keyword(“{”), fd.regionFor.keyword(“}”))[indent] fd.declarations.forEach[format] fd.regionFor.keyword(“;”) .prepend[noSpace highPriority] .append[setNewlines(1, 1, 2)] } } 13
  • 26. Time for a plan 14
  • 27. Time for a plan 1. Make tests compatible 14
  • 28. Time for a plan 1. Make tests compatible 2. Start out easy: only indentation 14
  • 29. Time for a plan 1. Make tests compatible 2. Start out easy: only indentation 3. Fix tests one by one 14
  • 30. Time for a plan 1. Make tests compatible 2. Start out easy: only indentation 3. Fix tests one by one 4. Fix old bugs 14
  • 31. Time for a plan 1. Make tests compatible 2. Start out easy: only indentation 3. Fix tests one by one 4. Fix old bugs 5. Do not introduce new bugs 14
  • 32. Time for a plan 1. Make tests compatible 2. Start out easy: only indentation 3. Fix tests one by one 4. Fix old bugs 5. Do not introduce new bugs 6. Feature parity & extend with new features 14
  • 33. Time for a plan 1. Make tests compatible 2. Start out easy: only indentation 3. Fix tests one by one 4. Fix old bugs 5. Do not introduce new bugs 6. Feature parity & extend with new features 7. Performance tweaking to same or better level than old 14
  • 34. Actual timeline formatter.format(node, node.offset, node.length).formattedText 1. Make tests compatible 15
  • 35. Actual timeline formatter.format(node, node.offset, node.length).formattedText 1. Make tests compatible 15
  • 36. Actual timeline formatter.format(node, node.offset, node.length).formattedText 1. Make tests compatible val request = new FormatterRequest() val parsed = new XtextResource() parsed.contents.add(parseResult.rootASTElement) parsed.setParseResult(parseResult) val access = builder.forNodeModel(resource).create() request.setTextRegionAccess(access) val replacements = formatter.format(request) access.rewriter.renderToString(replacements) 15
  • 38. interior(entity.regionFor.keyword(“is”), entity.regionFor.keyword(“end”))[indent] Actual timeline 2. Start out easy: only indentation ● Indentation requires newline definitions 16
  • 39. interior(entity.regionFor.keyword(“is”), entity.regionFor.keyword(“end”))[indent] Actual timeline 2. Start out easy: only indentation ● Indentation requires newline definitions ● => replace all newlines with… the same amount of newlines 16
  • 40. Actual timeline 3. Fix tests one by one 4. Fix old bugs 17
  • 41. Actual timeline 3. Fix tests one by one 4. Fix old bugs 17
  • 42. Actual timeline 5. Do not introduce new bugs 18
  • 43. Actual timeline 5. Do not introduce new bugs 18
  • 44. Actual timeline 6. Feature parity & extend formatter with new features 19
  • 45. Actual timeline 6. Feature parity & extend formatter with new features ● Parity: 19
  • 46. Actual timeline 6. Feature parity & extend formatter with new features ● Parity: ○ Keyword casing 19
  • 47. Actual timeline 6. Feature parity & extend formatter with new features ● Parity: ○ Keyword casing ○ Comment alignment to columns 19
  • 48. Actual timeline 6. Feature parity & extend formatter with new features ● Parity: ○ Keyword casing ○ Comment alignment to columns ○ Vertical alignment on keywords “:”, “:=”,... 19
  • 49. Actual timeline 6. Feature parity & extend formatter with new features ● Parity: ○ Keyword casing ○ Comment alignment to columns ○ Vertical alignment on keywords “:”, “:=”,... ○ Preserve newline 19
  • 50. Actual timeline 6. Feature parity & extend formatter with new features ● Parity: ○ Keyword casing ○ Comment alignment to columns ○ Vertical alignment on keywords “:”, “:=”,... ○ Preserve newline ● New features: 19
  • 51. Actual timeline 6. Feature parity & extend formatter with new features ● Parity: ○ Keyword casing ○ Comment alignment to columns ○ Vertical alignment on keywords “:”, “:=”,... ○ Preserve newline ● New features: ○ Correct indentation 19
  • 52. Actual timeline 6. Feature parity & extend formatter with new features ● Parity: ○ Keyword casing ○ Comment alignment to columns ○ Vertical alignment on keywords “:”, “:=”,... ○ Preserve newline ● New features: ○ Correct indentation ○ Formatter tags 19
  • 53. Actual timeline 6. Feature parity & extend formatter with new features ● Parity: ○ Keyword casing ○ Comment alignment to columns ○ Vertical alignment on keywords “:”, “:=”,... ○ Preserve newline ● New features: ○ Correct indentation ○ Formatter tags Easy once we have alignment 19
  • 56. Alignment? ● Replacements are added in random order, applied in correct order 21
  • 57. Alignment? ● Replacements are added in random order, applied in correct order ● Alignment needs to be done on post-formatted input 21
  • 58. Alignment? ● Replacements are added in random order, applied in correct order ● Alignment needs to be done on post-formatted input ● How do I know which region to format? 21
  • 65. Alignment! Find smallest encapsulating object that formats region between start and end start end 22
  • 66. Alignment! Find smallest encapsulating object that formats region between start and end start end 22
  • 67. Alignment! clk : in std_logic := ‘X’; 23
  • 68. Alignment! clk : in std_logic := ‘X’; start end 23
  • 69. PortDeclaration Alignment! clk : in std_logic := ‘X’; start end name direction type value end.getSemanticElement() PortDeclaration PortList 23
  • 70. PortDeclaration Alignment! clk : in std_logic := ‘X’; start end name direction type value offset x x + 4 end.getSemanticElement() PortDeclaration PortList 23
  • 71. val rule = portDecl.getParserRule() val oldAccess = createTextRegionAccess(rule, portDecl.text) val formatted = portDecl.format() Alignment! Format smallest encapsulating object 24
  • 72. val rule = portDecl.getParserRule() val oldAccess = createTextRegionAccess(rule, portDecl.text) val formatted = portDecl.format() Alignment! val newAccess = createTextRegionAccess(rule, formatted.text) val oldIndices = oldAccess.getIndices(start, end) val length = newAccess.countBetween(oldIndices) Format smallest encapsulating object Map unformatted string to formatted string 24
  • 73. Align on first parameter? →return ( →→foo((5, →→·····6), →→····3)); 25
  • 74. Align on first parameter? →return ( →→foo((5, →→·····6), →→····3)); 25
  • 75. Align on first parameter? →return ( →→foo((5, →→·····6), →→····3)); →return (5, →········foo((5, →·············6), →············3)); 25
  • 76. Align on first parameter? →return ( →→foo((5, →→·····6), →→····3)); →return (5, →········foo((5, →·············6), →············3)); 25
  • 77. Align on first parameter? →return ( →→foo((5, →→·····6), →→····3)); →return (5, →········foo((5, →·············6), →············3)); →return foo((5, →············6), →···········3)); 25
  • 78. Align on first parameter? →return ( →→foo((5, →→·····6), →→····3)); →return (5, →········foo((5, →·············6), →············3)); →return foo((5, →············6), →···········3)); 25
  • 79. Align on first parameter? →return ( →→foo((5, →→·····6), →→····3)); →return (5, →········foo((5, →·············6), →············3)); →return foo((5, →············6), →···········3)); →return foo( →→(5, →→·6), →→3)); 25
  • 80. Align on first parameter? →return ( →→foo((5, →→·····6), →→····3)); →return (5, →········foo((5, →·············6), →············3)); →return foo((5, →············6), →···········3)); →return foo( →→(5, →→·6), →→3)); 25
  • 81. Align on first parameter? →return ( →→foo((5, →→·····6), →→····3)); →return (5, →········foo((5, →·············6), →············3)); →return foo((5, →············6), →···········3)); →return foo( →→(5, →→·6), →→3)); Find largest encapsulating element on same line 25
  • 82. Actual timeline 6. Feature parity & extend formatter with new features Correct indentation 26
  • 83. Actual timeline 6. Feature parity & extend formatter with new features Correct indentation val replacements = formatter.format(request) 26
  • 84. Actual timeline 6. Feature parity & extend formatter with new features Correct indentation val replacements = formatter.format(request) replacements .filter[ r| ] 26
  • 85. Actual timeline 6. Feature parity & extend formatter with new features Correct indentation val replacements = formatter.format(request) replacements .filter[ r| r.lineCount > 1 ] 26
  • 86. Actual timeline 6. Feature parity & extend formatter with new features Correct indentation val replacements = formatter.format(request) replacements .filter[ r| r.lineCount > 1 && r.replacementText.newlines + 1 == r.lineCount ] 26
  • 87. Actual timeline 6. Feature parity & extend formatter with new features Formatter tags 27
  • 88. Actual timeline 6. Feature parity & extend formatter with new features Formatter tags -- @formatter:off Turns formatter off -- @formatter:on Turns formatter on 27
  • 89. Actual timeline 6. Feature parity & extend formatter with new features Formatter tags -- @formatter:off Turns formatter off -- @formatter:on Turns formatter on val originalRegions = request.getRegions() ?: document.region 27
  • 90. Actual timeline 6. Feature parity & extend formatter with new features Formatter tags -- @formatter:off Turns formatter off -- @formatter:on Turns formatter on val originalRegions = request.getRegions() ?: document.region val betweenRegions = document.findRegionsBetween(off, on) 27
  • 91. Actual timeline 6. Feature parity & extend formatter with new features Formatter tags -- @formatter:off Turns formatter off -- @formatter:on Turns formatter on val originalRegions = request.getRegions() ?: document.region val betweenRegions = document.findRegionsBetween(off, on) .addAll(document.findRegionsBetween(off, EOF)) 27
  • 92. Actual timeline 6. Feature parity & extend formatter with new features Formatter tags -- @formatter:off Turns formatter off -- @formatter:on Turns formatter on val originalRegions = request.getRegions() ?: document.region val betweenRegions = document.findRegionsBetween(off, on) .addAll(document.findRegionsBetween(off, EOF)) val newRegions = originalRegions.removeRegions(betweenRegions) 27
  • 93. Actual timeline 6. Feature parity & extend formatter with new features Formatter tags -- @formatter:off Turns formatter off -- @formatter:on Turns formatter on val originalRegions = request.getRegions() ?: document.region val betweenRegions = document.findRegionsBetween(off, on) .addAll(document.findRegionsBetween(off, EOF)) val newRegions = originalRegions.removeRegions(betweenRegions) request.setRegions(newRegions) 27
  • 94. Performance 7. Performance tweaking to same or better level than old 28
  • 95. Performance 7. Performance tweaking to same or better level than old ● Cache ITextRegionAccess in subformats 28
  • 96. Performance 7. Performance tweaking to same or better level than old ● Cache ITextRegionAccess in subformats ● Cache IParser.createAllRules(Grammar) 28
  • 97. Performance 7. Performance tweaking to same or better level than old ● Cache ITextRegionAccess in subformats ● Cache IParser.createAllRules(Grammar) ● Merge all replacements into one big replacement 28
  • 98. Performance 7. Performance tweaking to same or better level than old emacs/xtend > 25m 29
  • 99. Performance 7. Performance tweaking to same or better level than old emacs/xtend > 25m 30
  • 100. Biggest problems in hindsight 31
  • 101. Biggest problems in hindsight ● Tests pass, close enough? 31
  • 102. Biggest problems in hindsight ● Tests pass, close enough? ○ Nope, old testset isn’t nearly enough 31
  • 103. Biggest problems in hindsight ● Tests pass, close enough? ○ Nope, old testset isn’t nearly enough ● Comments are an enormous pain: eat newlines, add spaces, eat spaces, fake empty lines 31
  • 104. Biggest problems in hindsight ● Tests pass, close enough? ○ Nope, old testset isn’t nearly enough ● Comments are an enormous pain: eat newlines, add spaces, eat spaces, fake empty lines ● Alignment interactions with normal and first param alignments and comments 31
  • 105. Biggest problems in hindsight ● Tests pass, close enough? ○ Nope, old testset isn’t nearly enough ● Comments are an enormous pain: eat newlines, add spaces, eat spaces, fake empty lines ● Alignment interactions with normal and first param alignments and comments 31
  • 106. Biggest problems in hindsight ● Tests pass, close enough? ○ Nope, old testset isn’t nearly enough ● Comments are an enormous pain: eat newlines, add spaces, eat spaces, fake empty lines ● Alignment interactions with normal and first param alignments and comments 31
  • 107. Biggest problems in hindsight ● Tests pass, close enough? ○ Nope, old testset isn’t nearly enough ● Comments are an enormous pain: eat newlines, add spaces, eat spaces, fake empty lines ● Alignment interactions with normal and first param alignments and comments 31
  • 108. Biggest problems in hindsight ● Tests pass, close enough? ○ Nope, old testset isn’t nearly enough ● Comments are an enormous pain: eat newlines, add spaces, eat spaces, fake empty lines ● Alignment interactions with normal and first param alignments and comments 3031
  • 109. Biggest problems in hindsight ● Tests pass, close enough? ○ Nope, old testset isn’t nearly enough ● Comments are an enormous pain: eat newlines, add spaces, eat spaces, fake empty lines ● Alignment interactions with normal and first param alignments and comments 3031
  • 110. Biggest problems in hindsight ● Tests pass, close enough? ○ Nope, old testset isn’t nearly enough ● Comments are an enormous pain: eat newlines, add spaces, eat spaces, fake empty lines ● Alignment interactions with normal and first param alignments and comments 3031
  • 111. Warning to Xtext users Default ExceptionHandler logs DSL source code to stderr 32
  • 113. Sigasi future work ● Smooth out remaining bugs 33
  • 114. Sigasi future work ● Smooth out remaining bugs ● Some more context awareness 33
  • 115. Sigasi future work ● Smooth out remaining bugs ● Some more context awareness ● Autowrap 33
  • 116. Sigasi future work ● Smooth out remaining bugs ● Some more context awareness ● Autowrap ● Performance 33
  • 117. Sigasi future work ● Smooth out remaining bugs ● Some more context awareness ● Autowrap ● Performance ● Upstream features 33
  • 118. Sigasi future work ● Smooth out remaining bugs ● Some more context awareness ● Autowrap ● Performance ● Upstream features ○ Formatter tags 33
  • 119. Sigasi future work ● Smooth out remaining bugs ● Some more context awareness ● Autowrap ● Performance ● Upstream features ○ Formatter tags ○ Correct indentation 33
  • 120. Sigasi future work ● Smooth out remaining bugs ● Some more context awareness ● Autowrap ● Performance ● Upstream features ○ Formatter tags ○ Correct indentation ○ Performance optimizations 33
  • 122. Xtext wish list ● Accept my PRs (tags, correct indent, performance) 34
  • 123. Xtext wish list ● Accept my PRs (tags, correct indent, performance) ● Fix/discuss my issues 34
  • 124. Xtext wish list ● Accept my PRs (tags, correct indent, performance) ● Fix/discuss my issues ● Fix Xtend formatter issues 34
  • 125. Xtext wish list ● Accept my PRs (tags, correct indent, performance) ● Fix/discuss my issues ● Fix Xtend formatter issues ● Very slow Xtend formatter source file 34
  • 126. Xtext wish list ● Accept my PRs (tags, correct indent, performance) ● Fix/discuss my issues ● Fix Xtend formatter issues ● Very slow Xtend formatter source file ● Add pre- and post format hooks in format(FormatterRequest) 34
  • 130. Conclusion ● Context aware ● Debugable ● Good performance 35
  • 131. Conclusion ● Context aware ● Debugable ● Good performance ● Very customizable 35
  • 132. Conclusion ● Context aware ● Debugable ● Good performance ● Very customizable ● User friendly 35
  • 133. Conclusion ● Context aware ● Debugable ● Good performance ● Very customizable ● User friendly ○ Done in 2 months (base in 2 weeks) while first task and not used to Xtend 35
  • 134. Conclusion ● Context aware ● Debugable ● Good performance ● Very customizable ● User friendly ○ Done in 2 months (base in 2 weeks) while first task and not used to Xtend ● Happy with the switch 35
  • 135. Conclusion ● Context aware ● Debugable ● Good performance ● Very customizable ● User friendly ○ Done in 2 months (base in 2 weeks) while first task and not used to Xtend ● Happy with the switch ○ New features 35
  • 136. Conclusion ● Context aware ● Debugable ● Good performance ● Very customizable ● User friendly ○ Done in 2 months (base in 2 weeks) while first task and not used to Xtend ● Happy with the switch ○ New features ○ Very readable 35
  • 137. Conclusion ● Context aware ● Debugable ● Good performance ● Very customizable ● User friendly ○ Done in 2 months (base in 2 weeks) while first task and not used to Xtend ● Happy with the switch ○ New features ○ Very readable ○ Conditional formatting 35
  • 138. Evaluate the Sessions -1 0 +1 Sign in and vote at eclipsecon.org