Marcel Taeumel uploaded a new version of ShoutCore to project The Trunk:
http://source.squeak.org/trunk/ShoutCore-ct.66.mcz ==================== Summary ==================== Name: ShoutCore-ct.66 Author: ct Time: 21 July 2019, 1:20:54.761477 pm UUID: d881aecc-1ceb-4b4d-a3f6-02ac4e71cbbf Ancestors: ShoutCore-ul.65 Allow context-dependent styling We will be able to use this in ContextVariableInspector =============== Diff against ShoutCore-ul.65 =============== Item was changed: Object subclass: #SHParserST80 + instanceVariableNames: 'classOrMetaClass source workspace arguments sourcePosition currentToken currentTokenFirst temporaries instanceVariables errorBlock currentTokenSourcePosition blockDepth bracketDepth ranges environment allowUnderscoreAssignments allowUnderscoreSelectors parseAMethod context' - instanceVariableNames: 'classOrMetaClass source workspace arguments sourcePosition currentToken currentTokenFirst temporaries instanceVariables errorBlock currentTokenSourcePosition blockDepth bracketDepth ranges environment allowUnderscoreAssignments allowUnderscoreSelectors parseAMethod' classVariableNames: '' poolDictionaries: '' category: 'ShoutCore-Parsing'! !SHParserST80 commentStamp: 'tween 8/16/2004 15:44' prior: 0! I am a Smalltalk method / expression parser. Rather than creating an Abstract Syntax Tree, I create a sequence of SHRanges (in my 'ranges' instance variable), which represent the tokens within the String I am parsing. I am used by a SHTextStylerST80 to parse method source strings. I am able to parse incomplete / incorrect methods, and so can be used to parse methods that are being edited. My 'source' instance variable should be set to the string to be parsed. My 'classOrMetaClass' instance var must be set to the class or metaClass for the method source so that I can correctly resolve identifiers within the source. If this is nil , I parse the source as an expression (i.e. a doIt expression). My 'workspace' instance variable can be set to a Workspace, so that I can resolve workspace variables. My 'environment' instance variable is the global namespace (this is initialized to Smalltalk, but can be set to a different environment). Example 1. ranges := SHParserST80 new classOrMetaClass: Object; source: 'testMethod ^self'; parse; ranges ! Item was changed: ----- Method: SHParserST80>>parse: (in category 'parse') ----- parse: isAMethod "Parse the receiver's text. If isAMethod is true then treat text as a method, if false as an expression with no message pattern" self initializeInstanceVariables. allowUnderscoreAssignments := Scanner allowUnderscoreAsAssignment. allowUnderscoreSelectors := Scanner prefAllowUnderscoreSelectors. sourcePosition := 1. arguments := Dictionary new. temporaries := Dictionary new. blockDepth := bracketDepth := 0. ranges ifNil: [ ranges := OrderedCollection new: 40 "Covers over 80% of all methods." ] ifNotNil: [ ranges reset ]. + context ifNotNil: [ + (context tempNames copyFrom: 1 to: context numArgs) + do: [:arg | self pushArgument: arg]. + (context tempNames allButFirst: context numArgs) + do: [:temp | self pushTemporary: temp]]. errorBlock := [^false]. self scanNext. isAMethod ifTrue: [ self parseMessagePattern; parsePragmaSequence ]. self parseMethodTemporaries. isAMethod ifTrue: [ self parsePragmaSequence ]. self parseStatementList. currentToken ifNotNil: [ self error ]. ^true! Item was changed: ----- Method: SHParserST80>>rangesIn:classOrMetaClass:workspace:environment: (in category 'parse') ----- rangesIn: sourceString classOrMetaClass: aBehaviour workspace: aWorkspace environment: anEnvironmentOrNil + ^ self rangesIn: sourceString classOrMetaClass: aBehaviour workspace: aWorkspace environment: anEnvironmentOrNil context: nil! - anEnvironmentOrNil ifNotNil: [environment := anEnvironmentOrNil]. - self - workspace: aWorkspace; - classOrMetaClass: aBehaviour; - source: sourceString. - self parse. - ^ranges! Item was added: + ----- Method: SHParserST80>>rangesIn:classOrMetaClass:workspace:environment:context: (in category 'parse') ----- + rangesIn: sourceString classOrMetaClass: aBehaviour workspace: aWorkspace environment: anEnvironmentOrNil context: aContextOrNil + anEnvironmentOrNil ifNotNil: [environment := anEnvironmentOrNil]. + aContextOrNil ifNotNil: [context := aContextOrNil]. + self + workspace: aWorkspace; + classOrMetaClass: aBehaviour; + source: sourceString. + self parse. + ^ranges! Item was changed: SHTextStyler subclass: #SHTextStylerST80 + instanceVariableNames: 'classOrMetaClass workspace font parser formatAssignments environment sourceMap processedSourceMap pixelHeight attributesByPixelHeight parseAMethod context' - instanceVariableNames: 'classOrMetaClass workspace font parser formatAssignments environment sourceMap processedSourceMap pixelHeight attributesByPixelHeight parseAMethod' classVariableNames: 'SyntaxHighlightingAsYouType SyntaxHighlightingAsYouTypeAnsiAssignment SyntaxHighlightingAsYouTypeLeftArrowAssignment TextAttributesByPixelHeight' poolDictionaries: '' category: 'ShoutCore-Styling'! !SHTextStylerST80 commentStamp: 'tween 8/27/2004 10:55' prior: 0! I style Smalltalk methods and expressions. My 'styleTable' class instance var holds an array ofArrays which control how each token is styled/coloured. See my defaultStyleTable class method for its structure. My styleTable can be changed by either modifying the defaultStyleTable class method and then executing SHTextStylerST80 initialize ; or by giving me a new styleTable through my #styleTable: class method. My 'textAttributesByPixelSize' class instance var contains a dictionary of dictionaries. The key is a pixelSize and the value a Dictionary from token type Symbol to TextAttribute array. It is created/maintained automatically. I also install these 3 preferences when my class initialize method is executed.... #syntaxHighlightingAsYouType - controls whether methods are styled in browsers #syntaxHighlightingAsYouTypeAnsiAssignment - controls whether assignments are formatted to be := #syntaxHighlightingAsYouTypeLeftArrowAssignment - controls whether assignments are formatted to be _ I reimplement #unstyledTextFrom: so that TextActions are preserved in the unstyled text ! Item was added: + ----- Method: SHTextStylerST80>>context: (in category 'accessing') ----- + context: aContext + context := aContext! Item was changed: ----- Method: SHTextStylerST80>>rangesIn:setWorkspace: (in category 'private') ----- rangesIn: aText setWorkspace: aBoolean "Answer a collection of SHRanges by parsing aText. When formatting it is not necessary to set the workspace, and this can make the parse take less time, so aBoolean specifies whether the parser should be given the workspace" | shoutParserClass | "Switch parsers if we have to" shoutParserClass := (classOrMetaClass ifNil:[Object]) shoutParserClass. parser class == shoutParserClass ifFalse:[parser := shoutParserClass new]. parser parseAMethod: parseAMethod. ^parser rangesIn: aText asString classOrMetaClass: classOrMetaClass workspace: (aBoolean ifTrue:[workspace]) environment: environment + context: context! - ! |
Free forum by Nabble | Edit this page |