[Pharo-project] shorten petitparser expressions
Why i need to put #asParser everywhere? $a asParser / $b asParser / #foo asParser a proper implementation of #/ makes the above to just: $a asParser / $b / #foo which is much more cleaner and convenient. Or, is there a reason to not send #asParser to every argument where parser expected? -- Best regards, Igor Stasenko.
Hi, I think the reason is for consistency. If fact I like as it is now for that reason. $a asParser / $b asParser / #foo asParser "It looks clear to me and is consistent." a asParser / $b / #foo "it looks odd because it is inconsistent." Anyway, for such simple parsers you loose consistency and you don't gain much. If you have to deal with longer statements, if you have to make your parsers reusable or simply to make your simple example cleaner for real, you should have separate methods: a ^$a asParser b ^$b asParser foo ^#foo asParser a / b / foo " this is cleaner and consistent" I hope I made my point. Cheers, Fabrizio "Consistency, Consistency, Consistency" 2012/2/28 Igor Stasenko <siguctua@gmail.com>
Why i need to put #asParser everywhere?
$a asParser / $b asParser / #foo asParser
a proper implementation of #/ makes the above to just:
$a asParser / $b / #foo
which is much more cleaner and convenient.
Or, is there a reason to not send #asParser to every argument where parser expected?
-- Best regards, Igor Stasenko.
On 28 February 2012 16:50, Fabrizio Perin <fabrizio.perin@gmail.com> wrote:
Hi, I think the reason is for consistency. If fact I like as it is now for that reason.
$a asParser / $b asParser / #foo asParser "It looks clear to me and is consistent."
a asParser / $b / #foo "it looks odd because it is inconsistent."
Anyway, for such simple parsers you loose consistency and you don't gain much. If you have to deal with longer statements, if you have to make your parsers reusable or simply to make your simple example cleaner for real, you should have separate methods: a ^$a asParser
b ^$b asParser
foo ^#foo asParser
a / b / foo " this is cleaner and consistent"
I hope I made my point.
Cheers, Fabrizio
"Consistency, Consistency, Consistency"
I've often used #anyOf: - anyOf: someTokens "Writing without a compiler; may actually still work!" ^ someTokens allButFirst inject: someTokens first into: [:acc :each | acc / each asParser] self anyOf: #($a $b #foo). frank
2012/2/28 Igor Stasenko <siguctua@gmail.com>
Why i need to put #asParser everywhere?
$a asParser / $b asParser / #foo asParser
a proper implementation of #/ makes the above to just:
$a asParser / $b / #foo
which is much more cleaner and convenient.
Or, is there a reason to not send #asParser to every argument where parser expected?
-- Best regards, Igor Stasenko.
On 28 February 2012 18:40, Frank Shearar <frank.shearar@gmail.com> wrote:
On 28 February 2012 16:50, Fabrizio Perin <fabrizio.perin@gmail.com> wrote:
Hi, I think the reason is for consistency. If fact I like as it is now for that reason.
$a asParser / $b asParser / #foo asParser "It looks clear to me and is consistent."
a asParser / $b / #foo "it looks odd because it is inconsistent."
Anyway, for such simple parsers you loose consistency and you don't gain much. If you have to deal with longer statements, if you have to make your parsers reusable or simply to make your simple example cleaner for real, you should have separate methods: a ^$a asParser
b ^$b asParser
foo ^#foo asParser
a / b / foo " this is cleaner and consistent"
I hope I made my point.
Cheers, Fabrizio
"Consistency, Consistency, Consistency"
I've often used #anyOf: -
anyOf: someTokens  "Writing without a compiler; may actually still work!"  ^ someTokens allButFirst   inject: someTokens first   into: [:acc :each | acc / each asParser]
self anyOf: #($a $b #foo).
so, talking about consistency, where is consistency, when here you have implicit #asParser, while in rest methods not? :) maybe we should write it like that: self anyOf: {$a asParser. $b asParser. #foo asParser }. "Consistency, Consistency, Consistency" :)
frank
2012/2/28 Igor Stasenko <siguctua@gmail.com>
Why i need to put #asParser everywhere?
$a asParser / $b asParser / #foo asParser
a proper implementation of #/ makes the above to just:
$a asParser / $b / #foo
which is much more cleaner and convenient.
Or, is there a reason to not send #asParser to every argument where parser expected?
-- Best regards, Igor Stasenko.
-- Best regards, Igor Stasenko.
On 28 February 2012 17:43, Igor Stasenko <siguctua@gmail.com> wrote:
On 28 February 2012 18:40, Frank Shearar <frank.shearar@gmail.com> wrote:
On 28 February 2012 16:50, Fabrizio Perin <fabrizio.perin@gmail.com> wrote:
Hi, I think the reason is for consistency. If fact I like as it is now for that reason.
$a asParser / $b asParser / #foo asParser "It looks clear to me and is consistent."
a asParser / $b / #foo "it looks odd because it is inconsistent."
Anyway, for such simple parsers you loose consistency and you don't gain much. If you have to deal with longer statements, if you have to make your parsers reusable or simply to make your simple example cleaner for real, you should have separate methods: a ^$a asParser
b ^$b asParser
foo ^#foo asParser
a / b / foo " this is cleaner and consistent"
I hope I made my point.
Cheers, Fabrizio
"Consistency, Consistency, Consistency"
I've often used #anyOf: -
anyOf: someTokens  "Writing without a compiler; may actually still work!"  ^ someTokens allButFirst   inject: someTokens first   into: [:acc :each | acc / each asParser]
self anyOf: #($a $b #foo).
so, talking about consistency, where is consistency, when here you have implicit #asParser, while in rest methods not? :) maybe we should write it like that:
 self anyOf: {$a asParser.  $b asParser.  #foo asParser }.
 "Consistency, Consistency, Consistency"
:)
Well, I do like consistency, but I wasn't the one to say "Consistency, Consistency, Consistency" :) Still, at least #anyOf: indicates that something's happening, so it's not like it's magically adding #asParser. I don't have it open, but Cutie (from LanguageBoxes) has a parser that does vaguely magical stuff to say "a / b / c", something like a PPCompositeParser. frank
frank
2012/2/28 Igor Stasenko <siguctua@gmail.com>
Why i need to put #asParser everywhere?
$a asParser / $b asParser / #foo asParser
a proper implementation of #/ makes the above to just:
$a asParser / $b / #foo
which is much more cleaner and convenient.
Or, is there a reason to not send #asParser to every argument where parser expected?
-- Best regards, Igor Stasenko.
-- Best regards, Igor Stasenko.
On 28 February 2012 17:50, Fabrizio Perin <fabrizio.perin@gmail.com> wrote:
Hi, I think the reason is for consistency. If fact I like as it is now for that reason.
$a asParser / $b asParser / #foo asParser "It looks clear to me and is consistent."
a asParser / $b / #foo "it looks odd because it is inconsistent."
why odd? and explicitly sending #asParser to every argument is less odd?
Anyway, for such simple parsers you loose consistency and you don't gain much. If you have to deal with longer statements, if you have to make your parsers reusable or simply to make your simple example cleaner for real, you should have separate methods: a ^$a asParser
b ^$b asParser
foo ^#foo asParser
a / b / foo " this is cleaner and consistent"
oh please, don't call splitting single expression onto 3 separate methods "cleaning" :) With this change i could write same code as before, but you can't do write like me.
I hope I made my point.
Cheers, Fabrizio
"Consistency, Consistency, Consistency"
2012/2/28 Igor Stasenko <siguctua@gmail.com>
Why i need to put #asParser everywhere?
$a asParser / $b asParser / #foo asParser
a proper implementation of #/ makes the above to just:
$a asParser / $b / #foo
which is much more cleaner and convenient.
Or, is there a reason to not send #asParser to every argument where parser expected?
-- Best regards, Igor Stasenko.
-- Best regards, Igor Stasenko.
2012/2/28 Igor Stasenko <siguctua@gmail.com>
On 28 February 2012 17:50, Fabrizio Perin <fabrizio.perin@gmail.com> wrote:
Hi, I think the reason is for consistency. If fact I like as it is now for that reason.
$a asParser / $b asParser / #foo asParser "It looks clear to me and is consistent."
a asParser / $b / #foo "it looks odd because it is inconsistent."
why odd? and explicitly sending #asParser to every argument is less odd?
No but it is more consistent :)
Anyway, for such simple parsers you loose consistency and you don't gain much. If you have to deal with longer statements, if you have to make your parsers reusable or simply to make your simple example cleaner for real, you should have separate methods: a ^$a asParser
b ^$b asParser
foo ^#foo asParser
a / b / foo " this is cleaner and consistent"
oh please, don't call splitting single expression onto 3 separate methods "cleaning" :)
I was just providing an example as you did. Btw I do create most of the time really small productions all the time. I mean, if I think a parser deserve to be created let's make it good. Otherwise I can solve my problems with regular expressions and string comparisons.
With this change i could write same code as before, but you can't do write like me.
I don't want to write like you otherwise I wouldn't reply in the first place ;) Anyway, mine it is just an opinion. I simply prefer to have it explicit, that's all. Best regards, Fabrizio
I hope I made my point.
Cheers, Fabrizio
"Consistency, Consistency, Consistency"
2012/2/28 Igor Stasenko <siguctua@gmail.com>
Why i need to put #asParser everywhere?
$a asParser / $b asParser / #foo asParser
a proper implementation of #/ makes the above to just:
$a asParser / $b / #foo
which is much more cleaner and convenient.
Or, is there a reason to not send #asParser to every argument where parser expected?
-- Best regards, Igor Stasenko.
-- Best regards, Igor Stasenko.
participants (3)
-
Fabrizio Perin -
Frank Shearar -
Igor Stasenko