Class: RubyLexer::KeepWsTokenPrinter
- Inherits:
-
Object
- Object
- RubyLexer::KeepWsTokenPrinter
- Defined in:
- lib/rubylexer/tokenprinter.rb
Overview
Constant Summary collapse
- ACCUMSIZE =
50
Instance Attribute Summary collapse
-
#inws ⇒ Object
,:latestline.
-
#lastfal ⇒ Object
,:latestline.
-
#lasttok ⇒ Object
,:latestline.
-
#showzw ⇒ Object
readonly
Returns the value of attribute showzw.
Instance Method Summary collapse
- #aprint(tok) ⇒ Object (also: #sprint)
-
#initialize(sep = '', line = 1, showzw = 0) ⇒ KeepWsTokenPrinter
constructor
A new instance of KeepWsTokenPrinter.
- #lastfal_every_10_lines ⇒ Object
- #pprint(tok, output = $stdout) ⇒ Object
-
#ws_would_change_meaning?(tok, lasttok) ⇒ Boolean
insert extra ws unless an ambiguous op immediately follows id or num, in which case ws would change the meaning.
Constructor Details
#initialize(sep = '', line = 1, showzw = 0) ⇒ KeepWsTokenPrinter
Returns a new instance of KeepWsTokenPrinter.
110 111 112 113 114 115 116 117 118 |
# File 'lib/rubylexer/tokenprinter.rb', line 110 def initialize(sep='',line=1,showzw=0) @sep=sep @inws=false @lasttok='' #@latestline=line @lastprintline=0 @accum=[] @showzw=showzw end |
Instance Attribute Details
#inws ⇒ Object
,:latestline
105 106 107 |
# File 'lib/rubylexer/tokenprinter.rb', line 105 def inws @inws end |
#lastfal ⇒ Object
,:latestline
105 106 107 |
# File 'lib/rubylexer/tokenprinter.rb', line 105 def lastfal @lastfal end |
#lasttok ⇒ Object
,:latestline
105 106 107 |
# File 'lib/rubylexer/tokenprinter.rb', line 105 def lasttok @lasttok end |
#showzw ⇒ Object (readonly)
Returns the value of attribute showzw.
106 107 108 |
# File 'lib/rubylexer/tokenprinter.rb', line 106 def showzw @showzw end |
Instance Method Details
#aprint(tok) ⇒ Object Also known as: sprint
128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 |
# File 'lib/rubylexer/tokenprinter.rb', line 128 def aprint(tok) if StringToken===tok or HereBodyToken===tok # (HerePlaceholderToken===tok and # tok.bodyclass!=OutlinedHereBodyToken # ) str_needs_escnls=(tok.line-@lastfal.line).nonzero? end if false result=tok.ws_munge(self) and return result #insert extra ws unless an ambiguous op immediately follows #id or num, in which case ws would change the meaning result=tok result= case tok when ZwToken,EoiToken,NoWsToken, HereBodyToken, NewlineToken, ImplicitParamListStartToken,ImplicitParamListEndToken; tok else @sep.dup<<tok.to_s end unless NoWsToken===lasttok if str_needs_escnls result=result.to_s result.gsub!(/(["`\/])$/){ "\\\n"*str_needs_escnls+$1 } end @lasttok=tok @inws=false return result end |
#lastfal_every_10_lines ⇒ Object
164 165 166 167 168 169 |
# File 'lib/rubylexer/tokenprinter.rb', line 164 def lastfal_every_10_lines if(@lastprintline+=1) > 10 @lastprintline=0 %Q[ #@lastfal] end end |
#pprint(tok, output = $stdout) ⇒ Object
120 121 122 123 124 125 126 |
# File 'lib/rubylexer/tokenprinter.rb', line 120 def pprint(tok,output=$stdout) @accum<<aprint(tok).to_s if (@accum.size>ACCUMSIZE and NewlineToken===tok) or EoiToken===tok output<<(@accum.join) @accum=[] end end |
#ws_would_change_meaning?(tok, lasttok) ⇒ Boolean
insert extra ws unless an ambiguous op immediately follows id or num, in which case ws would change the meaning
174 175 176 177 178 179 180 181 |
# File 'lib/rubylexer/tokenprinter.rb', line 174 def ws_would_change_meaning?(tok,lasttok) #yukk -- is it used? tok.kind_of?(String) and /^[%(]$/===tok and #is ambiguous operator? lasttok and (lasttok.kind_of?(Numeric) or (lasttok.kind_of?(String) and /^[$@a-zA-Z_]/===@lasttok)) #lasttok is id or num? end |