From 96813dfec1ee468c580618ffbe42fe54a9a71499 Mon Sep 17 00:00:00 2001 From: "Brian T. Rice" Date: Wed, 22 Dec 2010 01:37:32 -0800 Subject: [PATCH] Renamed "Writer" types to "PrintStream" and appropriate variations. --- src/lib/xml.slate | 36 +++++++------- src/syntax/writer.slate | 102 +++++++++++++++++++-------------------- src/unfinished/objc/writer.slate | 4 +- src/web/cgi.slate | 4 +- src/web/xml.slate | 32 ++++++------ 5 files changed, 89 insertions(+), 89 deletions(-) diff --git a/src/lib/xml.slate b/src/lib/xml.slate index 409e0ea..c5e5b46 100644 --- a/src/lib/xml.slate +++ b/src/lib/xml.slate @@ -72,7 +72,7 @@ n@(XML Node traits) tagsNamed: name ifReceiverOrChildDo: block n@(XML Node traits) printOn: stream "This is for normal printing compatibility." [ - n printXMLOn: (XML Writer newOn: stream) + n printXMLOn: (XML PrintStream newOn: stream) ]. n@(XML Node traits) printXMLOn: _ @@ -104,7 +104,7 @@ d@(XML Document traits) printXMLOn: writer d@(XML Document traits) printCanonicalOn: stream [| writer | - writer := XML Writer on: stream. + writer := XML PrintStream on: stream. writer canonical := True. d printXMLOn: writer ]. @@ -209,7 +209,7 @@ XML define: #ProcessingInstruction &parents: {XML Node} &slots: pi@(XML ProcessingInstruction traits) newForTarget: name data: string [pi clone `setting: #{#target. #data} to: {name. string}]. -"printXMLOn: defined after XML Writer is defined." +"printXMLOn: defined after XML PrintStream is defined." XML define: #StringNode &parents: {XML Node} &slots: {#string -> ''}. @@ -235,13 +235,13 @@ sn@(XML StringNode traits) printXMLOn: writer $\' -> '''. $\" -> '"'}. -XML define: #Writer &parents: {Cloneable} +XML define: #PrintStream &parents: {Cloneable} &slots: {#stack -> Stack new. #stream. #scanner. #canonical -> False}. -w@(XML Writer traits) newOn: stream +w@(XML PrintStream traits) newOn: stream [w clone `setting: #{#stack. #stream} to: {w stack new. stream}]. -w@(XML Writer traits) attribute: name value: value +w@(XML PrintStream traits) attribute: name value: value [ w stream ; ' ' ; name printString ; '="'. w pcData: value. @@ -249,32 +249,32 @@ w@(XML Writer traits) attribute: name value: value w ]. -w@(XML Writer traits) cdata: string +w@(XML PrintStream traits) cdata: string [ w stream ; '' ]. -w@(XML Writer traits) pcData: c +w@(XML PrintStream traits) pcData: c [ w stream ; (XML Translation at: c ifAbsent: [c as: String]) ]. -w@(XML Writer traits) comment: string +w@(XML PrintStream traits) comment: string [ w stream ; '' ]. -pi@(XML ProcessingInstruction traits) printXMLOn: w@(XML Writer traits) +pi@(XML ProcessingInstruction traits) printXMLOn: w@(XML PrintStream traits) [ w stream ; '' ]. -w@(XML Writer traits) pushTag: name +w@(XML PrintStream traits) pushTag: name [ w stack push: name ]. -w@(XML Writer traits) popTag: name +w@(XML PrintStream traits) popTag: name [| top | top := w stack isEmpty ifTrue: [''] @@ -284,20 +284,20 @@ w@(XML Writer traits) popTag: name ifFalse: [w error: 'Closing tag ' ; name ; ' doesn\'t match ' ; top] ]. -w@(XML Writer traits) startTag: name +w@(XML PrintStream traits) startTag: name [ w stream ; '<' ; name. "w canonical ifTrue: [w stream ; ' ']." w pushTag: name ]. -w@(XML Writer traits) endTag +w@(XML PrintStream traits) endTag [ w stream nextPut: $>. w ]. -w@(XML Writer traits) endTag: name +w@(XML PrintStream traits) endTag: name [ w popTag: name. w stream ; ''. @@ -313,7 +313,7 @@ w@(XML Writer traits) endEmptyTag: name w ]. -w@(XML Writer traits) startElement: name attributes: attribs +w@(XML PrintStream traits) startElement: name attributes: attribs [ w canonical ifFalse: [w stream nextPut: $\r]. w startTag: name. @@ -322,7 +322,7 @@ w@(XML Writer traits) startElement: name attributes: attribs w ]. -w@(XML Writer traits) xmlDeclaration: versionString +w@(XML PrintStream traits) xmlDeclaration: versionString [ w canonical ifFalse: [ w stream ; ' ' '. +IndentedPrintStream traits define: #indentString -> ' '. -w@(Writer traits) print: node +w@(IndentedPrintStream traits) print: node "The basic printing method to specialize on the target syntax object." [overrideThis]. -w@(Writer traits) indentedDo: block surroundedBy: str1 and: str2 +w@(IndentedPrintStream traits) indentedDo: block surroundedBy: str1 and: str2 [ w newLine. w ; str1. @@ -21,7 +21,7 @@ w@(Writer traits) indentedDo: block surroundedBy: str1 and: str2 w ; str2. ]. -define: #SourceWriter &parents: {Writer} &slots: { +define: #SourcePrintStream &parents: {IndentedPrintStream} &slots: { #printComments -> False. "Whether comments are added to the source. The default is not to." #useApplyWith -> False. @@ -34,7 +34,7 @@ define: #SourceWriter &parents: {Writer} &slots: { }. "This visitor is a dispatch point for these methods and may be overridden." -w@(SourceWriter traits) print: node@(nodes Node traits) +w@(SourcePrintStream traits) print: node@(nodes Node traits) "All printable nodes need to override this method." [ overrideThis @@ -43,15 +43,15 @@ w@(SourceWriter traits) print: node@(nodes Node traits) x@(nodes Node traits) printOn: o "Specialize printOn: for syntax nodes" [ - (SourceWriter newOn: o) print: x. + (SourcePrintStream newOn: o) print: x. o ]. -w@(SourceWriter traits) print: _@(nodes ImplicitArgument traits) +w@(SourcePrintStream traits) print: _@(nodes ImplicitArgument traits) "The target of implicit message sends to the context. Prints nothing." []. -w@(SourceWriter traits) print: node@(nodes Comment traits) +w@(SourcePrintStream traits) print: node@(nodes Comment traits) "(Optionally) print out the comment on the following line." [ w print: node value. @@ -61,7 +61,7 @@ w@(SourceWriter traits) print: node@(nodes Comment traits) w ]. -"w@(SourceWriter traits) print: node inParenthesesOn: s +"w@(SourcePrintStream traits) print: node inParenthesesOn: s [ s ; '('. w print: node on: s. @@ -70,19 +70,19 @@ w@(SourceWriter traits) print: node@(nodes Comment traits) ]. " -w@(SourceWriter traits) print: node@(nodes Literal traits) +w@(SourcePrintStream traits) print: node@(nodes Literal traits) [w ; node value printString. ]. -w@(SourceWriter traits) printSelectorPrefixOf: _ +w@(SourcePrintStream traits) printSelectorPrefixOf: _ []. -w@(SourceWriter traits) printSelectorPrefixOf: _@(nodes Macro traits) +w@(SourcePrintStream traits) printSelectorPrefixOf: _@(nodes Macro traits) [w ; '`'. ]. -w@(SourceWriter traits) printSelectorPrefixOf: _@(nodes Deferred traits) +w@(SourcePrintStream traits) printSelectorPrefixOf: _@(nodes Deferred traits) [w ; '%'. ]. -w@(SourceWriter traits) withSurroundingArity: arity do: block +w@(SourcePrintStream traits) withSurroundingArity: arity do: block [| previousArity | previousArity := w surroundingArity. w surroundingArity := arity. @@ -90,7 +90,7 @@ w@(SourceWriter traits) withSurroundingArity: arity do: block w surroundingArity := previousArity. ]. -w@(SourceWriter traits) print: node sending: selector to: args +w@(SourcePrintStream traits) print: node sending: selector to: args "Accepts a method name and array of arguments, and print the appropriate source on the stream." [| previousArity closeParen | @@ -136,21 +136,21 @@ source on the stream." w ]. -w@(SourceWriter traits) print: node@(nodes StoreVariable traits) +w@(SourcePrintStream traits) print: node@(nodes StoreVariable traits) [ w print: node sending: (node variable name name ; ':') intern to: {nodes ImplicitArgument. node value} ]. -w@(SourceWriter traits) print: node@(nodes LoadVariable traits) +w@(SourcePrintStream traits) print: node@(nodes LoadVariable traits) [ w print: node sending: node variable name to: {nodes ImplicitArgument} ]. -w@(SourceWriter traits) print: node@(nodes Variable traits) +w@(SourcePrintStream traits) print: node@(nodes Variable traits) [shouldNotImplement]. -w@(SourceWriter traits) print: node@(nodes Message traits) +w@(SourcePrintStream traits) print: node@(nodes Message traits) [ w useApplyWith ifTrue: [w ; '(' ; node selector printString ; ' applyWith: ' @@ -159,12 +159,12 @@ w@(SourceWriter traits) print: node@(nodes Message traits) w ]. -w@(SourceWriter traits) print: node@(nodes MessageWrapper traits) +w@(SourcePrintStream traits) print: node@(nodes MessageWrapper traits) [ w print: node message ]. -w@(SourceWriter traits) print: node@(nodes OptionalKeywords traits) +w@(SourcePrintStream traits) print: node@(nodes OptionalKeywords traits) [| closeParen | closeParen := False. w surroundingArity >= 0 ifTrue: [w ; '('. closeParen := True]. @@ -182,7 +182,7 @@ w@(SourceWriter traits) print: node@(nodes OptionalKeywords traits) w ]. -w@(SourceWriter traits) print: node@(nodes RestArguments traits) +w@(SourcePrintStream traits) print: node@(nodes RestArguments traits) [| closeParen | closeParen := False. w surroundingArity >= 0 ifTrue: [w ; '('. closeParen := True]. @@ -199,27 +199,27 @@ w@(SourceWriter traits) print: node@(nodes RestArguments traits) w ]. -w@(SourceWriter traits) print: node@(nodes Placeholder traits) +w@(SourcePrintStream traits) print: node@(nodes Placeholder traits) [ w ; '_' ]. -w@(SourceWriter traits) print: node@(nodes Pattern traits) +w@(SourcePrintStream traits) print: node@(nodes Pattern traits) [ w ; '#('. resend. w ; ')' ]. -w@(SourceWriter traits) isDefaultLastStatement: node +w@(SourcePrintStream traits) isDefaultLastStatement: node "Whether the expression would be a default value for the last statement in a sequence - only True for Literal Nil." [False]. -w@(SourceWriter traits) isDefaultLastStatement: node@(nodes Literal traits) +w@(SourcePrintStream traits) isDefaultLastStatement: node@(nodes Literal traits) [node value isNil]. -w@(SourceWriter traits) printStatements: statements &separatedBy: separator +w@(SourcePrintStream traits) printStatements: statements &separatedBy: separator [ separator `defaultsTo: [w newLine]. w withSurroundingArity: -1 do: @@ -232,12 +232,12 @@ w@(SourceWriter traits) printStatements: statements &separatedBy: separator w ]. -w@(SourceWriter traits) printAsRole: node +w@(SourcePrintStream traits) printAsRole: node [ w withSurroundingArity: 0 do: [w print: node]. ]. -w@(SourceWriter traits) print: node@(nodes CompoundStatement traits) +w@(SourcePrintStream traits) print: node@(nodes CompoundStatement traits) [ w indentedDo: [w newLine. @@ -246,7 +246,7 @@ w@(SourceWriter traits) print: node@(nodes CompoundStatement traits) w ]. -w@(SourceWriter traits) print: node@(nodes Array traits) +w@(SourcePrintStream traits) print: node@(nodes Array traits) [ w ; '{'. resend. @@ -254,7 +254,7 @@ w@(SourceWriter traits) print: node@(nodes Array traits) w ]. -w@(SourceWriter traits) print: node@(nodes Parenthesis traits) +w@(SourcePrintStream traits) print: node@(nodes Parenthesis traits) [ w ; '('. w printStatements: node statements. @@ -262,7 +262,7 @@ w@(SourceWriter traits) print: node@(nodes Parenthesis traits) w ]. -w@(SourceWriter traits) printVariablesOf: node@(nodes Block traits) &skipInputs: skipInputs +w@(SourcePrintStream traits) printVariablesOf: node@(nodes Block traits) &skipInputs: skipInputs [ skipInputs `defaultsTo: False. (skipInputs not /\ [node inputVariables size > 0]) \/ @@ -284,7 +284,7 @@ w@(SourceWriter traits) printVariablesOf: node@(nodes Block traits) &skipInputs: w ; ' | ']. ]. -w@(SourceWriter traits) print: node@(nodes Block traits) +w@(SourcePrintStream traits) print: node@(nodes Block traits) [ w ; '['. w printVariablesOf: node. @@ -292,12 +292,12 @@ w@(SourceWriter traits) print: node@(nodes Block traits) w ; ']'. ]. -w@(SourceWriter traits) printAsStatement: node +w@(SourcePrintStream traits) printAsStatement: node [ w print: node ]. -w@(SourceWriter traits) printArg: arg withRole: role +w@(SourcePrintStream traits) printArg: arg withRole: role [ w ; (arg name as: String). (role is: nodes Literal) /\ [role value == NoRole] ifFalse: @@ -305,7 +305,7 @@ w@(SourceWriter traits) printArg: arg withRole: role w printAsRole: role] ]. -w@(SourceWriter traits) print: node@(nodes Signature traits) +w@(SourcePrintStream traits) print: node@(nodes Signature traits) "Accepts a method name and array of arguments, and print the appropriate source on the stream." [| args selector | @@ -346,14 +346,14 @@ source on the stream." w ; variable name]]. ]. -w@(SourceWriter traits) printSignatureOf: node@(nodes MethodDefinition traits) +w@(SourcePrintStream traits) printSignatureOf: node@(nodes MethodDefinition traits) "Accepts a method name and array of arguments, and print the appropriate source on the stream." [ w print: (node as: nodes Signature) ]. -w@(SourceWriter traits) printAsMethodBody: node@(nodes Block traits) +w@(SourcePrintStream traits) printAsMethodBody: node@(nodes Block traits) [ w newLine. w ; '['. @@ -365,26 +365,26 @@ w@(SourceWriter traits) printAsMethodBody: node@(nodes Block traits) w ; ']'. ]. -w@(SourceWriter traits) print: node@(nodes MethodDefinition traits) +w@(SourcePrintStream traits) print: node@(nodes MethodDefinition traits) [ w newLine. w printSignatureOf: node. w printAsMethodBody: node. ]. -w@(SourceWriter traits) print: node@(nodes Return traits) +w@(SourcePrintStream traits) print: node@(nodes Return traits) [ w ; node selector ; ' '. w withSurroundingArity: 2 do: [w print: node value]. ]. -w@(SourceWriter traits) print: _@(nodes Resend traits) +w@(SourcePrintStream traits) print: _@(nodes Resend traits) [ w ; 'resend'. ]. -w@(SourceWriter traits) treatAsSimpleNode: node +w@(SourcePrintStream traits) treatAsSimpleNode: node [| nodeCount | nodeCount := 0. node walk: [| :each | (nodeCount += 1) > 7 ifTrue: [^ False]]. @@ -392,20 +392,20 @@ w@(SourceWriter traits) treatAsSimpleNode: node ]. " -w@(SourceWriter traits) treatAsSimpleNode: node@(nodes CompoundStatement traits) +w@(SourcePrintStream traits) treatAsSimpleNode: node@(nodes CompoundStatement traits) [ node statements size <= 1 ]. " -w@(SourceWriter traits) printAsArgument: node +w@(SourcePrintStream traits) printAsArgument: node "Print the node as an argument and return wether something was printed at all" [ w print: node. True ]. -w@(SourceWriter traits) printAsArgument: def@(nodes MethodDefinition traits) +w@(SourcePrintStream traits) printAsArgument: def@(nodes MethodDefinition traits) [ w surroundingArity isNegative ifFalse: [w ; '(']. @@ -415,10 +415,10 @@ w@(SourceWriter traits) printAsArgument: def@(nodes MethodDefinition traits) True ]. -w@(SourceWriter traits) printAsArgument: _@(nodes ImplicitArgument traits) +w@(SourcePrintStream traits) printAsArgument: _@(nodes ImplicitArgument traits) [False]. -w@(SourceWriter traits) printAsArgument: node@(nodes CompoundStatement traits) +w@(SourcePrintStream traits) printAsArgument: node@(nodes CompoundStatement traits) [ w indentedDo: [w newLine. @@ -426,7 +426,7 @@ w@(SourceWriter traits) printAsArgument: node@(nodes CompoundStatement traits) True ]. -w@(SourceWriter traits) printAsArgument: node@(nodes Parenthesis traits) +w@(SourcePrintStream traits) printAsArgument: node@(nodes Parenthesis traits) [ w ; '('. w indentedDo: @@ -435,7 +435,7 @@ w@(SourceWriter traits) printAsArgument: node@(nodes Parenthesis traits) True ]. -w@(SourceWriter traits) printAsArgument: node@(nodes Block traits) +w@(SourcePrintStream traits) printAsArgument: node@(nodes Block traits) [ (w treatAsSimpleNode: node) ifTrue: @@ -448,7 +448,7 @@ w@(SourceWriter traits) printAsArgument: node@(nodes Block traits) True ]. -w@(SourceWriter traits) printAsArgument: node@(nodes Array traits) +w@(SourcePrintStream traits) printAsArgument: node@(nodes Array traits) [ (w treatAsSimpleNode: node) ifTrue: diff --git a/src/unfinished/objc/writer.slate b/src/unfinished/objc/writer.slate index ecfc049..9c444a0 100644 --- a/src/unfinished/objc/writer.slate +++ b/src/unfinished/objc/writer.slate @@ -1,7 +1,7 @@ -ObjC define: #Writer &parents: {C Writer}. +ObjC define: #PrintStream &parents: {C PrintStream}. "Writes out ObjC code." -w@(ObjC Writer traits) print: msg@(ObjC Message traits) +w@(ObjC PrintStream traits) print: msg@(ObjC Message traits) [ w nextPut: $[. selector isUnarySelector ifTrue: diff --git a/src/web/cgi.slate b/src/web/cgi.slate index 7952c72..599479a 100644 --- a/src/web/cgi.slate +++ b/src/web/cgi.slate @@ -1,9 +1,9 @@ -"CGI define: #Writer &parents: {Parsing BasicParser} &slots: {#rootElement}." +"CGI define: #PrintStream &parents: {Parsing BasicParser} &slots: {#rootElement}." lobby define: #CGI &parents: {Cloneable} &slots: {#variables -> Dictionary new. #out -> Console writer. - #xhtml -> Xml XHTMLWriter. + #xhtml -> Xml XHTMLPrintStream. #postValues -> Dictionary new. #getValues -> Dictionary new. }. diff --git a/src/web/xml.slate b/src/web/xml.slate index 9db0c78..e51d996 100644 --- a/src/web/xml.slate +++ b/src/web/xml.slate @@ -365,19 +365,19 @@ p@(Xml Parser traits) parseDocument p parse ]. -Xml define: #Writer &parents: {Stream WrapperStream} &slots: {#tagStack -> Stack new}. +Xml define: #PrintStream &parents: {Stream WrapperStream} &slots: {#tagStack -> Stack new}. -w@(Xml Writer traits) on: outputStream +w@(Xml PrintStream traits) on: outputStream [ resend `>> [tagStack := w tagStack new. ] ]. -w@(Xml Writer traits) emitAttribute: key valued: value +w@(Xml PrintStream traits) emitAttribute: key valued: value [ w original ; ' ' ; key ; '=' ; '\"' ; (w encodeAttribute: value) ; '\"'. ]. -w@(Xml Writer traits) inTag: tagName do: block &attributes: attributes +w@(Xml PrintStream traits) inTag: tagName do: block &attributes: attributes [ attributes `defaultsTo: #{}. w original ; '<' ; tagName. @@ -389,7 +389,7 @@ w@(Xml Writer traits) inTag: tagName do: block &attributes: attributes w tagStack pop. ]. -w@(Xml Writer traits) emitTag: tagName &attributes: attributes +w@(Xml PrintStream traits) emitTag: tagName &attributes: attributes [ attributes `defaultsTo: #{}. w original ; '<' ; tagName. @@ -397,12 +397,12 @@ w@(Xml Writer traits) emitTag: tagName &attributes: attributes w original ; ' />'. ]. -w@(Xml Writer traits) inTag: tagName print: string +w@(Xml PrintStream traits) inTag: tagName print: string [ w inTag: tagName do: [|:w| w nextPutAll: string] ]. -w@(Xml Writer traits) encode: char@(String Character traits) +w@(Xml PrintStream traits) encode: char@(String Character traits) "TODO use generic entity code instead" [ char caseOf: { @@ -416,19 +416,19 @@ w@(Xml Writer traits) encode: char@(String Character traits) } ]. -w@(Xml Writer traits) nextPutAll: c +w@(Xml PrintStream traits) nextPutAll: c "Write the whole String, translating each character." [ c do: [| :char | w nextPut: char] ]. -w@(Xml Writer traits) nextPut: char +w@(Xml PrintStream traits) nextPut: char [ (w encode: char) ifNil: [resend] ifNotNilDo: [| :encoded | w original ; encoded. w] ]. -w@(Xml Writer traits) encodeAttribute: attrib +w@(Xml PrintStream traits) encodeAttribute: attrib [ [| :result | attrib do: @@ -438,24 +438,24 @@ w@(Xml Writer traits) encodeAttribute: attrib ] writingAs: attrib ]. -w@(Xml Writer traits) emitHeader +w@(Xml PrintStream traits) emitHeader [ w original ; '\n'. ]. -w@(Xml Writer traits) writeCharacterData: cdata +w@(Xml PrintStream traits) writeCharacterData: cdata [ "fixme ensure cdata doesn't contain terminator" w original ; ''. ]. -Xml define: #XHTMLWriter &parents: {Xml Writer}. +Xml define: #XHTMLPrintStream &parents: {Xml PrintStream}. -w@(Xml XHTMLWriter traits) emitHeader +w@(Xml XHTMLPrintStream traits) emitHeader [ w original ; '\n'. ]. -w@(Xml XHTMLWriter traits) inDocumentDo: block &head: head &attributes: attrib +w@(Xml XHTMLPrintStream traits) inDocumentDo: block &head: head &attributes: attrib [ w emitHeader. w inTag: 'html' do: @@ -468,7 +468,7 @@ w@(Xml XHTMLWriter traits) inDocumentDo: block &head: head &attributes: attrib ] &attributes: attrib. ]. -w@(Xml XHTMLWriter traits) didNotUnderstand: message at: position +w@(Xml XHTMLPrintStream traits) didNotUnderstand: message at: position [ position isPositive ifTrue: [resend] -- 2.11.4.GIT