Add Lepiter snippets for Carp

This commit is contained in:
2022-04-16 18:32:16 +02:00
parent 60321973fb
commit f1cac9749e
34 changed files with 597 additions and 61 deletions

View File

@@ -0,0 +1,21 @@
Class {
#name : #CarpExpressionNode,
#superclass : #SmaCCParseNode,
#category : #'Carp-AST'
}
{ #category : #generated }
CarpExpressionNode >> acceptVisitor: anExpressionVisitor [
^ anExpressionVisitor visitExpression: self
]
{ #category : #accessing }
CarpExpressionNode >> isQuoted [
^ parent ifNil: [ false ] ifNotNil: [ parent isQuoted ]
]
{ #category : #accessing }
CarpExpressionNode >> listDepth [
^ parent ifNil: [ 0 ] ifNotNil: [ parent listDepth + 1 ]
]

View File

@@ -13,6 +13,16 @@ CarpQuoteNode >> acceptVisitor: anExpressionVisitor [
^ anExpressionVisitor visitQuote: self ^ anExpressionVisitor visitQuote: self
] ]
{ #category : #accessing }
CarpQuoteNode >> isQuoted [
^ true
]
{ #category : #accessing }
CarpQuoteNode >> newMethod [
"This is a new method"
]
{ #category : #generated } { #category : #generated }
CarpQuoteNode >> nodeVariables [ CarpQuoteNode >> nodeVariables [

1
src/Carp-AST/package.st Normal file
View File

@@ -0,0 +1 @@
Package { #name : #'Carp-AST' }

View File

@@ -0,0 +1 @@
Package { #name : #'Carp-LanguageLink' }

View File

@@ -2,9 +2,11 @@ Class {
#name : #CarpArrayNode, #name : #CarpArrayNode,
#superclass : #CarpExpressionNode, #superclass : #CarpExpressionNode,
#instVars : [ #instVars : [
'expressions' 'leftBracket',
'expressions',
'rightBracket'
], ],
#category : #'Carp-AST' #category : #'Carp-Parser'
} }
{ #category : #generated } { #category : #generated }
@@ -38,3 +40,33 @@ CarpArrayNode >> initialize [
super initialize. super initialize.
expressions := OrderedCollection new: 2. expressions := OrderedCollection new: 2.
] ]
{ #category : #generated }
CarpArrayNode >> leftBracket [
^ leftBracket
]
{ #category : #generated }
CarpArrayNode >> leftBracket: aSmaCCToken [
leftBracket := aSmaCCToken
]
{ #category : #generated }
CarpArrayNode >> rightBracket [
^ rightBracket
]
{ #category : #generated }
CarpArrayNode >> rightBracket: aSmaCCToken [
rightBracket := aSmaCCToken
]
{ #category : #generated }
CarpArrayNode >> tokenVariables [
^ #( #leftBracket #rightBracket )
]

View File

@@ -2,9 +2,10 @@ Class {
#name : #CarpDerefNode, #name : #CarpDerefNode,
#superclass : #CarpExpressionNode, #superclass : #CarpExpressionNode,
#instVars : [ #instVars : [
'derefGlyph',
'value' 'value'
], ],
#category : #'Carp-AST' #category : #'Carp-Parser'
} }
{ #category : #generated } { #category : #generated }
@@ -13,12 +14,30 @@ CarpDerefNode >> acceptVisitor: anExpressionVisitor [
^ anExpressionVisitor visitDeref: self ^ anExpressionVisitor visitDeref: self
] ]
{ #category : #generated }
CarpDerefNode >> derefGlyph [
^ derefGlyph
]
{ #category : #generated }
CarpDerefNode >> derefGlyph: aSmaCCToken [
derefGlyph := aSmaCCToken
]
{ #category : #generated } { #category : #generated }
CarpDerefNode >> nodeVariables [ CarpDerefNode >> nodeVariables [
^ #( #value ) ^ #( #value )
] ]
{ #category : #generated }
CarpDerefNode >> tokenVariables [
^ #( #derefGlyph )
]
{ #category : #generated } { #category : #generated }
CarpDerefNode >> value [ CarpDerefNode >> value [

View File

@@ -2,9 +2,11 @@ Class {
#name : #CarpListNode, #name : #CarpListNode,
#superclass : #CarpExpressionNode, #superclass : #CarpExpressionNode,
#instVars : [ #instVars : [
'expressions' 'leftParen',
'expressions',
'rightParen'
], ],
#category : #'Carp-AST' #category : #'Carp-Parser'
} }
{ #category : #generated } { #category : #generated }
@@ -38,3 +40,33 @@ CarpListNode >> initialize [
super initialize. super initialize.
expressions := OrderedCollection new: 2. expressions := OrderedCollection new: 2.
] ]
{ #category : #generated }
CarpListNode >> leftParen [
^ leftParen
]
{ #category : #generated }
CarpListNode >> leftParen: aSmaCCToken [
leftParen := aSmaCCToken
]
{ #category : #generated }
CarpListNode >> rightParen [
^ rightParen
]
{ #category : #generated }
CarpListNode >> rightParen: aSmaCCToken [
rightParen := aSmaCCToken
]
{ #category : #generated }
CarpListNode >> tokenVariables [
^ #( #leftParen #rightParen )
]

View File

@@ -2,9 +2,11 @@ Class {
#name : #CarpMapNode, #name : #CarpMapNode,
#superclass : #CarpExpressionNode, #superclass : #CarpExpressionNode,
#instVars : [ #instVars : [
'pairs' 'leftBrace',
'pairs',
'rightBrace'
], ],
#category : #'Carp-AST' #category : #'Carp-Parser'
} }
{ #category : #generated } { #category : #generated }
@@ -25,6 +27,18 @@ CarpMapNode >> initialize [
pairs := OrderedCollection new: 2. pairs := OrderedCollection new: 2.
] ]
{ #category : #generated }
CarpMapNode >> leftBrace [
^ leftBrace
]
{ #category : #generated }
CarpMapNode >> leftBrace: aSmaCCToken [
leftBrace := aSmaCCToken
]
{ #category : #generated } { #category : #generated }
CarpMapNode >> pairs [ CarpMapNode >> pairs [
@@ -38,3 +52,21 @@ CarpMapNode >> pairs: anOrderedCollection [
pairs := anOrderedCollection. pairs := anOrderedCollection.
self setParents: self pairs to: self self setParents: self pairs to: self
] ]
{ #category : #generated }
CarpMapNode >> rightBrace [
^ rightBrace
]
{ #category : #generated }
CarpMapNode >> rightBrace: aSmaCCToken [
rightBrace := aSmaCCToken
]
{ #category : #generated }
CarpMapNode >> tokenVariables [
^ #( #leftBrace #rightBrace )
]

View File

@@ -6,7 +6,7 @@ Class {
{ #category : #'generated-accessing' } { #category : #'generated-accessing' }
CarpParser class >> cacheId [ CarpParser class >> cacheId [
^'2022-03-20T20:34:27.408287+01:00' ^'2022-04-16T18:21:43.028213+02:00'
] ]
{ #category : #generated } { #category : #generated }
@@ -95,22 +95,22 @@ Expression
| Unquote | Unquote
; ;
RefCall RefCall
: ""~"" Expression 'value' {{}} : ""~"" 'refGlyph' Expression 'value' {{}}
; ;
Unquote Unquote
: (""%"" | ""%@"") Expression 'value' {{}} : (""%"" 'unquoteGlyph' | ""%@""'unquoteGlyph') Expression 'value' {{}}
; ;
Ref Ref
: ""&"" Expression 'value' {{}} : ""&"" 'refGlyph' Expression 'value' {{}}
; ;
Deref Deref
: ""@"" Expression 'value' {{}} : ""@"" 'derefGlyph' Expression 'value' {{}}
; ;
Literal Literal
: String | List | Array | Symbol | Quote | Number | Character | Pattern | Map : String | List | Array | Symbol | Quote | Number | Character | Pattern | Map
; ;
Map Map
: ""{"" MapPairs ""}"" {{}} : ""{"" 'leftBrace' MapPairs ""}"" 'rightBrace' {{}}
; ;
MapPairs MapPairs
: :
@@ -120,7 +120,7 @@ MapPair
: Expression 'key' Expression 'value' {{Pair}} : Expression 'key' Expression 'value' {{Pair}}
; ;
Pattern Pattern
: ""#"" <string_literal> 'value' {{}} : ""#"" 'patternGlyph' <string_literal> 'value' {{}}
; ;
Character Character
: <character> 'value' {{}} : <character> 'value' {{}}
@@ -129,7 +129,7 @@ Number
: <numeric_literal> 'value' {{}} : <numeric_literal> 'value' {{}}
; ;
Array Array
: <open_bracket> Expressions <close_bracket> {{}} : <open_bracket> 'leftBracket' Expressions <close_bracket> 'rightBracket' {{}}
; ;
Quote Quote
: <quote> Expression 'value' {{}} : <quote> Expression 'value' {{}}
@@ -145,7 +145,7 @@ ModuleOrType
| <module> 'value' {{}} | <module> 'value' {{}}
; ;
List List
: <open_paren> Expressions <close_paren> {{}} : <open_paren> 'leftParen' Expressions <close_paren> 'rightParen' {{}}
; ;
String String
: <string_literal> 'value' {{}} : <string_literal> 'value' {{}}
@@ -157,42 +157,42 @@ CarpParser class >> reduceTable [
^#( ^#(
#(24 0 #reduceActionForExpressions1: 1289217 false) #(24 0 #reduceActionForExpressions1: 1289217 false)
#(23 1 #reduceActionForStart1: 1258497 false) #(23 1 #reduceActionForStart1: 1258497 false)
#(32 0 #reduceActionForExpressions1: 1712129 false) #(32 0 #reduceActionForExpressions1: 1803265 false)
#(43 1 #reduceActionForString1: 2274305 false) #(43 1 #reduceActionForString1: 2436097 false)
#(40 1 #reduceActionForVariable1: 2097153 false) #(40 1 #reduceActionForVariable1: 2233345 false)
#(41 1 #reduceActionForModuleOrType2: 2137090 false) #(41 1 #reduceActionForModuleOrType2: 2273282 false)
#(36 1 #reduceActionForNumber1: 1906689 false) #(36 1 #reduceActionForNumber1: 2013185 false)
#(35 1 #reduceActionForCharacter1: 1864705 false) #(35 1 #reduceActionForCharacter1: 1971201 false)
#(24 2 #reduceActionForExpressions2: 1289218 false) #(24 2 #reduceActionForExpressions2: 1289218 false)
#(25 1 #liftFirstValue: 1347588 false) #(25 1 #liftFirstValue: 1347588 false)
#(25 1 #liftFirstValue: 1347589 false) #(25 1 #liftFirstValue: 1347589 false)
#(25 1 #liftFirstValue: 1347587 false) #(25 1 #liftFirstValue: 1347587 false)
#(25 1 #liftFirstValue: 1347586 false) #(25 1 #liftFirstValue: 1347586 false)
#(25 1 #liftFirstValue: 1347585 false) #(25 1 #liftFirstValue: 1347585 false)
#(30 1 #liftFirstValue: 1587209 false) #(30 1 #liftFirstValue: 1652745 false)
#(30 1 #liftFirstValue: 1587208 false) #(30 1 #liftFirstValue: 1652744 false)
#(30 1 #liftFirstValue: 1587207 false) #(30 1 #liftFirstValue: 1652743 false)
#(30 1 #liftFirstValue: 1587206 false) #(30 1 #liftFirstValue: 1652742 false)
#(30 1 #liftFirstValue: 1587203 false) #(30 1 #liftFirstValue: 1652739 false)
#(30 1 #liftFirstValue: 1587205 false) #(30 1 #liftFirstValue: 1652741 false)
#(30 1 #liftFirstValue: 1587204 false) #(30 1 #liftFirstValue: 1652740 false)
#(39 1 #liftFirstValue: 2059266 false) #(39 1 #liftFirstValue: 2195458 false)
#(39 1 #liftFirstValue: 2059265 false) #(39 1 #liftFirstValue: 2195457 false)
#(30 1 #liftFirstValue: 1587202 false) #(30 1 #liftFirstValue: 1652738 false)
#(30 1 #liftFirstValue: 1587201 false) #(30 1 #liftFirstValue: 1652737 false)
#(34 2 #reduceActionForPattern1: 1815553 false) #(34 2 #reduceActionForPattern1: 1906689 false)
#(27 2 #reduceActionForUnquote1: 1455105 false) #(27 2 #reduceActionForUnquote1: 1466369 false)
#(27 2 #reduceActionForUnquote1: 1455106 false) #(27 2 #reduceActionForUnquote1: 1466370 false)
#(28 2 #reduceActionForRef1: 1507329 false) #(28 2 #reduceActionForRef1: 1548289 false)
#(29 2 #reduceActionForDeref1: 1546241 false) #(29 2 #reduceActionForDeref1: 1598465 false)
#(26 2 #reduceActionForRefCall1: 1412097 false) #(26 2 #reduceActionForRefCall1: 1412097 false)
#(38 2 #reduceActionForQuote1: 2014209 false) #(38 2 #reduceActionForQuote1: 2150401 false)
#(31 3 #reduceActionForMap1: 1679361 false) #(31 3 #reduceActionForMap1: 1744897 false)
#(32 2 #reduceActionForExpressions2: 1712130 false) #(32 2 #reduceActionForExpressions2: 1803266 false)
#(42 3 #reduceActionForList1: 2217985 false) #(42 3 #reduceActionForList1: 2354177 false)
#(41 3 #reduceActionForModuleOrType1: 2137089 false) #(41 3 #reduceActionForModuleOrType1: 2273281 false)
#(37 3 #reduceActionForArray1: 1952769 false) #(37 3 #reduceActionForArray1: 2059265 false)
#(33 2 #reduceActionForMapPair1: 1755137 false) #(33 2 #reduceActionForMapPair1: 1846273 false)
). ).
] ]
@@ -300,7 +300,9 @@ CarpParser >> reduceActionForArray1: nodes [
| result | | result |
result := CarpArrayNode new. result := CarpArrayNode new.
result leftBracket: (nodes at: 1).
result addNodes: (nodes at: 2) to: result expressions. result addNodes: (nodes at: 2) to: result expressions.
result rightBracket: (nodes at: 3).
^ result ^ result
] ]
@@ -318,6 +320,7 @@ CarpParser >> reduceActionForDeref1: nodes [
| result | | result |
result := CarpDerefNode new. result := CarpDerefNode new.
result derefGlyph: (nodes at: 1).
result value: (nodes at: 2). result value: (nodes at: 2).
^ result ^ result
] ]
@@ -344,7 +347,9 @@ CarpParser >> reduceActionForList1: nodes [
| result | | result |
result := CarpListNode new. result := CarpListNode new.
result leftParen: (nodes at: 1).
result addNodes: (nodes at: 2) to: result expressions. result addNodes: (nodes at: 2) to: result expressions.
result rightParen: (nodes at: 3).
^ result ^ result
] ]
@@ -353,7 +358,9 @@ CarpParser >> reduceActionForMap1: nodes [
| result | | result |
result := CarpMapNode new. result := CarpMapNode new.
result leftBrace: (nodes at: 1).
result addNodes: (nodes at: 2) to: result pairs. result addNodes: (nodes at: 2) to: result pairs.
result rightBrace: (nodes at: 3).
^ result ^ result
] ]
@@ -399,6 +406,7 @@ CarpParser >> reduceActionForPattern1: nodes [
| result | | result |
result := CarpPatternNode new. result := CarpPatternNode new.
result patternGlyph: (nodes at: 1).
result value: (nodes at: 2). result value: (nodes at: 2).
^ result ^ result
] ]
@@ -417,6 +425,7 @@ CarpParser >> reduceActionForRef1: nodes [
| result | | result |
result := CarpRefNode new. result := CarpRefNode new.
result refGlyph: (nodes at: 1).
result value: (nodes at: 2). result value: (nodes at: 2).
^ result ^ result
] ]
@@ -426,6 +435,7 @@ CarpParser >> reduceActionForRefCall1: nodes [
| result | | result |
result := CarpRefCallNode new. result := CarpRefCallNode new.
result refGlyph: (nodes at: 1).
result value: (nodes at: 2). result value: (nodes at: 2).
^ result ^ result
] ]
@@ -453,6 +463,7 @@ CarpParser >> reduceActionForUnquote1: nodes [
| result | | result |
result := CarpUnquoteNode new. result := CarpUnquoteNode new.
result unquoteGlyph: (nodes at: 1).
result value: (nodes at: 2). result value: (nodes at: 2).
^ result ^ result
] ]

View File

@@ -2,9 +2,10 @@ Class {
#name : #CarpPatternNode, #name : #CarpPatternNode,
#superclass : #CarpExpressionNode, #superclass : #CarpExpressionNode,
#instVars : [ #instVars : [
'patternGlyph',
'value' 'value'
], ],
#category : #'Carp-AST' #category : #'Carp-Parser'
} }
{ #category : #generated } { #category : #generated }
@@ -13,10 +14,22 @@ CarpPatternNode >> acceptVisitor: anExpressionVisitor [
^ anExpressionVisitor visitPattern: self ^ anExpressionVisitor visitPattern: self
] ]
{ #category : #generated }
CarpPatternNode >> patternGlyph [
^ patternGlyph
]
{ #category : #generated }
CarpPatternNode >> patternGlyph: aSmaCCToken [
patternGlyph := aSmaCCToken
]
{ #category : #generated } { #category : #generated }
CarpPatternNode >> tokenVariables [ CarpPatternNode >> tokenVariables [
^ #( #value ) ^ #( #patternGlyph #value )
] ]
{ #category : #generated } { #category : #generated }

View File

@@ -2,9 +2,10 @@ Class {
#name : #CarpRefCallNode, #name : #CarpRefCallNode,
#superclass : #CarpExpressionNode, #superclass : #CarpExpressionNode,
#instVars : [ #instVars : [
'refGlyph',
'value' 'value'
], ],
#category : #'Carp-AST' #category : #'Carp-Parser'
} }
{ #category : #generated } { #category : #generated }
@@ -19,6 +20,24 @@ CarpRefCallNode >> nodeVariables [
^ #( #value ) ^ #( #value )
] ]
{ #category : #generated }
CarpRefCallNode >> refGlyph [
^ refGlyph
]
{ #category : #generated }
CarpRefCallNode >> refGlyph: aSmaCCToken [
refGlyph := aSmaCCToken
]
{ #category : #generated }
CarpRefCallNode >> tokenVariables [
^ #( #refGlyph )
]
{ #category : #generated } { #category : #generated }
CarpRefCallNode >> value [ CarpRefCallNode >> value [

View File

@@ -2,9 +2,10 @@ Class {
#name : #CarpRefNode, #name : #CarpRefNode,
#superclass : #CarpExpressionNode, #superclass : #CarpExpressionNode,
#instVars : [ #instVars : [
'refGlyph',
'value' 'value'
], ],
#category : #'Carp-AST' #category : #'Carp-Parser'
} }
{ #category : #generated } { #category : #generated }
@@ -19,6 +20,24 @@ CarpRefNode >> nodeVariables [
^ #( #value ) ^ #( #value )
] ]
{ #category : #generated }
CarpRefNode >> refGlyph [
^ refGlyph
]
{ #category : #generated }
CarpRefNode >> refGlyph: aSmaCCToken [
refGlyph := aSmaCCToken
]
{ #category : #generated }
CarpRefNode >> tokenVariables [
^ #( #refGlyph )
]
{ #category : #generated } { #category : #generated }
CarpRefNode >> value [ CarpRefNode >> value [

View File

@@ -2,9 +2,10 @@ Class {
#name : #CarpUnquoteNode, #name : #CarpUnquoteNode,
#superclass : #CarpExpressionNode, #superclass : #CarpExpressionNode,
#instVars : [ #instVars : [
'unquoteGlyph',
'value' 'value'
], ],
#category : #'Carp-AST' #category : #'Carp-Parser'
} }
{ #category : #generated } { #category : #generated }
@@ -13,12 +14,35 @@ CarpUnquoteNode >> acceptVisitor: anExpressionVisitor [
^ anExpressionVisitor visitUnquote: self ^ anExpressionVisitor visitUnquote: self
] ]
{ #category : #accessing }
CarpUnquoteNode >> isQuoted [
^ false
]
{ #category : #generated } { #category : #generated }
CarpUnquoteNode >> nodeVariables [ CarpUnquoteNode >> nodeVariables [
^ #( #value ) ^ #( #value )
] ]
{ #category : #generated }
CarpUnquoteNode >> tokenVariables [
^ #( #unquoteGlyph )
]
{ #category : #generated }
CarpUnquoteNode >> unquoteGlyph [
^ unquoteGlyph
]
{ #category : #generated }
CarpUnquoteNode >> unquoteGlyph: aSmaCCToken [
unquoteGlyph := aSmaCCToken
]
{ #category : #generated } { #category : #generated }
CarpUnquoteNode >> value [ CarpUnquoteNode >> value [

View File

@@ -0,0 +1 @@
Package { #name : #'Carp-Parser' }

View File

@@ -1,11 +0,0 @@
Class {
#name : #CarpExpressionNode,
#superclass : #SmaCCParseNode,
#category : #'Carp-AST'
}
{ #category : #generated }
CarpExpressionNode >> acceptVisitor: anExpressionVisitor [
^ anExpressionVisitor visitExpression: self
]

View File

@@ -0,0 +1,129 @@
Class {
#name : #GtCarpCoderModel,
#superclass : #GtSourceCoder,
#instVars : [
'pharoBindings',
'carpLinkApplicationStrategy'
],
#category : #'Carp-Coder'
}
{ #category : #converting }
GtCarpCoderModel >> asCoderViewModel [
^ GtSourceCoderViewModel new coder: self
]
{ #category : #accessing }
GtCarpCoderModel >> bindAndExecute: sourceString [
"Answer the source code with all declared variables returned in an immediate dictionary"
<gtIgnoreConstraint: #GtRBAcceptVisitorCalledFromNonVisitingMethods>
| carpSource trimmedSource ast varNames lastStatement application commandFactory |
trimmedSource := SmaCCString on: sourceString trimRight.
ast := JSParser parse: trimmedSource.
"The variables to be returned are names that are in pharoBindings"
varNames := pharoBindings bindingNames asSet.
"Assign the final statement to snippetResult"
lastStatement := ast items last.
trimmedSource
insert: '(defdynamic snippetResult '
at: lastStatement startPosition.
varNames add: 'snippetResult'.
"Get the final source to execute"
carpSource := self sourceFrom: trimmedSource asString returnedVarNames: varNames.
application := carpLinkApplicationStrategy applicationServer.
application isRunning ifFalse: [ application start ].
commandFactory := application newCommandFactory.
^ commandFactory
<< carpSource;
sendAndWait.
]
{ #category : #accessing }
GtCarpCoderModel >> carpLinkApplicationStrategy: anApplicationStrategy [
carpLinkApplicationStrategy := anApplicationStrategy
]
{ #category : #accessing }
GtCarpCoderModel >> computeAst: theSourceString [
^ CarpParser
parseWithErrors: theSourceString
]
{ #category : #accessing }
GtCarpCoderModel >> initializeAddOns: addOns [
super initializeAddOns: addOns.
addOns addStyler: (GtCoderAstSmaCCParserStyler new smaccStyler: CarpParser gtStyler).
addOns
addMainAction: 'Evaluate' translated
icon: BrGlamorousVectorIcons play
action: [ :aCoderUIModel :anElement |
GtCoderCodeExecutor doIt
coderViewModel: aCoderUIModel;
element: anElement;
execute ]
id: GtSourceCoderDoItActionId.
addOns
addMainAction: 'Inspect' translated
icon: BrGlamorousVectorIcons playinspect
action: [ :aCoderUIModel :anElement |
GtCoderCodeExecutor doItAndGo
coderViewModel: aCoderUIModel;
element: anElement;
execute ]
id: GtSourceCoderDoItAndGoActionId.
]
{ #category : #accessing }
GtCarpCoderModel >> initializeShortcuts: addOns [
super initializeShortcuts: addOns.
addOns
addShortcut: GtSourceCoderDoItShortcut new;
addShortcut: GtSourceCoderDoItAndInspectShortcut new
]
{ #category : #accessing }
GtCarpCoderModel >> newCompletionStrategy [
^ GtCompletionStrategy new
]
{ #category : #accessing }
GtCarpCoderModel >> pharoBindings: anObject [
pharoBindings := anObject
]
{ #category : #accessing }
GtCarpCoderModel >> sourceFrom: trimmedSourceString returnedVarNames: varNames [
"Answer the modified source to return the declared variables"
^ String streamContents: [ :stream |
stream << trimmedSourceString.
stream
cr
<< '{ '.
varNames do: [ :varName |
stream
<< '(quote ';
<< varName;
<< ') ';
<< varName;
<< ' ' ].
"Answer the variable dictionary as an immediate object"
stream
<< '(quote carpLinkImmediate) true }' ]
]
{ #category : #accessing }
GtCarpCoderModel >> variableBindings: aGtSnippetBindings [
^ self pharoBindings: aGtSnippetBindings
]

View File

@@ -0,0 +1,57 @@
Class {
#name : #LeCarpApplicationStrategy,
#superclass : #LeExternalServerStrategy,
#category : #'Carp-Lepiter'
}
{ #category : #accessing }
LeCarpApplicationStrategy class >> strategyName [
^ #global
]
{ #category : #accessing }
LeCarpApplicationStrategy >> applicationServer [
content database isDatabase ifFalse: [ ^ nil ].
JSLinkApplication uniqueInstance ifNil:
[ JSLinkApplication uniqueInstance: (self newJavaScriptApplicationFor: content database) ].
^ JSLinkApplication uniqueInstance
]
{ #category : #accessing }
LeCarpApplicationStrategy >> applicationSettings [
"Answer the settings that will be used by the server.
This musn't actually start the server as that should be deferred until a snippet is evaluated for the first time."
^ JSLinkApplication isRunning ifTrue:
[ JSLinkApplication uniqueInstance settings ]
ifFalse:
[ self updatedSettings: JSLinkApplication defaultSettings ]
]
{ #category : #accessing }
LeCarpApplicationStrategy >> newJavaScriptApplicationFor: aLeDatabase [
^ JSLinkApplication new initializeWith:
(self updatedSettings: LanguageLinkSettings carpDefaultSettings).
]
{ #category : #accessing }
LeCarpApplicationStrategy >> updatedSettings: applicationCarpSettings [
"Update the supplied settings with the lepiter configuration"
| lepiterCarpSettings lepiterDatabase carpDir |
lepiterDatabase := content database.
lepiterCarpSettings := lepiterDatabase properties carpLinkSettings.
lepiterCarpSettings directory ifNotNil:
[ :relativeDir |
carpDir := lepiterDatabase localStoreRootDirectory resolve: relativeDir.
applicationCarpSettings workingDirectory: carpDir ].
"lepiterCarpSettings carpPath ifNotNil:
[ :carpPath | applicationCarpSettings serverExecutable: carpPath ]."
applicationCarpSettings serverDebugMode: lepiterCarpSettings serverDebugMode.
^ applicationCarpSettings
]

View File

@@ -0,0 +1,42 @@
Class {
#name : #LeCarpSnippet,
#superclass : #LeCodeSnippet,
#category : #'Carp-Lepiter'
}
{ #category : #'api - accessing menu' }
LeCarpSnippet class >> contextMenuItemSpecification [
<leSnippetSpecification>
^ LeContextMenuItemSpecification new
snippetClass: self;
title: 'Carp'
]
{ #category : #'lepiter-store' }
LeCarpSnippet class >> leJsonV3Name [
^ 'carpSnippet'
]
{ #category : #'lepiter-store' }
LeCarpSnippet class >> leJsonV4Name [
^ 'carpSnippet'
]
{ #category : #visiting }
LeCarpSnippet >> acceptVisitor: aVisitor [
^ aVisitor visitCarpSnippet: self
]
{ #category : #converting }
LeCarpSnippet >> asSnippetViewModel [
<return: #LeSnippetViewModel>
^ LeCarpSnippetViewModel new snippetModel: self
]
{ #category : #accessing }
LeCarpSnippet >> newCoder [
^ GtCarpCoderModel new
]

View File

@@ -0,0 +1,36 @@
Class {
#name : #LeCarpSnippetElement,
#superclass : #LeExternalEvaluatedSnippetElement,
#category : #'Carp-Lepiter'
}
{ #category : #accessing }
LeCarpSnippetElement >> onSnippetViewModelChanged [
super onSnippetViewModelChanged.
self updateLanguageLabel.
self coder
carpLinkApplicationStrategy: self serverStrategy;
pharoBindings: self snippetViewModel snippetBindings
]
{ #category : #accessing }
LeCarpSnippetElement >> serverStrategy [
^ serverStrategy ifNil:
[ serverStrategy := LeCarpApplicationStrategy new content: self ].
]
{ #category : #accessing }
LeCarpSnippetElement >> updateLanguageLabel [
| serverAddress label |
serverAddress := self serverStrategy applicationSettings serverSocketAddress.
label := String streamContents: [ :stream |
stream
<< 'Carp @ ';
<< serverAddress ipOrName;
<< ':';
print: serverAddress port ].
languageElement text: (label asRopedText glamorousRegularFont foreground: BrGlamorousColors textMarkupColor).
]

View File

@@ -0,0 +1,29 @@
Class {
#name : #LeCarpSnippetViewModel,
#superclass : #LeCodeSnippetViewModel,
#category : #'Carp-Lepiter'
}
{ #category : #accessing }
LeCarpSnippetViewModel >> initializeCoderAddOns: aCoderViewModel [
"Initialise the keyboard shortcuts in the code editor"
aCoderViewModel
"Create New snippet (after the current snippet)"
addShortcut: (LeSnippetSplitSnippetShortcut new combination: (self keyboardShortcut: #SplitSnippet));
"Delete previous character, or merge with previous snippet"
addShortcut: (LeSnippetDeletePreviousShortcut new combination: (self keyboardShortcut: #DeletePrevious));
"Indent LeSnippet"
addShortcut: (LeSnippetIndentSnippetShortcut new combination: (self keyboardShortcut: #IndentSnippet));
"Unindent LeSnippet"
addShortcut: (LeSnippetUnindentSnippetShortcut new combination: (self keyboardShortcut: #UnindentSnippet));
"Move Snippet up"
addShortcut: (LeSnippetMoveSnippetUpShortcut new combination: (self keyboardShortcut: #MoveSnippetUp));
"Move Snippet down"
addShortcut: (LeSnippetMoveSnippetDownShortcut new combination: (self keyboardShortcut: #MoveSnippetDown))
]
{ #category : #accessing }
LeCarpSnippetViewModel >> snippetElementClass [
^ LeCarpSnippetElement
]

View File

@@ -0,0 +1,13 @@
Extension { #name : #LeRoamJSONExportVisitor }
{ #category : #'*Carp' }
LeRoamJSONExportVisitor >> visitCarpSnippet: aSnippet [
^ String streamContents: [ :aStream |
aStream
<< '```javascript';
cr;
<< aSnippet code;
cr;
<< '```' ]
]

View File

@@ -0,0 +1,6 @@
Extension { #name : #TLeModelVisitor }
{ #category : #'*Carp' }
TLeModelVisitor >> visitCarpSnippet: aSnippet [
^ self visitTextualSnippet: aSnippet
]