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