Skip to content

Commit

Permalink
replacements: various improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
tom95 committed Sep 21, 2023
1 parent e644791 commit 33b0232
Show file tree
Hide file tree
Showing 15 changed files with 236 additions and 26 deletions.
2 changes: 1 addition & 1 deletion packages/Sandblocks-Javascript/SBJsRegex.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ SBJsRegex >> build [
self
layoutPolicy: SBAlgebraLayout new;
addMorphBack: (self
createBinding: [:c | SBRegex parse: (c at: 'root') contents]
createBinding: [:c | SBRegex parse: (c at: 'root') sourceString]
update: [:c :m | (c at: 'root') contents: m sourceString])
]

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,5 +86,6 @@ SBPyPltPaletteOverview class >> buildOnPlots: aBuilder [

{ #category : #'as yet unclassified' }
SBPyPltPaletteOverview class >> language [
^ #python

^ SBPython
]
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ Class {
{ #category : #matchers }
SBReCharacterClassEscape class >> newEmpty [

^ (SBRegex parseExpression: '\d') childSandblocks first applyReplacement
^ (SBRegex parseExpression: '\d') applyReplacement
]

{ #category : #accessing }
Expand Down
19 changes: 17 additions & 2 deletions packages/Sandblocks-Regex/SBReComment.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -18,21 +18,36 @@ Class {
SBReComment >> build [

self
addMorphBack: (self createBindingBlock: 'pattern');
layoutPolicy: SBAlgebraLayout new;
addMorphBack: (comment := self
createBindingFor: 'annotation'
build: [:annotation |
SBTextBubble multiLine
italic;
placeholderText: 'comment';
contents: annotation]
update: [:c :m | m contents]);
addMorphBack: (SBButton new
makeSmall;
balloonText: 'collapse';
icon: SBIcon iconMinus shortcut: nil do: [self collapseBlock])
icon: SBIcon iconMinus shortcut: nil do: [self collapseBlock]);
addMorphBack: (self createBindingBlock: 'pattern')
]

{ #category : #accessing }
SBReComment >> collapsedContent [

^ comment contents
]

{ #category : #'as yet unclassified' }
SBReComment >> layoutCommands [

^ SBAlgebraCommand container
data: {
self submorphs first layoutCommands.
self submorphs second layoutCommands.
SBAlgebraCommand hardLine.
self submorphs third layoutCommands};
morph: self
]
10 changes: 5 additions & 5 deletions packages/Sandblocks-Regex/SBReEncodedReplacement.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ SBReEncodedReplacement class >> newAround: aBlock [
| regex command |
regex := (SBTSFileParser new
parse: ('(?:(?:{1}:)\{0\}(?:x)) ' format: {self name})
language: SBRegex) childSandblocks first childSandblocks first.
command := SBCombinedCommand newWith: (aBlock owner ifNotNil: {SBReplaceCommand new target: aBlock replacer: regex} ifNil: [{}]), {SBReplaceCommand new target: regex lastDeepChild replacer: aBlock. regex applyReplacementCommand}.
language: SBRegex) childSandblocks first.
command := SBCombinedCommand newWith: (aBlock owner ifNotNil: [{SBReplaceCommand new target: aBlock replacer: regex}] ifNil: [{}]), {SBReplaceCommand new target: regex lastDeepChild replacer: aBlock. regex applyReplacementCommand}.
^ aBlock sandblockEditor
ifNotNil: [aBlock sandblockEditor do: command]
ifNil: [command do]
Expand All @@ -47,17 +47,17 @@ SBReEncodedReplacement class >> subclassForAnnotation: aString [
SBReEncodedReplacement >> build [
<lang: #regex match: '(non_capturing_group
(pattern
(term
.
(non_capturing_group
(pattern) @annotation
)
(count_quantifier) @zero
(non_capturing_group
(pattern) @pattern
)
)
)
) @block' sample: '(?:(?:annotation){0}(?:pattern))'>
) @block' sample: '(?:(?:SBReComment){0}(?:x))'>

^ (self class subclassForAnnotation: (bindings at: 'annotation') sourceString) ifNotNil: [:class |
class new
Expand Down
4 changes: 1 addition & 3 deletions packages/Sandblocks-Regex/SBReOptional.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,9 @@ SBReOptional class >> newEmpty [
{ #category : #initialization }
SBReOptional >> build [
<lang: #regex match: '(optional
"?"
"?"? @lazy
) @optional'>
) @optional' sample: 'a?'>


self
addMorphBack: (SBStringMorph new contents: 'optional');
buildLazyToggle
Expand Down
4 changes: 2 additions & 2 deletions packages/Sandblocks-Regex/SBRePalette.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ SBRePalette class >> groups [
{ #category : #properties }
SBRePalette class >> language [

^ self factory language
^ SBRegex
]

{ #category : #categories }
Expand All @@ -140,7 +140,7 @@ SBRePalette class >> quantifier [
{ #category : #categories }
SBRePalette class >> rules [

^ self factory grammarJsonObject rules keys select: [:type | (SBRegex instance bodyNodeForRule: type ifAbsent: [nil]) notNil]
^ self factory instance grammar rules keys select: [:type | (SBRegex instance grammar bodyNodeForRule: type ifAbsent: [nil]) notNil]
]

{ #category : #categories }
Expand Down
18 changes: 18 additions & 0 deletions packages/Sandblocks-Regex/SBRegex.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,12 @@ Class {
#category : #'Sandblocks-Regex'
}

{ #category : #'as yet unclassified' }
SBRegex class >> gapBetween: aBlock and: anotherBlock [

^ false
]

{ #category : #configuration }
SBRegex class >> grammarJson [
" https://github.com/tree-sitter/tree-sitter-regex/blob/master/grammar.js "
Expand Down Expand Up @@ -772,6 +778,18 @@ SBRegex class >> spaceBetween: aBlock and: anotherBlock lastCharacterOfFirst: aC
^ false
]

{ #category : #'as yet unclassified' }
SBRegex class >> unknownFor: aSymbol [

| morphs |
morphs := (self rule: aSymbol) buildEmpty.
(morphs size = 1 and: [morphs first isUnknown]) ifTrue: [^ morphs anyOne].
^ SBTSBlock new
slot: (SBTSSlot new addNode: (SBTSNodeSymbol new type: aSymbol factory: self instance grammar));
addAllMorphs: morphs;
yourself
]

{ #category : #'as yet unclassified' }
SBRegex class >> validSuffixIputs [

Expand Down
32 changes: 31 additions & 1 deletion packages/Sandblocks-TreeSitter/SBExample2.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,44 @@ SBExample2 >> artefactSaved: aMethodBlock [
(self firstOwnerSuchThat: [:owner | owner isTSBlock and: [owner type = #'function_definition']]) ifNotNil: [:method | | name arguments |
name := (method get: 'name') contents.
arguments := self updateDuring: [(bindings at: 'arguments') sourceString].
SBExecutionEnvironment value: self.
self runtime
evaluate: ('import {1}; {1}.{2}(*{3})' format: {(self containingArtefact file basename splitBy: '.') first. name. arguments})
in: self containingArtefact file parent]]
]

{ #category : #'as yet unclassified' }
SBExample2 >> buildJavaScript [
<lang: #javascript match: '(object (pair key: (string (string_fragment) ="args") (arrow_function (_) @arguments)) (pair key: (string (string_fragment) ="_sb_example") (string (string_fragment) @name)))' sample: '{"_sb_example": "example", "args": () => []}' keyword: 'example'>

self
layoutInset: 8;
layoutPolicy: SBAlgebraLayout new;
listDirection: #leftToRight;
cellPositioning: #center;
vResizing: #shrinkWrap;
hResizing: #shrinkWrap;
minimumWidth: 200 sbScaled;
cellGap: 4 sbScaled.

self
removeAllMorphs;
addMorphBack: (SBIcon iconPause
small;
color: (Color r: 1 g: 1 b: 1);
on: #click send: #toggleRunning to: self);
addMorphBack: (self createBinding: [SBTextBubble new layoutInset: 4 sbScaled] contents: 'name');
addMorphBack: (SBStringMorph new contents: 'args:');
addMorphBack: ((self createBindingBlock: 'arguments')
color: (Color r: 1 g: 1 b: 1);
layoutInset: 4 sbScaled;
hResizing: #shrinkWrap;
wrapCentering: #leftToRight)
]

{ #category : #'as yet unclassified' }
SBExample2 >> buildPython [
<lang: #python match: '(dictionary (pair key: (string) ="args" (lambda (_) @arguments)) (pair key: (string) ="_sb_example" (string) @name))' sample: '{"_sb_example": "example", "args": lambda: []}'>
<lang: #python match: '(dictionary (pair key: (string) ="args" (lambda (_) @arguments)) (pair key: (string) ="_sb_example" (string) @name))' sample: '{"_sb_example": "example", "args": lambda: []}' keyword: 'example'>

self
layoutInset: 8;
Expand Down
8 changes: 7 additions & 1 deletion packages/Sandblocks-TreeSitter/SBTSBlock.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -159,8 +159,14 @@ SBTSBlock >> applyReplacementCommand: aClass [
SBTSBlock >> applyReplacements [
<action>

self applyReplacements: SBTSReplacementBlock allSubclasses
]

{ #category : #'action helpers' }
SBTSBlock >> applyReplacements: aCollection [

| candidates |
candidates := self allReplacementCandidates: SBTSReplacementBlock allSubclasses.
candidates := self allReplacementCandidates: aCollection.
self allBlocksDo: [:block |
(block isTSBlock and: [block isTSReplacement not]) ifTrue: [
self
Expand Down
5 changes: 4 additions & 1 deletion packages/Sandblocks-TreeSitter/SBTSFile.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,10 @@ SBTSFile >> toggleRun [
runCancelBlock := nil]
ifNil: [
((runtime object new
evaluateFileAsync: self filepath
evaluateFileAsync: (SBToggledCode
comment: ''
active: 1
do: {[self filepath]. [(self filepath asFile parent / 'server-build' / 'index.js') asString]})
cancel: [:b | runCancelBlock := b]) then: [:b |
b value: [:status :stdout :stderr |
SBToggledCode comment: '' active: 1 do: {[Transcript showln: {status. stdout. stderr}]}.
Expand Down
13 changes: 12 additions & 1 deletion packages/Sandblocks-TreeSitter/SBToggle.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,20 @@ SBToggle >> buildChild: aBlock [
yourself
]

{ #category : #'as yet unclassified' }
SBToggle >> buildPython [
<lang: #python match: '(call (subscript (list) @array (integer) @index))' sample: '[lambda: __wrap__][0]()' keyword: 'toggle'>

self
createRepeatBindingFor: 'array'
childQuery: '(lambda body: (_) @)'
new: 'lambda: _expr'
build: [:e | self buildChild: e]
]

{ #category : #'as yet unclassified' }
SBToggle >> buildTypeScript [
<lang: #typescript match: '(call_expression (subscript_expression (array) @array (number) @index))' sample: '[() => __wrap__][0]()'>
<lang: #typescript match: '(call_expression (subscript_expression (array) @array (number) @index))' sample: '[() => __wrap__][0]()' keyword: 'toggle'>

self
createRepeatBindingFor: 'array'
Expand Down
14 changes: 14 additions & 0 deletions packages/Sandblocks-TreeSitter/SBVisExample.class.st
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
Class {
#name : #SBVisExample,
#superclass : #SBTSReplacementBlock,
#category : #'Sandblocks-TreeSitter-Replacements'
}

{ #category : #'as yet unclassified' }
SBVisExample >> build [
<lang: #typescript match: '(call_expression (arguments . (expression) @render (string (string_fragment) @color)))' sample: 'visualize(random_points(), "red")' keyword: 'visualize'>

self layoutInset: 4.
self addMorphBack: (self createBindingBlock: 'render').
self addMorphBack: (Morph new color: (self createStatic: [:color | Color fromCSS2String: color] contents: 'color'))
]
32 changes: 32 additions & 0 deletions packages/Sandblocks-Wing/SBWingCallback.class.st
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
Class {
#name : #SBWingCallback,
#superclass : #SBTSReplacementBlock,
#category : #'Sandblocks-Wing'
}

{ #category : #'as yet unclassified' }
SBWingCallback >> build [
<lang: #wing match: '(structured_access_expression
(array_literal .
(_) @expression
(string) ="post"
(string) @route .))' sample: '[httpPost(), "post", "/video"][0]'>

self layoutPolicy: SBAlgebraLayout new.
self layoutInset: 8.
self addMorphBack: (self createBindingBlock: 'expression').
self addMorphBack: (SBRow new
useAlgebraLayout;
addMorphBack: SBIcon iconArrowRight;
addMorphBack: (self createBinding: [SBTextBubble new prefix: 'Callback: '] contents: 'route'))
]

{ #category : #'as yet unclassified' }
SBWingCallback >> layoutCommands [

^ SBAlgebraCommand container
data: (self submorphs
collect: [:s | s layoutCommands]
separatedBy: [SBAlgebraCommand hardLine withGap: true]);
morph: self
]
Loading

0 comments on commit 33b0232

Please sign in to comment.