Path: csiph.com!newsfeed.hal-mli.net!feeder3.hal-mli.net!newsfeed.hal-mli.net!feeder1.hal-mli.net!nntp-feed.chiark.greenend.org.uk!ewrotcd!news.nosignal.org!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.001 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'binary': 0.05; 'reject': 0.05; 'lines.': 0.07; 'predefined': 0.07; 'python': 0.09; '===': 0.09; 'ast': 0.09; 'itself,': 0.09; 'notation': 0.09; 'operator,': 0.09; 'parsers': 0.09; 'sat,': 0.15; "('a'": 0.16; 'constants': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'operators,': 0.16; 'operators.': 0.16; 'tweak': 0.16; 'wrote:': 0.17; 'jan': 0.18; '>>>': 0.18; 'define': 0.20; 'fairly': 0.21; "i've": 0.23; 'pass': 0.25; 'header:In-Reply-To:1': 0.25; 'looks': 0.26; 'am,': 0.27; 'message-id:@mail.gmail.com': 0.27; 'chris': 0.28; 'implies': 0.29; 'character': 0.29; 'that.': 0.30; 'error': 0.30; 'code': 0.31; 'to:addr:python-list': 0.33; 'code:': 0.33; "can't": 0.34; 'received:google.com': 0.34; 'done': 0.34; 'built- in': 0.35; 'received:209.85.220': 0.35; 'received:209.85': 0.35; 'something': 0.35; 'add': 0.36; 'but': 0.36; 'anything': 0.36; 'possible': 0.37; 'two': 0.37; 'ones': 0.37; 'received:209': 0.37; 'subject:: ': 0.38; 'to:addr:python.org': 0.39; 'takes': 0.39; 'header:Received:5': 0.40; 'think': 0.40; 'first': 0.61; 'more': 0.63; 'behavior': 0.64; 'incorporate': 0.65; 'sum': 0.66; '2013': 0.84; 'edwards': 0.91 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type; bh=gQgnx+H7FcnvHPnYyUBAPrBgWJGKHOW84ksj8bhei4w=; b=ST5MDlqhr16Lpdidof7Oc+sqq11qLtejhhZT5Ozf8cPOvuaO0axDWMimqDb+wmFynd KNNVaxztFTLFbQPH34r4/wTLx8do0Vvbo9GHZw+UH+L56Xld9Vu6F6c16a7EFzuzGKXQ yfwN7SPWAnrDdkIjkN3TCm/GKNfogBSanGwvsttDqzjuliF0fOGzyJ3P3LbZgWgVE6eT 6kU4sPGh6RFmWXRPV96h98zlv6oGQwOVlL7EyaCEjUMhWWuD/n7+JYdePYhpIuF2d+5F bfMfFkP62J1Gj1fnHYMYOjaZeP5h4pXfgEHv2NDakZ29tsgWXzFj1enfsUHrCbKI9+8y HaXw== MIME-Version: 1.0 In-Reply-To: References: <50e6891c$0$30003$c3e8da3$5496439d@news.astraweb.com> Date: Sat, 5 Jan 2013 06:02:49 +1100 Subject: Re: Yet another attempt at a safe eval() call From: Chris Angelico To: python-list@python.org Content-Type: text/plain; charset=ISO-8859-1 X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 26 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1357326171 news.xs4all.nl 6902 [2001:888:2000:d::a6]:39806 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:36134 On Sat, Jan 5, 2013 at 5:43 AM, Grant Edwards wrote: > On 2013-01-04, Chris Angelico wrote: >> On Sat, Jan 5, 2013 at 5:09 AM, Grant Edwards wrote: >>> The error messages are still pretty cryptic, so improving >>> that will add a few more lines. One nice thing about the ast code is >>> that it's simple to add code to allow C-like character constants such >>> that ('A' === 0x41). Here's the first pass at ast-based code: >> >> Looks cool, and fairly neat! Now I wonder, is it possible to use that >> to create new operators, such as the letter d? Binary operator, takes >> two integers... > > I don't think you can define new operators. AFAICT, the > lexing/parsing is done using the built-in Python grammar. You can > control the behavior of the predefined operators and reject operators > you don't like, but you can't add new ones or change precedence/syntax > or anything like that. > > If you want to tweak the grammar itself, then I think you need to use > something like pyparsing. Oh well, hehe. I've not seen any simple parsers that let you incorporate D&D-style dice notation ("2d6" means "roll two 6-sided dice and sum the rolls" - "d6" implies "1d6"). ChrisA