Skip to content

Commit

Permalink
Use the proper side for the colorizer's scope.
Browse files Browse the repository at this point in the history
  • Loading branch information
rmacnak committed Apr 20, 2024
1 parent 48c6d57 commit dc3296d
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 79 deletions.
20 changes: 10 additions & 10 deletions src/Browsing.ns
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ acceptResponse ^<[:CodeMirrorFragment :Event]> = (
]
)
colorizeSource: s <String> withEditor: cm <CodeMirrorFragment> = (
ide colorizer colorizeHeader: s fromClass: subject classDeclaration via: (colorizingBlockFor: cm)
ide colorizer colorizeHeader: s fromMixin: subject classDeclaration instanceSide via: (colorizingBlockFor: cm)
)
) : (
)
Expand Down Expand Up @@ -534,11 +534,11 @@ editorDefinition ^ <CodeMirrorFragment> = (
cm changeResponse:
[:editor <CodeMirrorFragment> |
| src <String> = editor textBeingAccepted. |
ide colorizer colorizeDoIt: src fromClass: nil via: (colorizingBlockFor: editor)].
ide colorizer colorizeDoIt: src fromMixin: nil via: (colorizingBlockFor: editor)].
cm enterResponse:
[:editor <CodeMirrorFragment> |
respondToEvaluate: false].
ide colorizer colorizeDoIt: initialSource fromClass: nil via: (colorizingBlockFor: cm).
ide colorizer colorizeDoIt: initialSource fromMixin: nil via: (colorizingBlockFor: cm).
^cm
)
evaluate: expression <String> suspended: suspended <Boolean> ^<Fragment> = (
Expand All @@ -562,7 +562,7 @@ respondToEvaluate: suspended <Boolean> = (
| src = editor textBeingAccepted. |
addDiscardIfNeeded.
results addFirst: (evaluate: src suspended: suspended).
ide colorizer colorizeDoIt: src fromClass: nil via: (colorizingBlockFor: editor)
ide colorizer colorizeDoIt: src fromMixin: nil via: (colorizingBlockFor: editor)
)
) : (
)
Expand Down Expand Up @@ -928,7 +928,7 @@ public class MethodGroupSubject onModel: m <MirrorGroup[MethodMirror]> within: d
public colorizeSource: source <String> editor: cm <CodeMirrorFragment> ^ <TextFragment> = (
^ide colorizer
colorizeMethod: source
fromClass: definingMixin declaration
fromMixin: definingMixin
via: (colorizingBlockFor: cm)
)
public compileSource: source <String> ifSuccess: successBlock <[:MethodMirror]> ifFailure: failureBlock <[:String]> = (
Expand Down Expand Up @@ -970,7 +970,7 @@ acceptResponse ^ <[:CodeMirrorFragment :Event]> = (
]
)
colorizeSource: s <String> withEditor: cm <CodeMirrorFragment> = (
ide colorizer colorizeMethod: s fromClass: subject classDeclaration via: (colorizingBlockFor: cm)
ide colorizer colorizeMethod: s fromMixin: subject methodMirror definingMixin via: (colorizingBlockFor: cm)
)
) : (
)
Expand Down Expand Up @@ -1327,7 +1327,7 @@ public classTemplateText ^ <String> = (
public colorizeClassSource: source <String> editor: cm <CodeMirrorFragment> = (
^ide colorizer
colorizeClassDeclaration: source
fromClass: nil
fromMixin: nil
via: (colorizingBlockFor: cm)
)
public createPresenter ^ <NamespacePresenter> = (
Expand Down Expand Up @@ -1424,7 +1424,7 @@ public classTemplateText ^ <String> = (
public colorizeClassSource: source <String> editor: cm <CodeMirrorFragment> = (
^ide colorizer
colorizeClassDeclaration: source
fromClass: definingMixin declaration
fromMixin: definingMixin
via: (colorizingBlockFor: cm)
)
public createPresenter = (
Expand Down Expand Up @@ -1932,7 +1932,7 @@ public class TransientSlotGroupSubject onModel: m <MirrorGroup[TransientSlotMirr
public colorizeSource: source <String> editor: cm <CodeMirrorFragment> ^ <TextFragment> = (
^ide colorizer
colorizeTransientSlot: source
fromClass: definingMixin declaration
fromMixin: definingMixin
via: (colorizingBlockFor: cm)
)
public compileSource: source <String> ifSuccess: successBlock <[:MethodMirror]> ifFailure: failureBlock <[:String]> = (
Expand Down Expand Up @@ -1972,7 +1972,7 @@ acceptResponse ^ <[:CodeMirrorFragment :Event]> = (
]
)
colorizeSource: s <String> withEditor: cm <CodeMirrorFragment> = (
ide colorizer colorizeTransientSlot: s fromClass: subject classDeclaration via: (colorizingBlockFor: cm)
ide colorizer colorizeTransientSlot: s fromMixin: subject transientSlotMirror definingMixin via: (colorizingBlockFor: cm)
)
) : (
)
Expand Down
130 changes: 63 additions & 67 deletions src/NewspeakColorization.ns
Original file line number Diff line number Diff line change
Expand Up @@ -48,20 +48,20 @@ class Range kind: k start: s end: e = (
coloredText ^ <Text> = (
^TextBlock units: textSegments
)
public colorizeClassDeclaration: s <String> fromClass: c <Class> via: cf <[:Range]> = (
setString: s class: c.
public colorizeClassDeclaration: s <String> fromMixin: m <MixinMirror> via: cf <[:Range]> = (
setString: s mixin: m.
colorizeString: s withProduction: classDeclaration via: cf
)
public colorizeDoIt: s <String> fromClass: c <Class> via: cf <[:Range]> = (
setString: s class: c.
public colorizeDoIt: s <String> fromMixin: m <MixinMirror> via: cf <[:Range]> = (
setString: s mixin: m.
colorizeString: s withProduction: doItExpression via: cf
)
public colorizeHeader: s <String> fromClass: c <Class> via: cf <[:Range]> = (
setString: s class: c.
public colorizeHeader: s <String> fromMixin: m <MixinMirror> via: cf <[:Range]> = (
setString: s mixin: m.
colorizeString: s withProduction: classHeader via: cf
)
public colorizeMethod: s <String> fromClass: c <Class> via: cf <[:Range]> = (
setString: s class: c.
public colorizeMethod: s <String> fromMixin: m <MixinMirror> via: cf <[:Range]> = (
setString: s mixin: m.
colorizeString: s withProduction: methodDecl via: cf
)
colorizeString: s <String> withProduction: parser <CombinatorialParser> via: cf <[:Range]> = (
Expand All @@ -71,8 +71,8 @@ colorizeString: s <String> withProduction: parser <CombinatorialParser> via: cf
consolidateRanges.
rangeArray do: [:r | nil = r ifFalse: [cf value: r]].
)
public colorizeTransientSlot: s <String> fromClass: c <Class> via: cf <[:Range]> = (
setString: s class: c.
public colorizeTransientSlot: s <String> fromMixin: m <MixinMirror> via: cf <[:Range]> = (
setString: s mixin: m.
colorizeString: s withProduction: transientSlotDecl via: cf
)
computePropertiesMap ^ <Map[Symbol, TextProperties]> = (
Expand Down Expand Up @@ -225,47 +225,32 @@ consolidateRangesAt: index <Integer> = (
noteRange: kind <Symbol> from: start <Integer> to: end <Integer> = (
rangeMap add: (Range kind: kind start: (start max: 1) end: end).
)
public parseClassDecl: s <String> fromClass: c <Class> ^<Text> = (
(* Questionable*)
| parser |

setString: s class: c.
public parseClassDecl: s <String> fromMixin: m <MixinMirror> ^<Text> = (
setString: s mixin: m.
^parseString: s withProduction: classDecl
)
public parseClassDeclaration: s <String> fromClass: c <Class> ^<Text> = (
| parser |

setString: s class: c.
public parseClassDeclaration: s <String> fromMixin: m <MixinMirror> ^<Text> = (
setString: s mixin: m.
^parseString: s withProduction: classDeclaration
)
public parseClassHeader: s <String> fromClass: c <Class> ^<Text> = (
| parser |

setString: s class: c.
public parseClassHeader: s <String> fromMixin: m <MixinMirror> ^<Text> = (
setString: s mixin: m.
^parseString: s withProduction: classHeader
)
public parseCodeBody: s <String> fromClass: c <Class> ^<Text> = (
| parser |

setString: s class: c.
public parseCodeBody: s <String> fromMixin: m <MixinMirror> ^<Text> = (
setString: s mixin: m.
^parseString: s withProduction: codeBody
)
public parseDoIt: s <String> fromClass: c <Class> ^<Text> = (
| parser |

setString: s class: c.
public parseDoIt: s <String> fromMixin: m <MixinMirror> ^<Text> = (
setString: s mixin: m.
^parseString: s withProduction: doItExpression
)
public parseMethod: s <String> fromClass: c <Class> ^ <Text> = (
| parser |

setString: s class: c.
public parseMethod: s <String> fromMixin: m <MixinMirror> ^<Text> = (
setString: s mixin: m.
^parseString: s withProduction: methodDecl
)
public parseSlotDeclaration: s <String> fromClass: c <Class> ^<Text> = (
| parser |

setString: s class: c.
public parseSlotDeclaration: s <String> fromMixin: m <MixinMirror> ^<Text> = (
setString: s mixin: m.
^parseString: s withProduction: slotDef, eoi
)
parseString: s <String> withProduction: parser <CombinatorialParser> ^ <Text> = (
Expand All @@ -276,17 +261,18 @@ parseString: s <String> withProduction: parser <CombinatorialParser> ^ <Text> =
computeTextSegments.
^coloredText
)
setString: s <String> class: c <ClassDeclarationMirror | Mixin> = (
inputSize:: s size.
inputString:: s.
klass:: c.
bracketDepth:: 0.
braceDepth:: 0.
parenDepth:: 0.
setString: s <String> mixin: m <MixinMirror> = (
inputSize:: s size.
inputString:: s.
mixin:: m.
bracketDepth:: 0.
braceDepth:: 0.
parenDepth:: 0.
rangeMap:: List new.
textSegments:: List new.
priorSegmentEnd:: 1.
cachedScopeStack: nil.)
textSegments:: List new.
priorSegmentEnd:: 1.
cachedScopeStack: nil.
)
) : (
)
(*
Expand All @@ -299,7 +285,7 @@ It might be better to produce an actual AST (or a subset thereof) and visit it i
class NS3Colorizer = TypedNS3Grammar (
|
cachedScopeStack
klass
mixin <MixinMirror>
rangeMap <List[Range]>
inputSize <Integer>
startComment
Expand Down Expand Up @@ -392,15 +378,6 @@ checkKeyword: kwd <Token> = (
(inputString at: kwd end + 1) <= 32 ifTrue: [^self].
self noteRange: #whitespaceWarning from: kwd start to: kwd end
)
classDeclaration: classDecl canUnderstand: selector = (
(classDecl instanceSide methods includesMirrorNamed: selector)
ifTrue: [^true].
(classDecl instanceSide nestedClasses includesMirrorNamed: selector)
ifTrue: [^true].
(classDecl instanceSide slots includesMirrorNamed: selector)
ifTrue: [^true].
^false
)
public classHeader = (
^super classHeader
wrap:
Expand Down Expand Up @@ -452,15 +429,14 @@ endComment = (
^(TokenizingParser withSubparser: super endComment) wrap:
[:t | rangeMap removeLast. t].
)
extendedCanUnderstand: sel <Symbol> = (
| k <ClassDeclarationMirror> |
k: klass.
[nil = k] whileFalse:
[(classDeclaration: k canUnderstand: sel) ifTrue: [^true].
k: k enclosingClass].
extendedCanUnderstand: selector <String> ^<Boolean> = (
| m <MixinMirror> ::= mixin. |
[nil = m] whileFalse:
[(mixin: m canUnderstand: selector) ifTrue: [^true].
m:: m enclosingMixin].

(* klass mixin applications do: [:any | ^any canUnderstand: sel].*)
^classDeclaration: mixinMirrorForObject declaration canUnderstand: sel
^mixin: mixinMirrorForObject canUnderstand: selector
)
increaseBraceLevel = (
self braceDepth: (self braceDepth + 1) \\ 7.
Expand Down Expand Up @@ -544,6 +520,25 @@ method = (
self popScope.
^res
)
mixin: mixin <MixinMirror> canUnderstand: selector <String> ^<Boolean> = (
(mixin methods includesMirrorNamed: selector)
ifTrue: [^true].

(mixin nestedClasses includesMirrorNamed: selector)
ifTrue: [^true].

mixin slots do:
[:slot |
slot name = selector ifTrue: [^true].
slot isMutable ifTrue: [slot name, ':' = selector ifTrue: [^true]]].

mixin transientSlots do:
[:slot |
slot name = selector ifTrue: [^true].
slot isMutable ifTrue: [slot name, ':' = selector ifTrue: [^true]]].

^false
)
nestedClassDecl = (
^super nestedClassDecl wrap:
[:tokens | (* accessModifier opt, classDeclaration*)
Expand Down Expand Up @@ -656,7 +651,8 @@ string = (
)
symbol: aString <String> ifInScope: inScopeAction ifNotInScope: notInScopeAction ifObsolete: obsoleteAction = (
scopeStack do: [:s | (s includesKey: aString) ifTrue: [^inScopeAction value]].
^inScopeAction value (* BOGUS *)
(extendedCanUnderstand: aString) ifTrue: [^inScopeAction value].
^notInScopeAction value
)
symbolConstant = (
^super symbolConstant wrapper:
Expand Down
4 changes: 2 additions & 2 deletions src/NewspeakColorizationTesting.ns
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ public class NS3BrowserColorizerTests = TestContext (|
private colorizer = NS3BrowserColorizer new.
|) (
public testParseDoIt = (
assert: (colorizer parseDoIt: '| foo' fromClass: nil) isKindOfTextBlock.
assert: (colorizer parseDoIt: '| foo' fromClass: nil) isKindOfTextBlock.
assert: (colorizer parseDoIt: '| foo' fromMixin: nil) isKindOfTextBlock.
assert: (colorizer parseDoIt: '| foo' fromMixin: nil) isKindOfTextBlock.
)
) : (
TEST_CONTEXT = ()
Expand Down

0 comments on commit dc3296d

Please sign in to comment.