SlideShare a Scribd company logo
B U I L D I N G A P Y T H O N I D E
W I T H X T E X T
S E B A S T I A N Z A R N E K O W
T H I S I S N O T A B O U T
T H I S I S A B O U T
A N D A N T L R
A N D
[nrt ]
I N D E N TAT I O N A WA R E
Block:
OPEN
stmt+=Statement+
CLOSE;
C H A L L E N G E S
I N D E N TA T I O N A WA R E L A N G U A G E S
PA R S I N G
C O N T E N T A S S I S T
F O R M AT T I N G
F O L D I N G
O U T L I N E
C H A L L E N G E S
I N D E N TA T I O N A WA R E L A N G U A G E S
PA R S I N G
I N D E N TA T I O N A WA R E L A N G U A G E S - C H A L L E N G E S
PA R S I N G
I N D E N TA T I O N A WA R E L A N G U A G E S - C H A L L E N G E S
Stateless, Upfront Lexing
Reentrant Lexing
CommonToken Oddities
Token Types
Only Basic Logic in Terminal Rules
S O M E P Y T H O N E S Q U E C O D E
if name==“Sebastian”:
println “Hello”
S O M E P Y T H O N E S Q U E C O D E
if.name==“Sebastian”:n
....println.“Hello”n
PA R S I N G - T O K E N I Z I N G
i f . n a m e = = “ S e b a s t i a

n ” : n . . . . p r i n t l n . “ H
e l l o ” n
PA R S I N G - T O K E N I Z I N G
i f . n a m
e = = “ S e
b a s t i a
n ” : n . .
. . p r i n
t l n . “ H
e l l o ” n
CharStream
o.a.IntStream
AntlrStringStream
PA R S I N G - T O K E N I Z I N G
if

.

name

==

“Sebastian”

:

n....

println

.

“Hello”

n
CharStream
o.a.IntStream
AntlrStringStream
PA R S I N G - T O K E N I Z I N G
if

.

name

==

“Sebastian”

:

n....

println

.

“Hello”

n
CharStream
o.a.IntStream
AntlrStringStream
1 2
9
1 0
7
8
6
9
1 0
9
9
8
- 1
PA R S I N G - T O K E N I Z I N G
if

.

name

==

“Sebastian”

:

n....

println

.

“Hello”

n
CharStream
o.a.IntStream
TokenSource
Lexer
AntlrStringStream
1 2
9
1 0
7
8
6
9
1 0
9
9
8
- 1
PA R S I N G - T O K E N I Z I N G
if

.

name

==

“Sebastian”

:

n....

println

.

“Hello”

n
1 2
9
1 0
7
8
6
9
1 0
9
9
8
TokenStream
- 1
TokenSource
Lexer
o.a.IntStream
if

.

name

==

“Sebastian”

:

n....

println

.

“Hello”

n
1 2
9
1 0
7
8
6
9
1 0
9
9
8
- 1
Parser
TokenStream
TokenSource
PA R S I N G - T O K E N I Z I N G
Parser
TokenStream
TokenSource
PA R S I N G - T O K E N I Z I N G
9
9
9
9
- 1
if

.

name

==

“Sebastian”

:

n....

println

.

“Hello”

n
if

.

name

==

“Sebastian”

:

n....

println

.

“Hello”

n
9
9
9
9
- 1
TokenSource
TokenStream
?
PA R S I N G - T O K E N I Z I N G
Parser
R E C A P
Block:
OPEN
stmt+=Statement+
CLOSE;
IfStatement:
‘if’ cond=Condition ‘:’

then=Block;
R E C A P
if name==“Sebastian”:
println “Hello”
if

.

name

==

“Sebastian”

:

n....

println

.

“Hello”

n
n OPEN . . . .
9
9
9
9
- 1
1 3 9
n CLOSE1 4
PA R S I N G - T O K E N S P L I T T I N G
if

.

name

==

“Sebastian”

:

n....

println

.

“Hello”

n
9
9
9
9
- 1
1 3 9
1 4
PA R S I N G - T O K E N S P L I T T I N G
if

.

name

==

“Sebastian”

:

n....

println

.

“Hello”

n
1 3 9
1 4
PA R S I N G - T O K E N S P L I T T I N G
1 2
9
1 0
7
8
6
9
1 0
9
9
8
- 1
if

.

name

==

“Sebastian”

:

n....

println

.

“Hello”

n
PA R S I N G - T O K E N S P L I T T I N G
1 3 9
1 4
TokenStream
Parser
SplittingTokenSource
TokenSource
1 2
9
1 0
7
8
6
9
1 0
9
9
8
- 1
Lexer
L E T ’ S D O T H I S
I N D E N TA T I O N A WA R E L A N G U A G E S
Block:
OPEN
stmt+=Statement+
CLOSE;
1. D E F I N E I N D E N TAT I O N 

T O K E N S
1. D E F I N E I N D E N TAT I O N 

T O K E N S
terminal OPEN: ‘synthetic:OPEN’;
terminal CLOSE: ‘synthetic:CLOSE’;
fragment = parser.antlr.ex.rt.AntlrGeneratorFragment {}
..
fragment =

parser.antlr.ex.ca.ContentAssistParserGeneratorFragment {}
2. A D J U S T M W E 2
W O R K F L O W
1. GENERATE SPLITTING TOKEN SOURCE
2. DISABLE PARTIAL PARSING
public class MyDslTokenSource extends AbstractIndentationTokenSource {
public MyDslTokenSource(TokenSource delegate) {
super(delegate);
}
@Override
protected boolean shouldSplitTokenImpl(Token token) {
return token.getType() == InternalMyDslParser.RULE_WS;
}
@Override
protected int getBeginTokenType() {
return InternalMyDslParser.RULE_OPEN;
}
@Override
protected int getEndTokenType() {
return InternalMyDslParser.RULE_CLOSE;
}
}
3. M A R K T O K E N S A S
S P L I T TA B L E
3. M A R K T O K E N S A S
S P L I T TA B L E
protected Token createEndToken(int offset) {
CommonToken result = new CommonToken(getEndTokenType());
result.setText("");
result.setChannel(Token.DEFAULT_CHANNEL);
result.setStartIndex(offset);
result.setStopIndex(offset-1);
return result;
}
public class AbstractIndentationTokenSource

extends AbstractSplittingTokenSource {

…
…
}
@Override
protected boolean shouldSplitTokenImpl(Token token) {
return token.getType() == InternalMyDslParser.RULE_WS;
}
@Override
protected int getBeginTokenType() {
return InternalMyDslParser.RULE_OPEN;
}
@Override
protected int getEndTokenType() {
return InternalMyDslParser.RULE_CLOSE;
}
3. M A R K T O K E N S A S
S P L I T TA B L E
@Override
protected boolean shouldSplitTokenImpl(Token token) {
return token.getType() == InternalMyDslParser.RULE_WS;
}
@Override
protected int getBeginTokenType() {
return InternalMyDslParser.RULE_OPEN;
}
@Override
protected int getEndTokenType() {
return InternalMyDslParser.RULE_CLOSE;
}
3. M A R K T O K E N S A S
S P L I T TA B L E
@Override
protected boolean shouldEmitPendingEndTokens() {
return false;
}
4. M A R K T O K E N S A S
S P L I T TA B L E A G A I N
1. Configure Content-Assist Parser
2. Almost the same, but:
CharStream
o.a.IntStream TokenSource
Lexer
AntlrStringStream
P U T T I N G E V E R T H I N G T O G E T H E R
I N D E N TA T I O N A WA R E L A N G U A G E S
TokenStream Parser
AbstractSplittingTokenSource
AbstractIndentationTokenSource
O N E M O R E T H I N G
I N D E N TA T I O N A WA R E L A N G U A G E S
def void format(Block block,

extension IFormattableDocument document) {

val open = block.regionForRuleCallTo(OPENRule)
open.prepend[ newLineAndIncreaseIndentation ]
val close = block.regionForRuleCallTo(CLOSERule)
if (block.isLast)
close.append[ decreaseIndentation ]
else
close.append[ newLineAndDecreaseIndentation ]
}
def void format(Block block,

extension IFormattableDocument document) {
val open = block.regionForRuleCallTo(OPENRule)
open.prepend[ newLineAndIncreaseIndentation ]
val close = block.regionForRuleCallTo(CLOSERule)
if (block.isLast)
close.append[ decreaseIndentation ]
else
close.append[ newLineAndDecreaseIndentation ]
}
5. F O R M AT T I N G
1. Indent Blocks
2. Adjust NewLines
3. Remove superfluous spaces
PA R S I N G
C O N T E N T A S S I S T
F O R M AT T I N G
F O L D I N G
O U T L I N E
D O N E
I N D E N TA T I O N A WA R E L A N G U A G E S
Q & A

More Related Content

Similar to Building a Python IDE with Xtext

Artur Skowroński – Ten Typ tak ma - O systemach typów na przykładzie TypeScri...
Artur Skowroński – Ten Typ tak ma - O systemach typów na przykładzie TypeScri...Artur Skowroński – Ten Typ tak ma - O systemach typów na przykładzie TypeScri...
Artur Skowroński – Ten Typ tak ma - O systemach typów na przykładzie TypeScri...
Artur Skowroński
 
Type Systems on the example of TypeScript
Type Systems on the example of TypeScriptType Systems on the example of TypeScript
Type Systems on the example of TypeScript
Artur Skowroński
 
10 d bs in 30 minutes
10 d bs in 30 minutes10 d bs in 30 minutes
10 d bs in 30 minutes
David Simons
 
Frontend architecture on big and small sites
Frontend architecture on big and small sitesFrontend architecture on big and small sites
Frontend architecture on big and small sites
Toni Pinel
 
JavaFX, because you're worth it
JavaFX, because you're worth itJavaFX, because you're worth it
JavaFX, because you're worth it
Thierry Wasylczenko
 
4Developers: Adam Sznajder Taking advantage of microservice architecture and ...
4Developers: Adam Sznajder Taking advantage of microservice architecture and ...4Developers: Adam Sznajder Taking advantage of microservice architecture and ...
4Developers: Adam Sznajder Taking advantage of microservice architecture and ...
PROIDEA
 
4Developers: Adam Sznajder- Taking advantage of microservice architecture and...
4Developers: Adam Sznajder- Taking advantage of microservice architecture and...4Developers: Adam Sznajder- Taking advantage of microservice architecture and...
4Developers: Adam Sznajder- Taking advantage of microservice architecture and...
PROIDEA
 
infraXstructure: Adam Sznajder, Optymalizacja kosztów w Amazon Web Services -...
infraXstructure: Adam Sznajder, Optymalizacja kosztów w Amazon Web Services -...infraXstructure: Adam Sznajder, Optymalizacja kosztów w Amazon Web Services -...
infraXstructure: Adam Sznajder, Optymalizacja kosztów w Amazon Web Services -...
PROIDEA
 
Continuous Delivery As Code
Continuous Delivery As CodeContinuous Delivery As Code
Continuous Delivery As Code
Alex Soto
 
Fast api
Fast apiFast api
Fast api
Simone Di Maulo
 
Geb for Testing Your Grails Application GR8Conf India 2016
Geb for Testing Your Grails Application  GR8Conf India 2016Geb for Testing Your Grails Application  GR8Conf India 2016
Geb for Testing Your Grails Application GR8Conf India 2016
Jacob Aae Mikkelsen
 
Constructs and techniques and their implementation in different languages
Constructs and techniques and their implementation in different languagesConstructs and techniques and their implementation in different languages
Constructs and techniques and their implementation in different languages
OliverYoung22
 
Testing Fuse Fabric with Pax Exam
Testing Fuse Fabric with Pax ExamTesting Fuse Fabric with Pax Exam
Testing Fuse Fabric with Pax Exam
Henryk Konsek
 
Cyber Security - Becoming Evil
Cyber Security - Becoming EvilCyber Security - Becoming Evil
Cyber Security - Becoming Evil
University of Hertfordshire
 
Advanced Use of Properties and Scripts in TIBCO Spotfire
Advanced Use of Properties and Scripts in TIBCO SpotfireAdvanced Use of Properties and Scripts in TIBCO Spotfire
Advanced Use of Properties and Scripts in TIBCO Spotfire
Herwig Van Marck
 
Continuous delivery with Gradle
Continuous delivery with GradleContinuous delivery with Gradle
Continuous delivery with Gradle
Bob Paulin
 
Xcode Survival Guide Version Two
Xcode Survival Guide Version TwoXcode Survival Guide Version Two
Xcode Survival Guide Version Two
Kristina Fox
 
Linq introduction
Linq introductionLinq introduction
Linq introduction
Mohammad Alyan
 
ChatBots and conversational marketing | Six & Flow
ChatBots and conversational marketing | Six & FlowChatBots and conversational marketing | Six & Flow
ChatBots and conversational marketing | Six & Flow
Richard Wood
 
Using Phing for Fun and Profit
Using Phing for Fun and ProfitUsing Phing for Fun and Profit
Using Phing for Fun and Profit
Nicholas Jansma
 

Similar to Building a Python IDE with Xtext (20)

Artur Skowroński – Ten Typ tak ma - O systemach typów na przykładzie TypeScri...
Artur Skowroński – Ten Typ tak ma - O systemach typów na przykładzie TypeScri...Artur Skowroński – Ten Typ tak ma - O systemach typów na przykładzie TypeScri...
Artur Skowroński – Ten Typ tak ma - O systemach typów na przykładzie TypeScri...
 
Type Systems on the example of TypeScript
Type Systems on the example of TypeScriptType Systems on the example of TypeScript
Type Systems on the example of TypeScript
 
10 d bs in 30 minutes
10 d bs in 30 minutes10 d bs in 30 minutes
10 d bs in 30 minutes
 
Frontend architecture on big and small sites
Frontend architecture on big and small sitesFrontend architecture on big and small sites
Frontend architecture on big and small sites
 
JavaFX, because you're worth it
JavaFX, because you're worth itJavaFX, because you're worth it
JavaFX, because you're worth it
 
4Developers: Adam Sznajder Taking advantage of microservice architecture and ...
4Developers: Adam Sznajder Taking advantage of microservice architecture and ...4Developers: Adam Sznajder Taking advantage of microservice architecture and ...
4Developers: Adam Sznajder Taking advantage of microservice architecture and ...
 
4Developers: Adam Sznajder- Taking advantage of microservice architecture and...
4Developers: Adam Sznajder- Taking advantage of microservice architecture and...4Developers: Adam Sznajder- Taking advantage of microservice architecture and...
4Developers: Adam Sznajder- Taking advantage of microservice architecture and...
 
infraXstructure: Adam Sznajder, Optymalizacja kosztów w Amazon Web Services -...
infraXstructure: Adam Sznajder, Optymalizacja kosztów w Amazon Web Services -...infraXstructure: Adam Sznajder, Optymalizacja kosztów w Amazon Web Services -...
infraXstructure: Adam Sznajder, Optymalizacja kosztów w Amazon Web Services -...
 
Continuous Delivery As Code
Continuous Delivery As CodeContinuous Delivery As Code
Continuous Delivery As Code
 
Fast api
Fast apiFast api
Fast api
 
Geb for Testing Your Grails Application GR8Conf India 2016
Geb for Testing Your Grails Application  GR8Conf India 2016Geb for Testing Your Grails Application  GR8Conf India 2016
Geb for Testing Your Grails Application GR8Conf India 2016
 
Constructs and techniques and their implementation in different languages
Constructs and techniques and their implementation in different languagesConstructs and techniques and their implementation in different languages
Constructs and techniques and their implementation in different languages
 
Testing Fuse Fabric with Pax Exam
Testing Fuse Fabric with Pax ExamTesting Fuse Fabric with Pax Exam
Testing Fuse Fabric with Pax Exam
 
Cyber Security - Becoming Evil
Cyber Security - Becoming EvilCyber Security - Becoming Evil
Cyber Security - Becoming Evil
 
Advanced Use of Properties and Scripts in TIBCO Spotfire
Advanced Use of Properties and Scripts in TIBCO SpotfireAdvanced Use of Properties and Scripts in TIBCO Spotfire
Advanced Use of Properties and Scripts in TIBCO Spotfire
 
Continuous delivery with Gradle
Continuous delivery with GradleContinuous delivery with Gradle
Continuous delivery with Gradle
 
Xcode Survival Guide Version Two
Xcode Survival Guide Version TwoXcode Survival Guide Version Two
Xcode Survival Guide Version Two
 
Linq introduction
Linq introductionLinq introduction
Linq introduction
 
ChatBots and conversational marketing | Six & Flow
ChatBots and conversational marketing | Six & FlowChatBots and conversational marketing | Six & Flow
ChatBots and conversational marketing | Six & Flow
 
Using Phing for Fun and Profit
Using Phing for Fun and ProfitUsing Phing for Fun and Profit
Using Phing for Fun and Profit
 

More from Sebastian Zarnekow

Scoping Tips and Tricks
Scoping Tips and TricksScoping Tips and Tricks
Scoping Tips and Tricks
Sebastian Zarnekow
 
Extending the Xbase Typesystem
Extending the Xbase TypesystemExtending the Xbase Typesystem
Extending the Xbase Typesystem
Sebastian Zarnekow
 
Java Performance MythBusters
Java Performance MythBustersJava Performance MythBusters
Java Performance MythBusters
Sebastian Zarnekow
 
Xtext Best Practices
Xtext Best PracticesXtext Best Practices
Xtext Best Practices
Sebastian Zarnekow
 
Xtend - A Language Made for Java Developers
Xtend - A Language Made for Java DevelopersXtend - A Language Made for Java Developers
Xtend - A Language Made for Java Developers
Sebastian Zarnekow
 
MDSD with Eclipse @ JUG Hamburg
MDSD with Eclipse @ JUG HamburgMDSD with Eclipse @ JUG Hamburg
MDSD with Eclipse @ JUG Hamburg
Sebastian Zarnekow
 
Eclipse DemoCamp in Paris: Language Development with Xtext
Eclipse DemoCamp in Paris: Language Development with XtextEclipse DemoCamp in Paris: Language Development with Xtext
Eclipse DemoCamp in Paris: Language Development with Xtext
Sebastian Zarnekow
 
Textual Modeling Framework Xtext
Textual Modeling Framework XtextTextual Modeling Framework Xtext
Textual Modeling Framework Xtext
Sebastian Zarnekow
 

More from Sebastian Zarnekow (8)

Scoping Tips and Tricks
Scoping Tips and TricksScoping Tips and Tricks
Scoping Tips and Tricks
 
Extending the Xbase Typesystem
Extending the Xbase TypesystemExtending the Xbase Typesystem
Extending the Xbase Typesystem
 
Java Performance MythBusters
Java Performance MythBustersJava Performance MythBusters
Java Performance MythBusters
 
Xtext Best Practices
Xtext Best PracticesXtext Best Practices
Xtext Best Practices
 
Xtend - A Language Made for Java Developers
Xtend - A Language Made for Java DevelopersXtend - A Language Made for Java Developers
Xtend - A Language Made for Java Developers
 
MDSD with Eclipse @ JUG Hamburg
MDSD with Eclipse @ JUG HamburgMDSD with Eclipse @ JUG Hamburg
MDSD with Eclipse @ JUG Hamburg
 
Eclipse DemoCamp in Paris: Language Development with Xtext
Eclipse DemoCamp in Paris: Language Development with XtextEclipse DemoCamp in Paris: Language Development with Xtext
Eclipse DemoCamp in Paris: Language Development with Xtext
 
Textual Modeling Framework Xtext
Textual Modeling Framework XtextTextual Modeling Framework Xtext
Textual Modeling Framework Xtext
 

Recently uploaded

42 Ways to Generate Real Estate Leads - Sellxpert
42 Ways to Generate Real Estate Leads - Sellxpert42 Ways to Generate Real Estate Leads - Sellxpert
42 Ways to Generate Real Estate Leads - Sellxpert
vaishalijagtap12
 
The Role of DevOps in Digital Transformation.pdf
The Role of DevOps in Digital Transformation.pdfThe Role of DevOps in Digital Transformation.pdf
The Role of DevOps in Digital Transformation.pdf
mohitd6
 
Baha Majid WCA4Z IBM Z Customer Council Boston June 2024.pdf
Baha Majid WCA4Z IBM Z Customer Council Boston June 2024.pdfBaha Majid WCA4Z IBM Z Customer Council Boston June 2024.pdf
Baha Majid WCA4Z IBM Z Customer Council Boston June 2024.pdf
Baha Majid
 
All you need to know about Spring Boot and GraalVM
All you need to know about Spring Boot and GraalVMAll you need to know about Spring Boot and GraalVM
All you need to know about Spring Boot and GraalVM
Alina Yurenko
 
ppt on the brain chip neuralink.pptx
ppt  on   the brain  chip neuralink.pptxppt  on   the brain  chip neuralink.pptx
ppt on the brain chip neuralink.pptx
Reetu63
 
How GenAI Can Improve Supplier Performance Management.pdf
How GenAI Can Improve Supplier Performance Management.pdfHow GenAI Can Improve Supplier Performance Management.pdf
How GenAI Can Improve Supplier Performance Management.pdf
Zycus
 
The Rising Future of CPaaS in the Middle East 2024
The Rising Future of CPaaS in the Middle East 2024The Rising Future of CPaaS in the Middle East 2024
The Rising Future of CPaaS in the Middle East 2024
Yara Milbes
 
WMF 2024 - Unlocking the Future of Data Powering Next-Gen AI with Vector Data...
WMF 2024 - Unlocking the Future of Data Powering Next-Gen AI with Vector Data...WMF 2024 - Unlocking the Future of Data Powering Next-Gen AI with Vector Data...
WMF 2024 - Unlocking the Future of Data Powering Next-Gen AI with Vector Data...
Luigi Fugaro
 
Transforming Product Development using OnePlan To Boost Efficiency and Innova...
Transforming Product Development using OnePlan To Boost Efficiency and Innova...Transforming Product Development using OnePlan To Boost Efficiency and Innova...
Transforming Product Development using OnePlan To Boost Efficiency and Innova...
OnePlan Solutions
 
Alluxio Webinar | 10x Faster Trino Queries on Your Data Platform
Alluxio Webinar | 10x Faster Trino Queries on Your Data PlatformAlluxio Webinar | 10x Faster Trino Queries on Your Data Platform
Alluxio Webinar | 10x Faster Trino Queries on Your Data Platform
Alluxio, Inc.
 
美洲杯赔率投注网【​网址​🎉3977·EE​🎉】
美洲杯赔率投注网【​网址​🎉3977·EE​🎉】美洲杯赔率投注网【​网址​🎉3977·EE​🎉】
美洲杯赔率投注网【​网址​🎉3977·EE​🎉】
widenerjobeyrl638
 
一比一原版(USF毕业证)旧金山大学毕业证如何办理
一比一原版(USF毕业证)旧金山大学毕业证如何办理一比一原版(USF毕业证)旧金山大学毕业证如何办理
一比一原版(USF毕业证)旧金山大学毕业证如何办理
dakas1
 
Manyata Tech Park Bangalore_ Infrastructure, Facilities and More
Manyata Tech Park Bangalore_ Infrastructure, Facilities and MoreManyata Tech Park Bangalore_ Infrastructure, Facilities and More
Manyata Tech Park Bangalore_ Infrastructure, Facilities and More
narinav14
 
Penify - Let AI do the Documentation, you write the Code.
Penify - Let AI do the Documentation, you write the Code.Penify - Let AI do the Documentation, you write the Code.
Penify - Let AI do the Documentation, you write the Code.
KrishnaveniMohan1
 
Orca: Nocode Graphical Editor for Container Orchestration
Orca: Nocode Graphical Editor for Container OrchestrationOrca: Nocode Graphical Editor for Container Orchestration
Orca: Nocode Graphical Editor for Container Orchestration
Pedro J. Molina
 
Stork Product Overview: An AI-Powered Autonomous Delivery Fleet
Stork Product Overview: An AI-Powered Autonomous Delivery FleetStork Product Overview: An AI-Powered Autonomous Delivery Fleet
Stork Product Overview: An AI-Powered Autonomous Delivery Fleet
Vince Scalabrino
 
Migration From CH 1.0 to CH 2.0 and Mule 4.6 & Java 17 Upgrade.pptx
Migration From CH 1.0 to CH 2.0 and  Mule 4.6 & Java 17 Upgrade.pptxMigration From CH 1.0 to CH 2.0 and  Mule 4.6 & Java 17 Upgrade.pptx
Migration From CH 1.0 to CH 2.0 and Mule 4.6 & Java 17 Upgrade.pptx
ervikas4
 
The Comprehensive Guide to Validating Audio-Visual Performances.pdf
The Comprehensive Guide to Validating Audio-Visual Performances.pdfThe Comprehensive Guide to Validating Audio-Visual Performances.pdf
The Comprehensive Guide to Validating Audio-Visual Performances.pdf
kalichargn70th171
 
Voxxed Days Trieste 2024 - Unleashing the Power of Vector Search and Semantic...
Voxxed Days Trieste 2024 - Unleashing the Power of Vector Search and Semantic...Voxxed Days Trieste 2024 - Unleashing the Power of Vector Search and Semantic...
Voxxed Days Trieste 2024 - Unleashing the Power of Vector Search and Semantic...
Luigi Fugaro
 

Recently uploaded (20)

42 Ways to Generate Real Estate Leads - Sellxpert
42 Ways to Generate Real Estate Leads - Sellxpert42 Ways to Generate Real Estate Leads - Sellxpert
42 Ways to Generate Real Estate Leads - Sellxpert
 
The Role of DevOps in Digital Transformation.pdf
The Role of DevOps in Digital Transformation.pdfThe Role of DevOps in Digital Transformation.pdf
The Role of DevOps in Digital Transformation.pdf
 
Baha Majid WCA4Z IBM Z Customer Council Boston June 2024.pdf
Baha Majid WCA4Z IBM Z Customer Council Boston June 2024.pdfBaha Majid WCA4Z IBM Z Customer Council Boston June 2024.pdf
Baha Majid WCA4Z IBM Z Customer Council Boston June 2024.pdf
 
All you need to know about Spring Boot and GraalVM
All you need to know about Spring Boot and GraalVMAll you need to know about Spring Boot and GraalVM
All you need to know about Spring Boot and GraalVM
 
ppt on the brain chip neuralink.pptx
ppt  on   the brain  chip neuralink.pptxppt  on   the brain  chip neuralink.pptx
ppt on the brain chip neuralink.pptx
 
How GenAI Can Improve Supplier Performance Management.pdf
How GenAI Can Improve Supplier Performance Management.pdfHow GenAI Can Improve Supplier Performance Management.pdf
How GenAI Can Improve Supplier Performance Management.pdf
 
The Rising Future of CPaaS in the Middle East 2024
The Rising Future of CPaaS in the Middle East 2024The Rising Future of CPaaS in the Middle East 2024
The Rising Future of CPaaS in the Middle East 2024
 
WMF 2024 - Unlocking the Future of Data Powering Next-Gen AI with Vector Data...
WMF 2024 - Unlocking the Future of Data Powering Next-Gen AI with Vector Data...WMF 2024 - Unlocking the Future of Data Powering Next-Gen AI with Vector Data...
WMF 2024 - Unlocking the Future of Data Powering Next-Gen AI with Vector Data...
 
Transforming Product Development using OnePlan To Boost Efficiency and Innova...
Transforming Product Development using OnePlan To Boost Efficiency and Innova...Transforming Product Development using OnePlan To Boost Efficiency and Innova...
Transforming Product Development using OnePlan To Boost Efficiency and Innova...
 
Alluxio Webinar | 10x Faster Trino Queries on Your Data Platform
Alluxio Webinar | 10x Faster Trino Queries on Your Data PlatformAlluxio Webinar | 10x Faster Trino Queries on Your Data Platform
Alluxio Webinar | 10x Faster Trino Queries on Your Data Platform
 
美洲杯赔率投注网【​网址​🎉3977·EE​🎉】
美洲杯赔率投注网【​网址​🎉3977·EE​🎉】美洲杯赔率投注网【​网址​🎉3977·EE​🎉】
美洲杯赔率投注网【​网址​🎉3977·EE​🎉】
 
一比一原版(USF毕业证)旧金山大学毕业证如何办理
一比一原版(USF毕业证)旧金山大学毕业证如何办理一比一原版(USF毕业证)旧金山大学毕业证如何办理
一比一原版(USF毕业证)旧金山大学毕业证如何办理
 
Manyata Tech Park Bangalore_ Infrastructure, Facilities and More
Manyata Tech Park Bangalore_ Infrastructure, Facilities and MoreManyata Tech Park Bangalore_ Infrastructure, Facilities and More
Manyata Tech Park Bangalore_ Infrastructure, Facilities and More
 
Penify - Let AI do the Documentation, you write the Code.
Penify - Let AI do the Documentation, you write the Code.Penify - Let AI do the Documentation, you write the Code.
Penify - Let AI do the Documentation, you write the Code.
 
Orca: Nocode Graphical Editor for Container Orchestration
Orca: Nocode Graphical Editor for Container OrchestrationOrca: Nocode Graphical Editor for Container Orchestration
Orca: Nocode Graphical Editor for Container Orchestration
 
Stork Product Overview: An AI-Powered Autonomous Delivery Fleet
Stork Product Overview: An AI-Powered Autonomous Delivery FleetStork Product Overview: An AI-Powered Autonomous Delivery Fleet
Stork Product Overview: An AI-Powered Autonomous Delivery Fleet
 
Migration From CH 1.0 to CH 2.0 and Mule 4.6 & Java 17 Upgrade.pptx
Migration From CH 1.0 to CH 2.0 and  Mule 4.6 & Java 17 Upgrade.pptxMigration From CH 1.0 to CH 2.0 and  Mule 4.6 & Java 17 Upgrade.pptx
Migration From CH 1.0 to CH 2.0 and Mule 4.6 & Java 17 Upgrade.pptx
 
The Comprehensive Guide to Validating Audio-Visual Performances.pdf
The Comprehensive Guide to Validating Audio-Visual Performances.pdfThe Comprehensive Guide to Validating Audio-Visual Performances.pdf
The Comprehensive Guide to Validating Audio-Visual Performances.pdf
 
Voxxed Days Trieste 2024 - Unleashing the Power of Vector Search and Semantic...
Voxxed Days Trieste 2024 - Unleashing the Power of Vector Search and Semantic...Voxxed Days Trieste 2024 - Unleashing the Power of Vector Search and Semantic...
Voxxed Days Trieste 2024 - Unleashing the Power of Vector Search and Semantic...
 
bgiolcb
bgiolcbbgiolcb
bgiolcb
 

Building a Python IDE with Xtext

  • 1. B U I L D I N G A P Y T H O N I D E W I T H X T E X T S E B A S T I A N Z A R N E K O W
  • 2. T H I S I S N O T A B O U T
  • 3. T H I S I S A B O U T
  • 4. A N D A N T L R
  • 6. I N D E N TAT I O N A WA R E Block: OPEN stmt+=Statement+ CLOSE;
  • 7. C H A L L E N G E S I N D E N TA T I O N A WA R E L A N G U A G E S
  • 8. PA R S I N G C O N T E N T A S S I S T F O R M AT T I N G F O L D I N G O U T L I N E C H A L L E N G E S I N D E N TA T I O N A WA R E L A N G U A G E S
  • 9. PA R S I N G I N D E N TA T I O N A WA R E L A N G U A G E S - C H A L L E N G E S
  • 10. PA R S I N G I N D E N TA T I O N A WA R E L A N G U A G E S - C H A L L E N G E S Stateless, Upfront Lexing Reentrant Lexing CommonToken Oddities Token Types Only Basic Logic in Terminal Rules
  • 11. S O M E P Y T H O N E S Q U E C O D E if name==“Sebastian”: println “Hello”
  • 12. S O M E P Y T H O N E S Q U E C O D E if.name==“Sebastian”:n ....println.“Hello”n
  • 13. PA R S I N G - T O K E N I Z I N G i f . n a m e = = “ S e b a s t i a
 n ” : n . . . . p r i n t l n . “ H e l l o ” n
  • 14. PA R S I N G - T O K E N I Z I N G i f . n a m e = = “ S e b a s t i a n ” : n . . . . p r i n t l n . “ H e l l o ” n CharStream o.a.IntStream AntlrStringStream
  • 15. PA R S I N G - T O K E N I Z I N G if
 .
 name
 ==
 “Sebastian”
 :
 n....
 println
 .
 “Hello”
 n CharStream o.a.IntStream AntlrStringStream
  • 16. PA R S I N G - T O K E N I Z I N G if
 .
 name
 ==
 “Sebastian”
 :
 n....
 println
 .
 “Hello”
 n CharStream o.a.IntStream AntlrStringStream 1 2 9 1 0 7 8 6 9 1 0 9 9 8 - 1
  • 17. PA R S I N G - T O K E N I Z I N G if
 .
 name
 ==
 “Sebastian”
 :
 n....
 println
 .
 “Hello”
 n CharStream o.a.IntStream TokenSource Lexer AntlrStringStream 1 2 9 1 0 7 8 6 9 1 0 9 9 8 - 1
  • 18. PA R S I N G - T O K E N I Z I N G if
 .
 name
 ==
 “Sebastian”
 :
 n....
 println
 .
 “Hello”
 n 1 2 9 1 0 7 8 6 9 1 0 9 9 8 TokenStream - 1 TokenSource Lexer o.a.IntStream
  • 19. if
 .
 name
 ==
 “Sebastian”
 :
 n....
 println
 .
 “Hello”
 n 1 2 9 1 0 7 8 6 9 1 0 9 9 8 - 1 Parser TokenStream TokenSource PA R S I N G - T O K E N I Z I N G
  • 20. Parser TokenStream TokenSource PA R S I N G - T O K E N I Z I N G 9 9 9 9 - 1 if
 .
 name
 ==
 “Sebastian”
 :
 n....
 println
 .
 “Hello”
 n
  • 22. R E C A P Block: OPEN stmt+=Statement+ CLOSE; IfStatement: ‘if’ cond=Condition ‘:’
 then=Block;
  • 23. R E C A P if name==“Sebastian”: println “Hello”
  • 24. if
 .
 name
 ==
 “Sebastian”
 :
 n....
 println
 .
 “Hello”
 n n OPEN . . . . 9 9 9 9 - 1 1 3 9 n CLOSE1 4 PA R S I N G - T O K E N S P L I T T I N G
  • 26. if
 .
 name
 ==
 “Sebastian”
 :
 n....
 println
 .
 “Hello”
 n 1 3 9 1 4 PA R S I N G - T O K E N S P L I T T I N G 1 2 9 1 0 7 8 6 9 1 0 9 9 8 - 1
  • 27. if
 .
 name
 ==
 “Sebastian”
 :
 n....
 println
 .
 “Hello”
 n PA R S I N G - T O K E N S P L I T T I N G 1 3 9 1 4 TokenStream Parser SplittingTokenSource TokenSource 1 2 9 1 0 7 8 6 9 1 0 9 9 8 - 1 Lexer
  • 28. L E T ’ S D O T H I S I N D E N TA T I O N A WA R E L A N G U A G E S
  • 29. Block: OPEN stmt+=Statement+ CLOSE; 1. D E F I N E I N D E N TAT I O N 
 T O K E N S
  • 30. 1. D E F I N E I N D E N TAT I O N 
 T O K E N S terminal OPEN: ‘synthetic:OPEN’; terminal CLOSE: ‘synthetic:CLOSE’;
  • 31. fragment = parser.antlr.ex.rt.AntlrGeneratorFragment {} .. fragment =
 parser.antlr.ex.ca.ContentAssistParserGeneratorFragment {} 2. A D J U S T M W E 2 W O R K F L O W 1. GENERATE SPLITTING TOKEN SOURCE 2. DISABLE PARTIAL PARSING
  • 32. public class MyDslTokenSource extends AbstractIndentationTokenSource { public MyDslTokenSource(TokenSource delegate) { super(delegate); } @Override protected boolean shouldSplitTokenImpl(Token token) { return token.getType() == InternalMyDslParser.RULE_WS; } @Override protected int getBeginTokenType() { return InternalMyDslParser.RULE_OPEN; } @Override protected int getEndTokenType() { return InternalMyDslParser.RULE_CLOSE; } } 3. M A R K T O K E N S A S S P L I T TA B L E
  • 33. 3. M A R K T O K E N S A S S P L I T TA B L E protected Token createEndToken(int offset) { CommonToken result = new CommonToken(getEndTokenType()); result.setText(""); result.setChannel(Token.DEFAULT_CHANNEL); result.setStartIndex(offset); result.setStopIndex(offset-1); return result; } public class AbstractIndentationTokenSource
 extends AbstractSplittingTokenSource {
 … … }
  • 34. @Override protected boolean shouldSplitTokenImpl(Token token) { return token.getType() == InternalMyDslParser.RULE_WS; } @Override protected int getBeginTokenType() { return InternalMyDslParser.RULE_OPEN; } @Override protected int getEndTokenType() { return InternalMyDslParser.RULE_CLOSE; } 3. M A R K T O K E N S A S S P L I T TA B L E
  • 35. @Override protected boolean shouldSplitTokenImpl(Token token) { return token.getType() == InternalMyDslParser.RULE_WS; } @Override protected int getBeginTokenType() { return InternalMyDslParser.RULE_OPEN; } @Override protected int getEndTokenType() { return InternalMyDslParser.RULE_CLOSE; } 3. M A R K T O K E N S A S S P L I T TA B L E
  • 36. @Override protected boolean shouldEmitPendingEndTokens() { return false; } 4. M A R K T O K E N S A S S P L I T TA B L E A G A I N 1. Configure Content-Assist Parser 2. Almost the same, but:
  • 37. CharStream o.a.IntStream TokenSource Lexer AntlrStringStream P U T T I N G E V E R T H I N G T O G E T H E R I N D E N TA T I O N A WA R E L A N G U A G E S TokenStream Parser AbstractSplittingTokenSource AbstractIndentationTokenSource
  • 38. O N E M O R E T H I N G I N D E N TA T I O N A WA R E L A N G U A G E S
  • 39. def void format(Block block,
 extension IFormattableDocument document) {
 val open = block.regionForRuleCallTo(OPENRule) open.prepend[ newLineAndIncreaseIndentation ] val close = block.regionForRuleCallTo(CLOSERule) if (block.isLast) close.append[ decreaseIndentation ] else close.append[ newLineAndDecreaseIndentation ] } def void format(Block block,
 extension IFormattableDocument document) { val open = block.regionForRuleCallTo(OPENRule) open.prepend[ newLineAndIncreaseIndentation ] val close = block.regionForRuleCallTo(CLOSERule) if (block.isLast) close.append[ decreaseIndentation ] else close.append[ newLineAndDecreaseIndentation ] } 5. F O R M AT T I N G 1. Indent Blocks 2. Adjust NewLines 3. Remove superfluous spaces
  • 40. PA R S I N G C O N T E N T A S S I S T F O R M AT T I N G F O L D I N G O U T L I N E D O N E I N D E N TA T I O N A WA R E L A N G U A G E S
  • 41. Q & A