SlideShare una empresa de Scribd logo
1 de 41
Descargar para leer sin conexión
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

Más contenido relacionado

Similar a 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 TypeScriptArtur Skowroński
 
10 d bs in 30 minutes
10 d bs in 30 minutes10 d bs in 30 minutes
10 d bs in 30 minutesDavid 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 sitesToni Pinel
 
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
 
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
 
Continuous Delivery As Code
Continuous Delivery As CodeContinuous Delivery As Code
Continuous Delivery As CodeAlex Soto
 
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 2016Jacob 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 languagesOliverYoung22
 
Testing Fuse Fabric with Pax Exam
Testing Fuse Fabric with Pax ExamTesting Fuse Fabric with Pax Exam
Testing Fuse Fabric with Pax ExamHenryk Konsek
 
php[world] 2016 - You Don’t Need Node.js - Async Programming in PHP
php[world] 2016 - You Don’t Need Node.js - Async Programming in PHPphp[world] 2016 - You Don’t Need Node.js - Async Programming in PHP
php[world] 2016 - You Don’t Need Node.js - Async Programming in PHPAdam Englander
 
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 SpotfireHerwig Van Marck
 
Continuous delivery with Gradle
Continuous delivery with GradleContinuous delivery with Gradle
Continuous delivery with GradleBob Paulin
 
Xcode Survival Guide Version Two
Xcode Survival Guide Version TwoXcode Survival Guide Version Two
Xcode Survival Guide Version TwoKristina Fox
 
ChatBots and conversational marketing | Six & Flow
ChatBots and conversational marketing | Six & FlowChatBots and conversational marketing | Six & Flow
ChatBots and conversational marketing | Six & FlowRichard Wood
 

Similar a 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...
 
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 -...
 
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 ...
 
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
 
php[world] 2016 - You Don’t Need Node.js - Async Programming in PHP
php[world] 2016 - You Don’t Need Node.js - Async Programming in PHPphp[world] 2016 - You Don’t Need Node.js - Async Programming in PHP
php[world] 2016 - You Don’t Need Node.js - Async Programming in PHP
 
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
 

Más de Sebastian Zarnekow

Extending the Xbase Typesystem
Extending the Xbase TypesystemExtending the Xbase Typesystem
Extending the Xbase TypesystemSebastian 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 DevelopersSebastian Zarnekow
 
MDSD with Eclipse @ JUG Hamburg
MDSD with Eclipse @ JUG HamburgMDSD with Eclipse @ JUG Hamburg
MDSD with Eclipse @ JUG HamburgSebastian 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 XtextSebastian Zarnekow
 
Textual Modeling Framework Xtext
Textual Modeling Framework XtextTextual Modeling Framework Xtext
Textual Modeling Framework XtextSebastian Zarnekow
 

Más de 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
 

Último

Right Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsRight Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsJhone kinadey
 
Diamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with PrecisionDiamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with PrecisionSolGuruz
 
why an Opensea Clone Script might be your perfect match.pdf
why an Opensea Clone Script might be your perfect match.pdfwhy an Opensea Clone Script might be your perfect match.pdf
why an Opensea Clone Script might be your perfect match.pdfjoe51371421
 
HR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comHR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comFatema Valibhai
 
Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...OnePlan Solutions
 
Optimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVOptimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVshikhaohhpro
 
Project Based Learning (A.I).pptx detail explanation
Project Based Learning (A.I).pptx detail explanationProject Based Learning (A.I).pptx detail explanation
Project Based Learning (A.I).pptx detail explanationkaushalgiri8080
 
Professional Resume Template for Software Developers
Professional Resume Template for Software DevelopersProfessional Resume Template for Software Developers
Professional Resume Template for Software DevelopersVinodh Ram
 
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected WorkerHow To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected WorkerThousandEyes
 
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...harshavardhanraghave
 
How To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.jsHow To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.jsAndolasoft Inc
 
What is Binary Language? Computer Number Systems
What is Binary Language?  Computer Number SystemsWhat is Binary Language?  Computer Number Systems
What is Binary Language? Computer Number SystemsJheuzeDellosa
 
Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)OPEN KNOWLEDGE GmbH
 
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...soniya singh
 
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...MyIntelliSource, Inc.
 
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...gurkirankumar98700
 
Cloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStackCloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStackVICTOR MAESTRE RAMIREZ
 
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️anilsa9823
 
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...kellynguyen01
 
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...stazi3110
 

Último (20)

Right Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsRight Money Management App For Your Financial Goals
Right Money Management App For Your Financial Goals
 
Diamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with PrecisionDiamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with Precision
 
why an Opensea Clone Script might be your perfect match.pdf
why an Opensea Clone Script might be your perfect match.pdfwhy an Opensea Clone Script might be your perfect match.pdf
why an Opensea Clone Script might be your perfect match.pdf
 
HR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comHR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.com
 
Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...
 
Optimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVOptimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTV
 
Project Based Learning (A.I).pptx detail explanation
Project Based Learning (A.I).pptx detail explanationProject Based Learning (A.I).pptx detail explanation
Project Based Learning (A.I).pptx detail explanation
 
Professional Resume Template for Software Developers
Professional Resume Template for Software DevelopersProfessional Resume Template for Software Developers
Professional Resume Template for Software Developers
 
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected WorkerHow To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
 
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
 
How To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.jsHow To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.js
 
What is Binary Language? Computer Number Systems
What is Binary Language?  Computer Number SystemsWhat is Binary Language?  Computer Number Systems
What is Binary Language? Computer Number Systems
 
Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)
 
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
 
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
 
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
 
Cloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStackCloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStack
 
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️
 
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
 
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
 

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