diff --git a/lepiter/98eic2k973nz738qf6nsxvl1o.bak b/lepiter/98eic2k973nz738qf6nsxvl1o.bak index 88bd036..4b977ca 100644 --- a/lepiter/98eic2k973nz738qf6nsxvl1o.bak +++ b/lepiter/98eic2k973nz738qf6nsxvl1o.bak @@ -103,14 +103,14 @@ "__type" : "time", "time" : { "__type" : "dateAndTime", - "dateAndTimeString" : "2022-04-17T19:36:14.725535+02:00" + "dateAndTimeString" : "2022-06-13T22:57:31.662829+02:00" } }, "uid" : { "__type" : "uid", "uidString" : "yC3J0D6ZDQCd0ZgmDqn2mw==" }, - "code" : "'Example' asCarpModule\r\taddExpression: (CarpStaticFunction\r\t\t\t named: 'example' asCarpSymbol\r\t\t\t withArguments: { \r\t\t\t\t\t 'x' asCarpSymbol.\r\t\t\t\t\t 'y' asCarpSymbol }\r\t\t\t andBody: (CarpCall function: '+' asCarpSymbol arguments: { \r\t\t\t\t\t\t\t 'x' asCarpSymbol.\r\t\t\t\t\t\t\t 'y' asCarpSymbol }));\r\taddExpression: (CarpDynamicVariable\r\t\t\t named: 'dyn-example' asCarpSymbol\r\t\t\t binding: 1 asCarpInteger);\r\ttoCarp" + "code" : "'Example' asCarpModule\r\taddExpression: (CarpStaticFunction\r\t\t\t named: 'example' asCarpSymbol\r\t\t\t withArguments: { \r\t\t\t\t\t 'x' asCarpSymbol.\r\t\t\t\t\t 'y' asCarpSymbol }\r\t\t\t andBody: {}'+' asCarpSymbol arguments: { \r\t\t\t\t\t\t\t 'x' asCarpSymbol.\r\t\t\t\t\t\t\t 'y' asCarpSymbol }));\r\taddExpression: (CarpDynamicVariable\r\t\t\t named: 'dyn-example' asCarpSymbol\r\t\t\t binding: 1 asCarpInteger);\r\ttoCarp" }, { "__type" : "textSnippet", @@ -248,7 +248,7 @@ "__type" : "time", "time" : { "__type" : "dateAndTime", - "dateAndTimeString" : "2022-04-17T19:40:10.759445+02:00" + "dateAndTimeString" : "2022-04-17T19:40:21.249005+02:00" } }, "uid" : { @@ -258,7 +258,7 @@ "paragraphStyle" : { "__type" : "textStyle" }, - "string" : "In the next chapter, we will use this code generator in our newly created coder" + "string" : "In the next chapter named [[A coder of one’s own]], we will use this code generator in our newly created coder." } ] }, diff --git a/lepiter/98eic2k973nz738qf6nsxvl1o.lepiter b/lepiter/98eic2k973nz738qf6nsxvl1o.lepiter index b9063eb..0123098 100644 --- a/lepiter/98eic2k973nz738qf6nsxvl1o.lepiter +++ b/lepiter/98eic2k973nz738qf6nsxvl1o.lepiter @@ -103,14 +103,14 @@ "__type" : "time", "time" : { "__type" : "dateAndTime", - "dateAndTimeString" : "2022-04-17T19:36:14.725535+02:00" + "dateAndTimeString" : "2022-06-13T22:57:42.883096+02:00" } }, "uid" : { "__type" : "uid", "uidString" : "yC3J0D6ZDQCd0ZgmDqn2mw==" }, - "code" : "'Example' asCarpModule\r\taddExpression: (CarpStaticFunction\r\t\t\t named: 'example' asCarpSymbol\r\t\t\t withArguments: { \r\t\t\t\t\t 'x' asCarpSymbol.\r\t\t\t\t\t 'y' asCarpSymbol }\r\t\t\t andBody: (CarpCall function: '+' asCarpSymbol arguments: { \r\t\t\t\t\t\t\t 'x' asCarpSymbol.\r\t\t\t\t\t\t\t 'y' asCarpSymbol }));\r\taddExpression: (CarpDynamicVariable\r\t\t\t named: 'dyn-example' asCarpSymbol\r\t\t\t binding: 1 asCarpInteger);\r\ttoCarp" + "code" : "'Example' asCarpModule\r\taddExpression: (CarpStaticFunction\r\t\t\t named: 'example' asCarpSymbol\r\t\t\t withArguments: { \r\t\t\t\t\t 'x' asCarpSymbol.\r\t\t\t\t\t 'y' asCarpSymbol }\r\t\t\t andBody: {'+' asCarpSymbol .\r\t\t\t\t\t\t\t 'x' asCarpSymbol.\r\t\t\t\t\t\t\t 'y' asCarpSymbol } asCarpCall);\r\taddExpression: (CarpDynamicVariable\r\t\t\t named: 'dyn-example' asCarpSymbol\r\t\t\t binding: 1 asCarpInteger);\r\ttoCarp" }, { "__type" : "textSnippet", diff --git a/src/Carp-AST/CarpCharacterNode.class.st b/src/Carp-AST/CarpCharacterNode.class.st index a3ee3cf..899a1d4 100644 --- a/src/Carp-AST/CarpCharacterNode.class.st +++ b/src/Carp-AST/CarpCharacterNode.class.st @@ -13,6 +13,11 @@ CarpCharacterNode >> acceptVisitor: anExpressionVisitor [ ^ anExpressionVisitor visitCharacter: self ] +{ #category : #accessing } +CarpCharacterNode >> intoModel [ + ^ CarpCharacter character: self value source asCharacter +] + { #category : #accessing } CarpCharacterNode >> toPharo [ ^ value source asCharacter diff --git a/src/Carp-AST/CarpNumberNode.class.st b/src/Carp-AST/CarpNumberNode.class.st index d19feb6..daf11f7 100644 --- a/src/Carp-AST/CarpNumberNode.class.st +++ b/src/Carp-AST/CarpNumberNode.class.st @@ -13,6 +13,11 @@ CarpNumberNode >> acceptVisitor: anExpressionVisitor [ ^ anExpressionVisitor visitNumber: self ] +{ #category : #accessing } +CarpNumberNode >> intoModel [ + ^ CarpDouble number: self value source asNumber +] + { #category : #accessing } CarpNumberNode >> toPharo [ ^ value source asInteger diff --git a/src/Carp-AST/CarpStartNode.class.st b/src/Carp-AST/CarpStartNode.class.st index 642c2e7..73ceaa0 100644 --- a/src/Carp-AST/CarpStartNode.class.st +++ b/src/Carp-AST/CarpStartNode.class.st @@ -39,6 +39,12 @@ CarpStartNode >> initialize [ expressions := OrderedCollection new: 2. ] +{ #category : #accessing } +CarpStartNode >> intoModel [ + self assert: self expressions size = 1. + ^ self expressions first intoModel +] + { #category : #accessing } CarpStartNode >> toPharo [ ^ expressions collect: #toPharo diff --git a/src/Carp-AST/CarpStringNode.class.st b/src/Carp-AST/CarpStringNode.class.st index 10565d2..53b8f67 100644 --- a/src/Carp-AST/CarpStringNode.class.st +++ b/src/Carp-AST/CarpStringNode.class.st @@ -13,6 +13,11 @@ CarpStringNode >> acceptVisitor: anExpressionVisitor [ ^ anExpressionVisitor visitString: self ] +{ #category : #accessing } +CarpStringNode >> intoModel [ + ^ CarpStringExpression contents: self value source +] + { #category : #accessing } CarpStringNode >> toPharo [ ^ value source diff --git a/src/Carp-AST/CarpVariableNode.class.st b/src/Carp-AST/CarpVariableNode.class.st index c1a9e75..1c232b4 100644 --- a/src/Carp-AST/CarpVariableNode.class.st +++ b/src/Carp-AST/CarpVariableNode.class.st @@ -13,6 +13,11 @@ CarpVariableNode >> acceptVisitor: anExpressionVisitor [ ^ anExpressionVisitor visitVariable: self ] +{ #category : #accessing } +CarpVariableNode >> intoModel [ + ^ CarpSymbol named: self value source +] + { #category : #accessing } CarpVariableNode >> isDefinitionPredicate [ ^ {'defdynamic'. diff --git a/src/Carp-Parser/CarpArrayNode.class.st b/src/Carp-Parser/CarpArrayNode.class.st index 3a0c70e..bc987c9 100644 --- a/src/Carp-Parser/CarpArrayNode.class.st +++ b/src/Carp-Parser/CarpArrayNode.class.st @@ -41,6 +41,11 @@ CarpArrayNode >> initialize [ expressions := OrderedCollection new: 2. ] +{ #category : #accessing } +CarpArrayNode >> intoModel [ + ^ CarpArray contents: (expressions collect: #intoModel) +] + { #category : #generated } CarpArrayNode >> leftBracket [ diff --git a/src/Carp-Parser/CarpDerefNode.class.st b/src/Carp-Parser/CarpDerefNode.class.st index 8863b41..2da6b07 100644 --- a/src/Carp-Parser/CarpDerefNode.class.st +++ b/src/Carp-Parser/CarpDerefNode.class.st @@ -26,6 +26,11 @@ CarpDerefNode >> derefGlyph: aSmaCCToken [ derefGlyph := aSmaCCToken ] +{ #category : #accessing } +CarpDerefNode >> intoModel [ + ^ CarpCall function: 'deref' arguments: {value intoModel} +] + { #category : #generated } CarpDerefNode >> nodeVariables [ diff --git a/src/Carp-Parser/CarpListNode.class.st b/src/Carp-Parser/CarpListNode.class.st index 2b9affa..74eb256 100644 --- a/src/Carp-Parser/CarpListNode.class.st +++ b/src/Carp-Parser/CarpListNode.class.st @@ -49,6 +49,12 @@ CarpListNode >> initialize [ expressions := OrderedCollection new: 2. ] +{ #category : #accessing } +CarpListNode >> intoModel [ + ^ CarpList + contents: (expressions collect: #intoModel) +] + { #category : #accessing } CarpListNode >> isDefinition [ ^ self definitionVariable isNotNil diff --git a/src/Carp-Parser/CarpMapNode.class.st b/src/Carp-Parser/CarpMapNode.class.st index abc2215..4244cb0 100644 --- a/src/Carp-Parser/CarpMapNode.class.st +++ b/src/Carp-Parser/CarpMapNode.class.st @@ -27,6 +27,15 @@ CarpMapNode >> initialize [ pairs := OrderedCollection new: 2. ] +{ #category : #accessing } +CarpMapNode >> intoModel [ + ^ CarpMap + contents: (pairs + flatCollect: [ :p | + {p key intoModel. + p value intoModel} ]) +] + { #category : #generated } CarpMapNode >> leftBrace [ diff --git a/src/Carp-Parser/CarpModuleOrTypeNode.class.st b/src/Carp-Parser/CarpModuleOrTypeNode.class.st index c94420d..1f4624f 100644 --- a/src/Carp-Parser/CarpModuleOrTypeNode.class.st +++ b/src/Carp-Parser/CarpModuleOrTypeNode.class.st @@ -14,6 +14,14 @@ CarpModuleOrTypeNode >> acceptVisitor: anExpressionVisitor [ ^ anExpressionVisitor visitModuleOrType: self ] +{ #category : #accessing } +CarpModuleOrTypeNode >> intoModel [ + ^ CarpSymbol + named: ('.' + join: {module source. + value source}) +] + { #category : #generated } CarpModuleOrTypeNode >> module [ diff --git a/src/Carp-Parser/CarpRefCallNode.class.st b/src/Carp-Parser/CarpRefCallNode.class.st index f51a624..423d1f5 100644 --- a/src/Carp-Parser/CarpRefCallNode.class.st +++ b/src/Carp-Parser/CarpRefCallNode.class.st @@ -14,6 +14,11 @@ CarpRefCallNode >> acceptVisitor: anExpressionVisitor [ ^ anExpressionVisitor visitRefCall: self ] +{ #category : #accessing } +CarpRefCallNode >> intoModel [ + ^ CarpCall function: '~' arguments: {value intoModel} +] + { #category : #generated } CarpRefCallNode >> nodeVariables [ diff --git a/src/Carp-Parser/CarpRefNode.class.st b/src/Carp-Parser/CarpRefNode.class.st index 02a0fa7..8ad6eb3 100644 --- a/src/Carp-Parser/CarpRefNode.class.st +++ b/src/Carp-Parser/CarpRefNode.class.st @@ -14,6 +14,11 @@ CarpRefNode >> acceptVisitor: anExpressionVisitor [ ^ anExpressionVisitor visitRef: self ] +{ #category : #accessing } +CarpRefNode >> intoModel [ + ^ CarpCall function: 'ref' arguments: {value intoModel} +] + { #category : #generated } CarpRefNode >> nodeVariables [ diff --git a/src/Carp-Parser/CarpUnquoteNode.class.st b/src/Carp-Parser/CarpUnquoteNode.class.st index 8336eb5..1056f34 100644 --- a/src/Carp-Parser/CarpUnquoteNode.class.st +++ b/src/Carp-Parser/CarpUnquoteNode.class.st @@ -14,6 +14,11 @@ CarpUnquoteNode >> acceptVisitor: anExpressionVisitor [ ^ anExpressionVisitor visitUnquote: self ] +{ #category : #accessing } +CarpUnquoteNode >> intoModel [ + ^ CarpCall function: 'unquote' arguments: {value intoModel} +] + { #category : #accessing } CarpUnquoteNode >> isQuoted [ ^ false diff --git a/src/Carp/CarpArray.class.st b/src/Carp/CarpArray.class.st new file mode 100644 index 0000000..402d8f2 --- /dev/null +++ b/src/Carp/CarpArray.class.st @@ -0,0 +1,15 @@ +Class { + #name : #CarpArray, + #superclass : #CarpSequence, + #category : #'Carp-IDE' +} + +{ #category : #accessing } +CarpArray >> close [ + ^ ']' +] + +{ #category : #accessing } +CarpArray >> open [ + ^ '[' +] diff --git a/src/Carp/CarpCharacter.class.st b/src/Carp/CarpCharacter.class.st new file mode 100644 index 0000000..a571fb5 --- /dev/null +++ b/src/Carp/CarpCharacter.class.st @@ -0,0 +1,28 @@ +Class { + #name : #CarpCharacter, + #superclass : #CarpLiteral, + #instVars : [ + 'character' + ], + #category : #'Carp-IDE' +} + +{ #category : #'instance creation' } +CarpCharacter class >> character: aCharacter [ + ^ self new character: aCharacter +] + +{ #category : #accessing } +CarpCharacter >> character [ + ^ character +] + +{ #category : #accessing } +CarpCharacter >> character: aCharacter [ + character := aCharacter +] + +{ #category : #accessing } +CarpCharacter >> toCarp [ + ^ '\', self character +] diff --git a/src/Carp/CarpDouble.class.st b/src/Carp/CarpDouble.class.st index 2c43a20..9ef63fa 100644 --- a/src/Carp/CarpDouble.class.st +++ b/src/Carp/CarpDouble.class.st @@ -3,3 +3,8 @@ Class { #superclass : #CarpNumber, #category : #'Carp-IDE' } + +{ #category : #accessing } +CarpDouble >> suffix [ + ^ '' +] diff --git a/src/Carp/CarpExpression.class.st b/src/Carp/CarpExpression.class.st index 38f62d8..887f0a5 100644 --- a/src/Carp/CarpExpression.class.st +++ b/src/Carp/CarpExpression.class.st @@ -12,6 +12,13 @@ CarpExpression >> asElement [ ^ (GtCarpCoderModel code: self toCarp) asElement ] +{ #category : #accessing } +CarpExpression >> asElementWithModule: aModule [ + ^ ((GtCarpIDECoderModel code: self toCarp) + module: aModule; + expression: self) asElement +] + { #category : #accessing } CarpExpression >> documentation [ ^ documentation ifNil: [''] @@ -22,6 +29,24 @@ CarpExpression >> documentation: aString [ documentation := aString ] +{ #category : #accessing } +CarpExpression >> gtCoderFor: aView [ + + ^ aView explicit + title: 'Code'; + priority: 1; + stencil: [ self asElement ] +] + +{ #category : #accessing } +CarpExpression >> gtTextFor: aView [ + + ^ aView textEditor + title: 'String'; + priority: 2; + text: [ self toCarp ] +] + { #category : #converting } CarpExpression >> toCarp [ ^ self subclassResponsibility diff --git a/src/Carp/CarpList.class.st b/src/Carp/CarpList.class.st new file mode 100644 index 0000000..0abb70e --- /dev/null +++ b/src/Carp/CarpList.class.st @@ -0,0 +1,15 @@ +Class { + #name : #CarpList, + #superclass : #CarpSequence, + #category : #'Carp-IDE' +} + +{ #category : #accessing } +CarpList >> close [ + ^ ')' +] + +{ #category : #accessing } +CarpList >> open [ + ^ '(' +] diff --git a/src/Carp/CarpMap.class.st b/src/Carp/CarpMap.class.st new file mode 100644 index 0000000..ab9e897 --- /dev/null +++ b/src/Carp/CarpMap.class.st @@ -0,0 +1,15 @@ +Class { + #name : #CarpMap, + #superclass : #CarpSequence, + #category : #'Carp-IDE' +} + +{ #category : #accessing } +CarpMap >> close [ + ^ '}' +] + +{ #category : #accessing } +CarpMap >> open [ + ^ '{' +] diff --git a/src/Carp/CarpModule.class.st b/src/Carp/CarpModule.class.st index 3faf188..12418ba 100644 --- a/src/Carp/CarpModule.class.st +++ b/src/Carp/CarpModule.class.st @@ -67,8 +67,7 @@ CarpModule >> carpCoderCommentsFor: aView [ { #category : #coders } CarpModule >> carpCoderStreamingMethodsFor: aView context: aPhlowContext [ - | aMethodsCoder aMethodsCoderViewModel aNewMethodCoderHolder | - + | aMethodsCoder aMethodsCoderViewModel aNewMethodCoderHolder coderElement | aNewMethodCoderHolder := ValueHolder new. ^ aView explicit @@ -76,46 +75,35 @@ CarpModule >> carpCoderStreamingMethodsFor: aView context: aPhlowContext [ title: 'Methods'; disableAsync; actionDropdownButtonDo: [ :aDrodownAction | - aDrodownAction dropdown + aDrodownAction dropdown icon: BrGlamorousVectorIcons add; - tooltip: 'Add new expression'; - content: [ :aButton | + tooltip: 'Add new function'; + content: [ :aButton | | aNewMethodCoder aNewMethodCoderViewModel aHandler | - aNewMethodCoderHolder contents - ifNotNil: [ :aContents | - aNewMethodCoderViewModel := aContents ] - ifNil: [ - - aNewMethodCoder := GtCarpCoderModel new. + ifNotNil: [ :aContents | aNewMethodCoderViewModel := aContents ] + ifNil: [ aNewMethodCoder := GtCarpNewFunctionCoderModel new + module: self; + onSave: [ aButton fireEvent: BrDropdownHideWish new. + coderElement initializeForModule ]. - aNewMethodCoderViewModel := aNewMethodCoder asCoderViewModel. - aNewMethodCoderViewModel - withoutHeader; - expanded: true; - focused: true; - moveCursorAtEnd. - - aNewMethodCoderHolder contents: aNewMethodCoderViewModel. + aNewMethodCoderViewModel := aNewMethodCoder asCoderViewModel. + aNewMethodCoderViewModel + withoutHeader; + expanded: true; + focused: true; + moveCursorAtEnd. - aHandler := GtPharoNewMethodCodeSavedHandler new - methodsCoderViewModel: aMethodsCoderViewModel; - element: aButton; - methodCoderHolder: aNewMethodCoderHolder. - - aNewMethodCoderViewModel weak - when: GtMethodCoderSaved - send: #onAnnouncement: - to: aHandler ]. + aNewMethodCoderHolder contents: aNewMethodCoderViewModel ]. - (GtExpandedOnlyCoderElement new coderViewModel: aNewMethodCoderViewModel) - hExact: 300; - vFitContent; - background: Color white; - padding: (BlInsets all: 5); - addAptitude: BrGlamorousFocusableShadowAptitude new ]; - name: #'button--add-new-expression']; - stencil: [ CarpStreamingMethodsCoderElement forModule: self ] + (GtExpandedOnlyCoderElement new coderViewModel: aNewMethodCoderViewModel) + hExact: 300; + vFitContent; + background: Color white; + padding: (BlInsets all: 5); + addAptitude: BrGlamorousFocusableShadowAptitude new ]; + name: #'button--add-new-expression' ]; + stencil: [ coderElement := CarpStreamingMethodsCoderElement forModule: self ] ] { #category : #coders } @@ -194,6 +182,11 @@ CarpModule >> name: aString [ name := aString ] +{ #category : #accessing } +CarpModule >> removeExpression: anExpression [ + expressions remove: anExpression +] + { #category : #accessing } CarpModule >> removeUse: aString [ uses remove: aString diff --git a/src/Carp/CarpModuleCoder.class.st b/src/Carp/CarpModuleCoder.class.st index d7c52ab..210ed9e 100644 --- a/src/Carp/CarpModuleCoder.class.st +++ b/src/Carp/CarpModuleCoder.class.st @@ -19,6 +19,15 @@ CarpModuleCoder >> asCoderViewModel [ ^ CarpModuleCoderViewModel new coder: self ] +{ #category : #accessing } +CarpModuleCoder >> coderName [ + "Return a short textual name of the coder. + For example, class coder would return a class name, package coder returns a package name." + + + ^ self module name +] + { #category : #'instance creation' } CarpModuleCoder >> module [ ^ module diff --git a/src/Carp/CarpNamedFunction.class.st b/src/Carp/CarpNamedFunction.class.st index b7ab2b0..f069348 100644 --- a/src/Carp/CarpNamedFunction.class.st +++ b/src/Carp/CarpNamedFunction.class.st @@ -49,5 +49,5 @@ CarpNamedFunction >> toCarp [ aStream << '(' << self bindingName << ' ' << self name toCarp << ' ['. arguments do: [ :anArgument | aStream << anArgument toCarp << ' ' ]. - aStream << '] ' << self body toCarp << ')' ] + aStream ensureNoSpace << '] ' << self body toCarp << ')' ] ] diff --git a/src/Carp/CarpPattern.class.st b/src/Carp/CarpPattern.class.st new file mode 100644 index 0000000..8af2c0e --- /dev/null +++ b/src/Carp/CarpPattern.class.st @@ -0,0 +1,10 @@ +Class { + #name : #CarpPattern, + #superclass : #CarpStringExpression, + #category : #'Carp-IDE' +} + +{ #category : #accessing } +CarpPattern >> toCarp [ + ^ '#', super toCarp +] diff --git a/src/Carp/CarpSequence.class.st b/src/Carp/CarpSequence.class.st new file mode 100644 index 0000000..ba9b097 --- /dev/null +++ b/src/Carp/CarpSequence.class.st @@ -0,0 +1,38 @@ +Class { + #name : #CarpSequence, + #superclass : #CarpLiteral, + #instVars : [ + 'elements', + 'contents' + ], + #category : #'Carp-IDE' +} + +{ #category : #'instance creation' } +CarpSequence class >> contents: aCollection [ + ^ self new contents: aCollection +] + +{ #category : #accessing } +CarpSequence >> close [ + ^ self subclassResponsibility +] + +{ #category : #accessing } +CarpSequence >> contents: aCollection [ + contents := aCollection +] + +{ #category : #accessing } +CarpSequence >> open [ + ^ self subclassResponsibility +] + +{ #category : #accessing } +CarpSequence >> toCarp [ + + ^ String streamContents: [ :aStream | + aStream << self open. + contents do: [ :anArgument | aStream << anArgument toCarp << ' ' ]. + aStream ensureNoSpace << self close] +] diff --git a/src/Carp/CarpStreamingMethodsCoderElement.class.st b/src/Carp/CarpStreamingMethodsCoderElement.class.st index 67e5433..0bf0d48 100644 --- a/src/Carp/CarpStreamingMethodsCoderElement.class.st +++ b/src/Carp/CarpStreamingMethodsCoderElement.class.st @@ -26,7 +26,7 @@ CarpStreamingMethodsCoderElement >> initialize [ itemType: [ :anItemTypeFactory :anItemObject | anItemObject ]; itemStencil: [ :anItem | - anItem asElement id: GtSourceCoderId ]; + (anItem asElementWithModule: module) id: GtSourceCoderId ]; itemsProvider: (BrListStreamItemsProvider new stream: AsyncEmptyStream new). diff --git a/src/Carp/GtCarpCoderModel.class.st b/src/Carp/GtCarpCoderModel.class.st index 5ce05fe..cc8af58 100644 --- a/src/Carp/GtCarpCoderModel.class.st +++ b/src/Carp/GtCarpCoderModel.class.st @@ -33,7 +33,9 @@ GtCarpCoderModel >> bindAndExecute: sourceString [ | res trimmedSource ast varNames lastStatement carpSource | trimmedSource := SmaCCString on: sourceString trimRight. ast := CarpParser parse: trimmedSource. "The variables to be returned are names that are in pharoBindings" - varNames := pharoBindings bindingNames asSet. "Assign the final statement to snippetResult" + varNames := pharoBindings + ifNil: [ Set new ] + ifNotNil: [ pharoBindings bindingNames asSet ]. "Assign the final statement to snippetResult" lastStatement := ast expressions last. trimmedSource insert: '(defdynamic snippetResult ' @@ -46,10 +48,10 @@ GtCarpCoderModel >> bindAndExecute: sourceString [ res := self bindAndExecuteRaw: sourceString. (res at: #result) = 'success' ifTrue: [ ^ CarpExecutionResult from: res ]. - exception := (PharoLinkRemoteError new - application: application; - command: commandFactory command; - trace: (res at: #value)). + exception := PharoLinkRemoteError new + application: application; + command: commandFactory command; + trace: (res at: #value). exception signal ] @@ -87,56 +89,58 @@ GtCarpCoderModel >> 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. - addOns - addMainAction: 'Expand Macros' translated - icon: BrGlamorousVectorIcons repair - action: [ :aCoderUIModel :anElement | - | source | - source := '(expand ''' , sourceCode currentSourceText value text , ')'. - anElement phlow - spawnObject: ((self bindAndExecute: source) parse view: #gtSourceFor:) ] - id: #'source-coder--macro-expand-action'. - addOns - addMainAction: 'Build and Run' translated - icon: BrGlamorousVectorIcons refresh - action: [ :aCoderUIModel :anElement | - | source | - source := '' , sourceCode currentSourceText value text , '(build) (run)'. - anElement phlow - spawnObject: (CarpCliOutput text: ((self bindAndExecuteRaw: source) at: 'value')) ] - id: #'source-coder--build-and-run-action'. - addOns - addMainAction: 'Infer Type' translated - icon: BrGlamorousVectorIcons inspect - action: [ :aCoderUIModel :anElement | self inspectTypeSpawningOn: anElement phlow] - id: #'source-coder--type-infer-action' + application + ifNotNil: [ 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. + addOns + addMainAction: 'Expand Macros' translated + icon: BrGlamorousVectorIcons repair + action: [ :aCoderUIModel :anElement | + | source | + source := '(expand ''' , sourceCode currentSourceText value text , ')'. + anElement phlow + spawnObject: ((self bindAndExecute: source) parse view: #gtSourceFor:) ] + id: #'source-coder--macro-expand-action'. + addOns + addMainAction: 'Build and Run' translated + icon: BrGlamorousVectorIcons refresh + action: [ :aCoderUIModel :anElement | + | source | + source := '' , sourceCode currentSourceText value text , '(build) (run)'. + anElement phlow + spawnObject: (CarpCliOutput text: ((self bindAndExecuteRaw: source) at: 'value')) ] + id: #'source-coder--build-and-run-action'. + addOns + addMainAction: 'Infer Type' translated + icon: BrGlamorousVectorIcons inspect + action: [ :aCoderUIModel :anElement | self inspectTypeSpawningOn: anElement phlow ] + id: #'source-coder--type-infer-action' ] ] { #category : #accessing } GtCarpCoderModel >> initializeShortcuts: addOns [ super initializeShortcuts: addOns. - addOns - addShortcut: GtSourceCoderDoItShortcut new; - addShortcut: GtSourceCoderDoItAndInspectShortcut new + application + ifNotNil: [ addOns + addShortcut: GtSourceCoderDoItShortcut new; + addShortcut: GtSourceCoderDoItAndInspectShortcut new ] ] { #category : #accessing } diff --git a/src/Carp/GtCarpIDECoderModel.class.st b/src/Carp/GtCarpIDECoderModel.class.st new file mode 100644 index 0000000..9339bbe --- /dev/null +++ b/src/Carp/GtCarpIDECoderModel.class.st @@ -0,0 +1,42 @@ +Class { + #name : #GtCarpIDECoderModel, + #superclass : #GtCarpNewFunctionCoderModel, + #instVars : [ + 'expression' + ], + #category : #'Carp-Coder' +} + +{ #category : #accessing } +GtCarpIDECoderModel >> expression [ + ^ expression +] + +{ #category : #accessing } +GtCarpIDECoderModel >> expression: anExpression [ + expression := anExpression +] + +{ #category : #accessing } +GtCarpIDECoderModel >> initializeAddOns: addOns [ + super initializeAddOns: addOns. + + addOns + addMainAction: 'Remove' translated + icon: BrGlamorousVectorIcons remove + action: [ :aCoderUIModel :anElement | self remove ] + id: GtMethodCoderSaveActionId +] + +{ #category : #accessing } +GtCarpIDECoderModel >> remove [ + ^ module removeExpression: self expression +] + +{ #category : #accessing } +GtCarpIDECoderModel >> save [ + module removeExpression: expression. + module + addExpression: (CarpParser parse: sourceCode availableSource text) intoModel. + onSave ifNotNil: [ onSave value ] +] diff --git a/src/Carp/GtCarpNewFunctionCoderModel.class.st b/src/Carp/GtCarpNewFunctionCoderModel.class.st new file mode 100644 index 0000000..a22abbb --- /dev/null +++ b/src/Carp/GtCarpNewFunctionCoderModel.class.st @@ -0,0 +1,37 @@ +Class { + #name : #GtCarpNewFunctionCoderModel, + #superclass : #GtCarpCoderModel, + #instVars : [ + 'module', + 'onSave' + ], + #category : #'Carp-Coder' +} + +{ #category : #accessing } +GtCarpNewFunctionCoderModel >> initializeAddOns: addOns [ + super initializeAddOns: addOns. + + addOns + addMainAction: 'Save' translated + icon: BrGlamorousVectorIcons accept + action: [ :aCoderUIModel :anElement | + self save ] + id: GtMethodCoderSaveActionId. +] + +{ #category : #coders } +GtCarpNewFunctionCoderModel >> module: aModule [ + module := aModule +] + +{ #category : #accessing } +GtCarpNewFunctionCoderModel >> onSave: aBlock [ + onSave := aBlock +] + +{ #category : #accessing } +GtCarpNewFunctionCoderModel >> save [ + module addExpression: (CarpParser parse: sourceCode currentSourceText value text) intoModel. + onSave ifNotNil: [ onSave value ] +] diff --git a/src/Carp/ByteString.extension.st b/src/Carp/String.extension.st similarity index 54% rename from src/Carp/ByteString.extension.st rename to src/Carp/String.extension.st index 79c61dd..bdeb2be 100644 --- a/src/Carp/ByteString.extension.st +++ b/src/Carp/String.extension.st @@ -1,11 +1,11 @@ -Extension { #name : #ByteString } +Extension { #name : #String } { #category : #'*Carp' } -ByteString >> asCarpModule [ +String >> asCarpModule [ ^ CarpModule named: self ] { #category : #'*Carp' } -ByteString >> asCarpSymbol [ +String >> asCarpSymbol [ ^ CarpSymbol named: self ]