coatl / redparse

RedParse is a ruby parser written in pure ruby.
redparse.rubyforge.org
GNU Lesser General Public License v2.1
24 stars 2 forks source link

Parser.new.to_s output is way verbose #3

Open rdp opened 15 years ago

rdp commented 15 years ago

with non helpful info--or is that inspect?

coatl commented 15 years ago

RedParse#to_s is extremely brief, but #inspect indeed shows many lines of output... there's a lot of state to a RedParse parser object, (particularly in the @lexer instance var). I can't really get rid of any of that state easily, and I don't see why this should be a big problem... who would ever really want to look at it?... except to debug something, when you do need to see all the state.

I'd rather not write a custom inspect for this class.

I think maybe you meant to complain about how ugly the output is when you p or pp a RedParse::Node tree? That's a more serious issue....

rdp commented 14 years ago

I was concerned with the ugliness of #inspect (when using it in an irb session).

I took the liberty of creating a patch on my branch... http://github.com/rdp/redparse

parser=RedParse.new("some ruby code here") => #<RedParse: [some ruby code here]>

instead of the [surprisingly large]

=> "#<RedParse:0x204c9c0 @rubyversion=1.80000000000000004441, @input=\"some ruby code here\", @write_cache=#<RedParse::Cache:0x204c8c0 @callersfile=\"90a756f941dd18031fd625c9e21fba41f78f379746c840adb87bec3f15b55d10\", @homedir=\"C:\\Documents and Settings\\packrd/.redparse/\">, @lexer=#<RubyLexer:0x2049c60 @offset_adjust=0, @filename=\"(eval)\", @original_file=\"some ruby code here\", @file=#<Sequence::OfString:0x2049c40 @data=\"some ruby code here\", @pos=0, @last_match=nil>, @linenum=1, @toptable=#<RubyLexer::CharHandler:0x2049a40 @default=:identifier, @receiver=#<RubyLexer:0x2049c60 ...>, @table={\"$\"=>:dollar_identifier, \"@\"=>:atidentifier, \"a\"=>:identifier, \"b\"=>:identifier, \"c\"=>:identifier, \"d\"=>:identifier, \"e\"=>:identifier, \"f\"=>:identifier, \"g\"=>:identifier, \"h\"=>:identifier, \"i\"=>:identifier, \"j\"=>:identifier, \"k\"=>:identifier, \"l\"=>:identifier, \"m\"=>:identifier, \"n\"=>:identifier, \"o\"=>:identifier, \"p\"=>:identifier, \"q\"=>:identifier, \"r\"=>:identifier, \"s\"=>:identifier, \"t\"=>:identifier, \"u\"=>:identifier, \"v\"=>:identifier, \"w\"=>:identifier, \"x\"=>:identifier, \"y\"=>:identifier, \"z\"=>:identifier, \"A\"=>:identifier, \"B\"=>:identifier, \"C\"=>:identifier, \"D\"=>:identifier, \"E\"=>:identifier, \"F\"=>:identifier, \"G\"=>:identifier, \"H\"=>:identifier, \"I\"=>:identifier, \"J\"=>:identifier, \"K\"=>:identifier, \"L\"=>:identifier, \"M\"=>:identifier, \"N\"=>:identifier, \"O\"=>:identifier, \"P\"=>:identifier, \"Q\"=>:identifier, \"R\"=>:identifier, \"S\"=>:identifier, \"T\"=>:identifier, \"U\"=>:identifier, \"V\"=>:identifier, \"W\"=>:identifier, \"X\"=>:identifier, \"Y\"=>:identifier, \"Z\"=>:identifier, \"\"=>:identifier, \"0\"=>:number, \"1\"=>:number, \"2\"=>:number, \"3\"=>:number, \"4\"=>:number, \"5\"=>:number, \"6\"=>:number, \"7\"=>:number, \"8\"=>:number, \"9\"=>:number, \"\"\"=>:double_quote, \"'\"=>:single_quote, \"\"=>:back_quote, \" \"=>:whitespace, \"\\t\"=>:whitespace, \"\\r\"=>:whitespace, \"\\v\"=>:whitespace, \"\\f\"=>:whitespace, \",\"=>:comma, \";\"=>:semicolon, \"^\"=>:caret, \"~\"=>:tilde, \"=\"=>:equals, \"!\"=>:exclam, \".\"=>:dot, \"/\"=>:regex_or_div, \"|\"=>:conjunction_or_goalpost, \">\"=>:quadriop, \"*\"=>:star_or_amp, \"&\"=>:star_or_amp, \"+\"=>:plusminus, \"-\"=>:plusminus, \"<\"=>:lessthan, \"%\"=>:percent, \"?\"=>:char_literal_or_op, \":\"=>:symbol_or_op, \"\\n\"=>:newline, \"\\\\\"=>:escnewline, \"[\"=>:open_brace, \"(\"=>:open_brace, \"{\"=>:open_brace, \"]\"=>:close_brace, \")\"=>:close_brace, \"}\"=>:close_brace, \"#\"=>:comment, \"\\x00\"=>:eof, \"\\x04\"=>:eof, \"\\x1A\"=>:eof, \"\\x01\"=>:illegal_char, \"\\x02\"=>:illegal_char, \"\\x03\"=>:illegal_char, \"\\x05\"=>:illegal_char, \"\\x06\"=>:illegal_char, \"\\a\"=>:illegal_char, \"\\b\"=>:illegal_char, \"\\x0E\"=>:illegal_char, \"\\x0F\"=>:illegal_char, \"\\x10\"=>:illegal_char, \"\\x11\"=>:illegal_char, \"\\x12\"=>:illegal_char, \"\\x13\"=>:illegal_char, \"\\x14\"=>:illegal_char, \"\\x15\"=>:illegal_char, \"\\x16\"=>:illegal_char, \"\\x17\"=>:illegal_char, \"\\x18\"=>:illegal_char, \"\\x19\"=>:illegal_char, \"\\e\"=>:illegal_char, \"\\x1C\"=>:illegal_char, \"\\x1D\"=>:illegal_char, \"\\x1E\"=>:illegal_char, \"\\x1F\"=>:illegal_char, \"\\x7F\"=>:illegal_char}, @matcher=/^[^$@abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_0123456789\"' \t\r\v\f,;^~=!.\/|>_&+-<%?:\n\[({])}#\x00\x04\x1A\x01\x02\x03\x05\x06\x07\x08\x0E\x0F\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1B\x1C\x1D\x1E\x1F\x7F]$/>, @min_offset_adjust=0, @moretokens=[#<RubyLexer::FileAndLineToken:0x2049c20 @ident=\"(eval)\", @offset=0, @line=1>], @endsets={}, @start_linenum=1, @parsestack=[#<RubyLexer::NestedContexts::TopLevelContext:0x2049bc0 @starter=\"\", @ender=\"\", @linenum=1>], @incomplete_here_tokens=[], @pending_here_bodies=[], @localvars_stack=[#<RubyLexer::SymbolTable:0x2049ae0 @symbols={}, @locals_lists=[{}]>], @defining_lvar=nil, @in_def_name=false, @last_operative_token=nil, @last_token_maybe_implicit=nil, @enable_macro=nil, @base_file=nil, @progress_thread=nil, @rubyversion=1.80000000000000004441, @encoding=:ascii, @methodoperators=/^([&|^\/%]|=(==?)|=~|>[=>]?|<(<|=>?)?|[+~-]@?|_\?|[]=?)/>, @filename=\"(eval)\", @min_sizes={}, @compiled_rules={}, @moretokens=[], @unary_or_binary_op=/^[-+]$/, @precedence={\"::\"=>121, \".\"=>121, \"[\"=>120, \"!\"=>119, \"~\"=>119, \"+@\"=>119, \"_\"=>118, \"-@\"=>117, \"\"=>116, \"/\"=>116, \"%\"=>116, \"+\"=>115, \"-\"=>115, \"<<\"=>114, \">>\"=>114, \"&\"=>113, \"^\"=>112, \"|\"=>112, \"<=\"=>111, \">=\"=>111, \"<\"=>111, \">\"=>111, \"<=>\"=>110, \"==\"=>110, \"===\"=>110, \"!=\"=>110, \"=~\"=>110, \"!~\"=>110, \"&&\"=>109, \"||\"=>108, \"..\"=>107, \"...\"=>107, \"?\"=>106, \"unary&\"=>105, \"lhs\"=>105, \"lhs,\"=>105, \"rescue3\"=>105, \"=\"=>104, \"%=\"=>104, \"/=\"=>104, \"-=\"=>104, \"+=\"=>104, \"|=\"=>104, \"&=\"=>104, \">>=\"=>104, \"<<=\"=>104, \"=\"=>104, \"&&=\"=>104, \"||=\"=>104, \"=\"=>104, \"^=\"=>104, \"defined?\"=>103, \"not\"=>103, \":\"=>102, \"=>\"=>101, \"rhs,\"=>100, \",\"=>100, \"rhs\"=>100, \"unary\"=>100, \"or\"=>99, \"and\"=>99, \"if\"=>98, \"unless\"=>98, \"while\"=>98, \"until\"=>98, \"rescue\"=>98, \";\"=>96}, @RIGHT_ASSOCIATIVE={\"\"=>118, \"=\"=>105, \"%=\"=>105, \"/=\"=>105, \"-=\"=>105, \"+=\"=>105, \"|=\"=>105, \"&=\"=>105, \">>=\"=>105, \"<<=\"=>105, \"=\"=>105, \"&&=\"=>105, \"||=\"=>105, \"*=\"=>105, \"^=\"=>105}, @saw_item_that=nil>"

check it out :)