[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

how can I debug treetop grammar?

Lex Williams

8/29/2008 7:57:00 AM

Hi guys !

Parse::RecDescent has RD_TRACE , which when is set to 1 , tells you
which rule the parser it's trying , what it matches , what part of the
input consumes , and so on . Does treetop have an equivalent to this ?
I don't really find the documentation available for it to be that good ,
and calling parser.failure_line and parser.failure_column returns 1,1 no
matter what. Help !
--
Posted via http://www.ruby-....

4 Answers

John

8/29/2008 1:42:00 PM

0

Lex Williams wrote:
> Parse::RecDescent has RD_TRACE , which when is set to 1 , tells you
> which rule the parser it's trying , what it matches , what part of the
> input consumes , and so on . Does treetop have an equivalent to this ?

Each SyntaxNode has "interval", which is the range of byte-offsets matched,
and text_value, which returns that interval from the input.

You seem to have missed some fine diagnostic methods:

SyntaxNode#inspect shows a wealth of information, including an indented
node hierarchy, what input that node matched (abbreviated) and what
accessor methods are added by the modules extended into each node.

Parser#failure_reason tells you where it got to, and what tokens would
have allowed it to get further.

If that isn't enough, try calling your grammar from a lower-level rule
and working up until you see where it's failing.

Also don't forget that there's a "tt" command you can use to generate
the grammar into a ruby file you can inspect.

As for your earlier query, it's a known bug.

Clifford Heath.

Lex Williams

8/29/2008 4:56:00 PM

0

> SyntaxNode#inspect shows a wealth of information, including an indented
> node hierarchy, what input that node matched (abbreviated) and what
> accessor methods are added by the modules extended into each node.
>
> Parser#failure_reason tells you where it got to, and what tokens would
> have allowed it to get further.
>
> If that isn't enough, try calling your grammar from a lower-level rule
> and working up until you see where it's failing.
>
> Also don't forget that there's a "tt" command you can use to generate
> the grammar into a ruby file you can inspect.
>
> As for your earlier query, it's a known bug.
>
> Clifford Heath.

Thank you Clifford , I really appreciate you taking the time to answer
this .
I will look into them , and post here whatever questions I will have !
--
Posted via http://www.ruby-....

Lex Williams

8/29/2008 6:49:00 PM

0

Would you please walk me through a debugging example ? Considering this
grammar :

grammar Dp
rule all
day space month {
def value
day.value.to_s + " " + month.value
end
}
end

rule day
[1-9] [1-9] / "" {
def value
text_value.to_i
end
}
end

rule space
' '*
end

rule month
"Jan" / "Feb" / "Mar" / "Apr" / "May" / "Jun" / "Jul" /
"Aug" / "Sep" / "Oct" / "Nov" / "Dec" / "" {
def value
text_value
end
}
end


end

and the following code :

equire "rubygems"
require "treetop"

Treetop.load "dp"

parser = DpParser.new
node = parser.parse("12")
another = parser.parse("Feb")
lastone = parser.parse("12 Feb")
puts node.value
puts another.value
puts lastone.value

-------------------------------------------------------------------------------
i'm getting back syntax nodes , but I can't call value on any of them .
could you please show me how you would debug the rules ?
hope I'm not asking for too much !
Thanks ,
Lex
--
Posted via http://www.ruby-....

Cresta

6/25/2009 12:41:00 PM

0


That worked Many Thanks

"Andy Pope" wrote:

> Hi,
>
> You should be able to find the information your after here,
> http://www.rondebruin.nl/ge...
>
> Cheers
> Andy
>
> --
>
> Andy Pope, Microsoft MVP - Excel
> http://www.and...
> "Cresta" <Cresta@discussions.microsoft.com> wrote in message
> news:DB64126A-103C-4672-8C4B-8CA8B61EF52D@microsoft.com...
> > Hello All
> >
> > Does anyone know the imageMso name for the Send option "E-mail as Pdf
> > Attachment"
> >
> > Thanks
>
>