<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><br>
Message: 1<br>
Date: Sun, 13 Dec 2015 22:33:37 -0500<br>
From: Mark Steele <<a href="mailto:mark@control-alt-del.org">mark@control-alt-del.org</a>><br>
To: <a href="mailto:erlang-questions@erlang.org">erlang-questions@erlang.org</a><br>
Subject: [erlang-questions] String parsing recommendations<br>
Message-ID:<br>
<CAB5=<a href="mailto:j_qy3PFF%2BfGYxHWLOq2NfGc_H-ciK%2B_TKnggR%2B4nRmM8BQ@mail.gmail.com">j_qy3PFF+fGYxHWLOq2NfGc_H-ciK+_TKnggR+4nRmM8BQ@mail.gmail.com</a>><br>
Content-Type: text/plain; charset="utf-8"<br>
<br>
Hi all,<br>
<br>
This is a pretty basic question, but I'm new so bear with me.<br>
<br>
I've got a binary that might look something like this:<br>
<br>
<<"(foo,bar(faz,fez,fur(foe)),fuz)">><br>
<br>
Parsed, the it might look like:<br>
[<br>
[<<"foo">>],<br>
[<<"bar>>,<<"faz">>],<br>
[<<"bar">>,<<"fez">>],<br>
[<<"bar">>,<<"fur">>,<<"foe">>],<br>
[<<"fuz">>]<br>
]<br>
<br>
<br>
Any recommendations on the best approach to tackle this in Erlang?<br>
<br>
Regards,<br>
<br>
Mark<br>
-------------- next part --------------<br>
An HTML attachment was scrubbed...<br>
URL: <<a href="http://erlang.org/pipermail/erlang-questions/attachments/20151213/6e75379c/attachment-0001.html" rel="noreferrer" target="_blank">http://erlang.org/pipermail/erlang-questions/attachments/20151213/6e75379c/attachment-0001.html</a>><br>
<br>
------------------------------<br>
<br>
Message: 2<br>
Date: Mon, 14 Dec 2015 13:02:24 +0900<br>
From: zxq9 <<a href="mailto:zxq9@zxq9.com">zxq9@zxq9.com</a>><br>
To: <a href="mailto:erlang-questions@erlang.org">erlang-questions@erlang.org</a><br>
Subject: Re: [erlang-questions] String parsing recommendations<br>
Message-ID: <1468783.uT1lQZLqR7@changa><br>
Content-Type: text/plain; charset="utf-8"<br>
<br>
On 2015?12?13? ??? 22:33:37 Mark Steele wrote:<br>
> Hi all,<br>
><br>
> This is a pretty basic question, but I'm new so bear with me.<br>
><br>
> I've got a binary that might look something like this:<br>
><br>
> <<"(foo,bar(faz,fez,fur(foe)),fuz)">><br>
><br>
> Parsed, the it might look like:<br>
> [<br>
> [<<"foo">>],<br>
> [<<"bar>>,<<"faz">>],<br>
> [<<"bar">>,<<"fez">>],<br>
> [<<"bar">>,<<"fur">>,<<"foe">>],<br>
> [<<"fuz">>]<br>
> ]<br>
><br>
><br>
> Any recommendations on the best approach to tackle this in Erlang?<br>
<br>
I'm a little confused about what you are asking. Can you provide some<br>
example input, and some example output? It seems like you're asking<br>
how to write a function that takes input X and returns output Y...?<br>
<br>
-Craig<br>
<br>
<br></blockquote><div><br></div><div>More along the lines of best practices and tools (eg: lex/yecc, neotoma, etc...). I'm good, did some additional research.</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
------------------------------<br>
<br>
Message: 3<br>
Date: Mon, 14 Dec 2015 10:27:57 +0100<br>
From: Mikael Pettersson <<a href="mailto:mikpelinux@gmail.com">mikpelinux@gmail.com</a>><br>
To: Mark Steele <<a href="mailto:mark@control-alt-del.org">mark@control-alt-del.org</a>><br>
Cc: <a href="mailto:erlang-questions@erlang.org">erlang-questions@erlang.org</a><br>
Subject: Re: [erlang-questions] String parsing recommendations<br>
Message-ID: <22126.35741.750950.255610@gargle.gargle.HOWL><br>
Content-Type: text/plain; charset=us-ascii<br>
<br>
Mark Steele writes:<br>
> Hi all,<br>
><br>
> This is a pretty basic question, but I'm new so bear with me.<br>
><br>
> I've got a binary that might look something like this:<br>
><br>
> <<"(foo,bar(faz,fez,fur(foe)),fuz)">><br>
><br>
> Parsed, the it might look like:<br>
> [<br>
> [<<"foo">>],<br>
> [<<"bar>>,<<"faz">>],<br>
> [<<"bar">>,<<"fez">>],<br>
> [<<"bar">>,<<"fur">>,<<"foe">>],<br>
> [<<"fuz">>]<br>
> ]<br>
><br>
><br>
> Any recommendations on the best approach to tackle this in Erlang?<br>
<br>
The input language is clearly not regular, so you'd need<br>
something stronger than regular expressions for parsing.<br>
In this case a context-free parser should work.<br>
<br>
Personally I'd implement a separate scanner which returns tokens<br>
and updated input, and a recursive descent parser which handles<br>
the grammar and produces the output. Your desired output is not<br>
like a parse tree but more like an evaluation of the parse tree<br>
(bar(faz,fez,...) expands to a different structure), but that<br>
expansion looks trivial so I'd let the parser do it -- otherwise<br>
an intermediate parse tree and a separate evaluator will work.<br>
<br>
There are scanner and parser generating tools for Erlang, but<br>
they would be overkill for this simple language -- unless you're<br>
new to language processing, in which case they could help by<br>
providing examples and imposing a sensible structure to the<br>
solution. The re module could be used in a hand-written scanner.<br>
<br>
Alas, no Erlang magic here, just ordinary compiler frontend code.<br>
<br>
/Mikael<br>
<br>
<br></blockquote><div><br></div><div>Yup, thanks.</div></div><br></div></div>