Presumably, you must parse the string (not evaluate), obtain an Abstract
Syntax Tree on return (or an Exception), and check that this AST conforms
to some pattern (at worse you code naïvly the pattern matching, at best you
can reuse the refactor/rewrite engine).

I've not followed latest Compiler developments, but from what I understand,
more and more tools are based on AST...
so it sounds pretty straight-forward.

2017-07-24 18:21 GMT+02:00 Mariano Martinez Peck <[email protected]>:

> Hi guys,
>
> Is there a portable (that would work in GemStone too) and safe way to know
> if a String would be a block?
>
> I must support this kind of strings:
>
> 'singleString'   -> false
> 'multi string' -> false
> '      [:a | 42]' -> true
> '   '' ''  [:a | 42]' -> true
> '[:a | 42]' -> true
> ' "a commet" [:a | 42]' -> true
> ' WhateverClass someVeryBadHackishMethod. [:a | 42]' -> true
>
> I need to identify whether the string is a closure or not. And ideally, I
> don't want to do an #evaluate: because I don't want any left hand code to
> be executed.
> I tried with #parse:  why I am having problems.
>
> Any ideas?
>
> Thanks in advance
>
> --
> Mariano
> http://marianopeck.wordpress.com
>

Reply via email to