GithubHelp home page GithubHelp logo

Comments (7)

sirthias avatar sirthias commented on June 11, 2024

parboiled sets the value field of a parse tree node to the top element of the value stack at the time of the node construction. Does your parser contain action code that pushes custom objects onto the value stack? Only then will you see non-null values in your parse tree nodes...

from parboiled.

adpande avatar adpande commented on June 11, 2024

Yes, you are right. When I am pushing values in the stack they are showing up. Will it not be good if we can get values of the child nodes??

from parboiled.

sirthias avatar sirthias commented on June 11, 2024

I'm not quite sure I get what you are asking for..
You can traverse the parse tree in any way you seem fit and, of course, also get to all members of potentially existing child nodes.

from parboiled.

adpande avatar adpande commented on June 11, 2024

Sorry Sirthias, I was little confused. I got it working now. You may see such (may be silly) questions form me as this is the first time I am working with parsers. Thanks a lot for this wonderful library. One seggestion : If possible include a tutorial on "How to use ParseTree".

from parboiled.

sirthias avatar sirthias commented on June 11, 2024

No problem, just go ahead and ask questions if you think that I or other users might be able to help. But probably the parboiled user mailing list is a better place for such things...

from parboiled.

adpande avatar adpande commented on June 11, 2024

Hi Mathias,

The Node.getValue() is still not working. I have the following parse tree:

[top_vars] 'def i\n <f c="dfdf">dfdfdf</f>\nend'
  [key] 'i\n '
  [value] '<f c="dfdf">dfdfdf</f>\n'
[top_vars] '\n\ndef j\n kfgfdgjdfg\nend'
  [key] 'j\n '
  [value] 'kfgfdgjdfg\n'
[top_vars] '\n\ndef k\n format = "mm-dd-yyyy"\nend'
  [key] 'k\n '
  [value] 'format = "mm-dd-yyyy"\n'

I am finding a node by using following Java code:

Node key = findNodeByLabel(n,"key");
Node value = findNodeByLabel(n,"value");

When I try to print the value of the node using

key.getValue().toString() it gives me null pointer exception. But If I try to print using the following code it works absolutely fine.

System.out.println("Key: "+ result.inputBuffer.extract(key.getStartIndex(),key.getEndIndex()).toString());

I am not sure what the problem is.

Thanks & Regards,
Abhishek

from parboiled.

sirthias avatar sirthias commented on June 11, 2024

I'm not sure I get what you are trying to do.
The "value" of a node is a custom object that you create! If you do not create anything the value will always be null. Could it be that you confuse the "value" of the node with its matched input text?
And: Please let's move these discussions to the user mailing list.

from parboiled.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.