Parsing lines in a file

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Parsing lines in a file

Sean Farrow

Hi all,

 

I have a file that has two kinds of lines:

:function GetTextInRect

:script InsertEmoticon

 

I have the following structure in which I’d like to parse the information:

struct JawsFunction

{

                wstring Name; //function/script name.

                FunctionType Type;

};

 

The FunctionType enum is defined as follows:

enum FunctionType

{

                ID_TYPE_FUNCTION, //function.

                ID_TYPE_SCRIPT //script.

};

 

Using spirit, how do I translate the :script and :function to their enum equivalents,  what is the best way of reading any number of these lines in any order from a file? Finally, how do I parse to the end of the line, excluding the line feed?

Any help appreciated.

Kind regards

Sean.


------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, SlashDot.org! http://sdm.link/slashdot
_______________________________________________
Spirit-general mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/spirit-general
Reply | Threaded
Open this post in threaded view
|

Re: Parsing lines in a file

sehe
On 07-02-17 04:18, Sean Farrow wrote:

 

Using spirit, how do I translate the :script and :function to their enum equivalents,  what is the best way of reading any number of these lines in any order from a file?

Any help appreciated.

Have a look at these

- https://stackoverflow.com/questions/17012941/boostspirit-how-to-parse-and-call-c-function-like-expressions (on parsing function invocations and executing them later)

- This full blown example that actually parses line-by line till the end of the file https://stackoverflow.com/questions/17768152/what-is-the-correct-way-to-handle-multiple-input-command-differently-in-c/17776618#17776618 (live demo on Coliru)

I think they should be inspiritional and perhaps will help you get started.

Finally, how do I parse to the end of the line, excluding the line feed?
Like so:

     *(char_ - eol) >> (eol|eol)

Which means: parse as many non-newline characters as possible till the end of input or an actual newline.

You can combine it with a skipper, but not with `qi::space` because it would eat the newline too:

      skip(blank) [ *(char_ - eol) >> (eol|eol) ];


------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, SlashDot.org! http://sdm.link/slashdot
_______________________________________________
Spirit-general mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/spirit-general
Reply | Threaded
Open this post in threaded view
|

Re: Parsing lines in a file

Sean Farrow

Hi,

 

Thanks, I think I was misunderstood though, I want to parse the two lines and set an enum value based on what is parsed.

Would the previous technique work for this?

Kind regards

Sean.

 

From: Seth [mailto:[hidden email]]
Sent: Tuesday, February 07, 2017 20:42
To: Spirit General Mailing List <[hidden email]>
Subject: Re: [Spirit-general] Parsing lines in a file

 

On 07-02-17 04:18, Sean Farrow wrote:

 

Using spirit, how do I translate the :script and :function to their enum equivalents,  what is the best way of reading any number of these lines in any order from a file?

Any help appreciated.

Have a look at these

- https://stackoverflow.com/questions/17012941/boostspirit-how-to-parse-and-call-c-function-like-expressions (on parsing function invocations and executing them later)

- This full blown example that actually parses line-by line till the end of the file https://stackoverflow.com/questions/17768152/what-is-the-correct-way-to-handle-multiple-input-command-differently-in-c/17776618#17776618 (live demo on Coliru)

I think they should be inspiritional and perhaps will help you get started.

Finally, how do I parse to the end of the line, excluding the line feed?

Like so:

     *(char_ - eol) >> (eol|eol)

Which means: parse as many non-newline characters as possible till the end of input or an actual newline.

You can combine it with a skipper, but not with `qi::space` because it would eat the newline too:

      skip(blank) [ *(char_ - eol) >> (eol|eol) ];


------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, SlashDot.org! http://sdm.link/slashdot
_______________________________________________
Spirit-general mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/spirit-general
Reply | Threaded
Open this post in threaded view
|

Re: Parsing lines in a file

sehe
On 08-02-17 10:05, Sean Farrow wrote:

Would the previous technique work for this?

Kind regards

I think so. You could be a lot more specific though, perhaps you can post the goal as a minimal example on stackoverflow


------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, SlashDot.org! http://sdm.link/slashdot
_______________________________________________
Spirit-general mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/spirit-general