Hi,

I actually have already written most of the parser. I have used regular 
expressions and custom string routines.

The file format I need is more complicated than a simple INI file (some INI 
parsers could deal with it, some could not...). I need features like sections, 
comment lines, logical lines, values containing whitespaces and arrays with 
unknown number of elements. I felt that formatted IO, or regexes directly on 
the channel, were insufficient for this task. Especially handling logical lines 
didn't seem easy. I am also most comfortable with parsing line-by-line using 
regular expressions and string routines like trim, split etc. so that also 
affected my decision.

Some features that could be useful to have would be function like sprintf / 
sscanf and/or ability to make channels from strings (similar to stringstram in 
c++?).

Having used regular expressions in that parser, some things I missed from the 
documentation:
 - List of functions (search, sub, match...)
 - What does the multiline option on above functions do? (Or is it broken? ie. 
shouldn't it do the same thing as applying m flag to whole regular expression?)
 - Some examples of regular expressions
 - Reminder that ([:space:]*) is different from ([[:space:]]*)... (that one 
caused some needles frustration)
 - What is the return type of compile("something"); ?
 - If regex support is disabled, why can't errors be generated at compile time?


26.02.2015, 19:35, "Michael Ferguson" <[email protected]>:
> Hi John -
>
> One more note - to write your INI parser you don't actually need
> the string routines like find and trim. (although we should
> certainly have those routines available and as Kyle pointed
> out we'd be happy to have help in this area).
>
> In the mean time, you might be able to do what you need for
> your INI parser with the I/O system. There are two mechanisms
> that you can use to build your parser that don't require working
> with strings as much. You can use the Regexp module or Chapel's
> formatted I/O capabilities to search for and capture some part
> of a file *directly on the channel*. That is, normally, you'd
> write (in every scripting language):
>
>  while true {
>    read a line
>    if EOF then break
>    parse the line into a number followed by a quoted string
>    do stuff based on the parsed line
>  }
>
> Instead, with Chapel, you can combine the reading and the
> parsing to something like this:
>  while true {
>    read a number followed by a quoted string followed by a newline
>    do something with the read number and string
>  }
>
> The README.formattedIO in doc/release/technotes or doc/technotes
> describes how you can use a mechanism similar to scanf in C
> do to these things. If you like working with regular expressions
> directly, you can also use the Regexp module. I'm working on
> improving the documentation for these features, so please let
> me know if you have any suggestions there.
>
> Cheers,
>
> -michael
>
> On 2/26/15, 9:19 AM, "John MacFrenz" <[email protected]> wrote:
>> Hi, and thanks for the information.
>>
>> In the case you haven't been following this list, I am working on a
>> custom array distribution at the moment. Writing this (INI file?) parser
>> is just a sidestep to help me writing tests for the distribution class.
>> This implies that I can't spend very much time on this issue.
>>
>> That said, I already have / will write string manipulation functions as
>> stand-alone functions, and I would surely be willing to spend some time
>> making them part of the new string class. The key factor here is how much
>> work it would require to "get into" the existing code and to get to
>> understand the string record; if adding new features was straightforward
>> enough I could definitely help. Just let me know when you have got the
>> required work done with the strings.
>>
>> I also probably have a few comments about the proposal, I'll try to
>> remember post them later...
>>
>> 26.02.2015, 01:08, "Kyle Brady" <[email protected]>:
>>>   Hi John,
>>>
>>>   In 1.10 the `string` type is just another name for a c_string (char *),
>>>   this type has many problems: memory leaks, issues with transport across
>>>   locales, etc. I've been working on improving the state of our strings
>>> for
>>>   this coming release (1.11). The NewString module is the basis of this
>>>   work, it is a string type that works like any other record in Chapel.
>>> You
>>>   can use the type defined in NewString (string_rec) with 1.10, but be
>>> aware
>>>   that the type hasn't been extensively used and some things will be
>>> renamed
>>>   or changed in the (hopefully) near future.
>>>
>>>   Example of using string_rec:
>>>
>>>   use NewString;
>>>   var msg: string_rec = "Hello, World!"
>>>   writeln(msg);
>>>
>>>   string_rec doesn't have too many procedures, but it does have find and
>>>   indexing (msg.substring(1..5) -> "Hello").
>>>
>>>   I don't think we have any of the others yet.
>>>>    How difficult would it be to incorporate those changes to the
>>>> Chapel's
>>>>   string type?
>>>   I would appreciate the help, but at this exact moment there isn't much
>>>   anyone else can do. I have a lot of code that is floating about for
>>>   switching our string type over to the record implementation that needs
>>>   some other changes to go in before I can merge. Your mail reminded me
>>> that
>>>   a string library proposal that was passed around never made it to
>>>   chapel-users, I'll email that out shortly. There is a lot in that
>>> proposal
>>>   left to work on, so if you are still interested in a few weeks there
>>> will
>>>   be plenty to do. I'd be happy to help get you started on some routines
>>>   then.
>>>
>>>   -Kyle
>>>
>>>   On 2/25/15, 2:13 PM, "John MacFrenz" <[email protected]> wrote:
>>>>   Hi,
>>>>
>>>>   I'm working on a simple file parser used to load configuration and
>>>> fill
>>>>   arrays. I need various helper methods like trim, find, tokenize,
>>>> iterate
>>>>   over string character by character, access character in string by
>>>>   index... So, a few questions relating to this:
>>>>
>>>>   - What is the role of the NewString.chpl file in modules/standard? I
>>>>   noticed it has a find method but I can't figure how to use it...
>>>>
>>>>   - How difficult would it be to incorporate those changes to the
>>>> Chapel's
>>>>   string type? If it was relatively easy and you would be interested I
>>>>   could also contribute code with those features...
>>>>
>>>> ------------------------------------------------------------------------
>>>> --
>>>>   ----
>>>>   Dive into the World of Parallel Programming The Go Parallel Website,
>>>>   sponsored
>>>>   by Intel and developed in partnership with Slashdot Media, is your hub
>>>>   for all
>>>>   things parallel software development, from weekly thought leadership
>>>>   blogs to
>>>>   news, videos, case studies, tutorials and more. Take a look and join
>>>> the
>>>>   conversation now. http://goparallel.sourceforge.net/
>>>>   _______________________________________________
>>>>   Chapel-users mailing list
>>>>   [email protected]
>>>>   https://lists.sourceforge.net/lists/listinfo/chapel-users
>> --------------------------------------------------------------------------
>> ----
>> Dive into the World of Parallel Programming The Go Parallel Website,
>> sponsored
>> by Intel and developed in partnership with Slashdot Media, is your hub
>> for all
>> things parallel software development, from weekly thought leadership
>> blogs to
>> news, videos, case studies, tutorials and more. Take a look and join the
>> conversation now. http://goparallel.sourceforge.net/
>> _______________________________________________
>> Chapel-users mailing list
>> [email protected]
>> https://lists.sourceforge.net/lists/listinfo/chapel-users

------------------------------------------------------------------------------
Dive into the World of Parallel Programming The Go Parallel Website, sponsored
by Intel and developed in partnership with Slashdot Media, is your hub for all
things parallel software development, from weekly thought leadership blogs to
news, videos, case studies, tutorials and more. Take a look and join the 
conversation now. http://goparallel.sourceforge.net/
_______________________________________________
Chapel-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/chapel-users

Reply via email to