473,804 Members | 2,148 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Validating Syntax only with PyParser_Simple ParseString ?


I am seeking for a method to parse single lines of Python code (infact
they are only formulas, so I generate a line like RESULT=<formula >). I
do only want to know if the syntax is correct and if there is an error
best would be to know where.

I did find PyParser_Simple ParseString which does return a node
structure. If there is an error it seems to return NULL, while I did
not find this documented.

Th eproblem with this is that first I do not get th elopcation of the
syntax error, and second I don't know what is the proper method to free
the node structure after I got it, since I will not use it. Or is there
any better method doing this anyway.

Environment: Windows / Borland C++

Mar 29 '06 #1
3 1653

ga************* *@web.de wrote:
I am seeking for a method to parse single lines of Python code (infact
they are only formulas, so I generate a line like RESULT=<formula >). I
do only want to know if the syntax is correct and if there is an error
best would be to know where.

I did find PyParser_Simple ParseString which does return a node
structure. If there is an error it seems to return NULL, while I did
not find this documented.

Th eproblem with this is that first I do not get th elopcation of the
syntax error, and second I don't know what is the proper method to free
the node structure after I got it, since I will not use it. Or is there
any better method doing this anyway.
A better way might be to use the standard library compiler module. A
file called cptools.py (part of the cherrypy project) has a very simple
example called 'unrepr' which shows how to do it.

I only have restricted internet access or I would find the URL for you
(sorry).

Fuzzyman
http://www.voidspace.org.uk/python/index.shtml
Environment: Windows / Borland C++


Mar 29 '06 #2

ga************* *@web.de wrote:
I am seeking for a method to parse single lines of Python code (infact
they are only formulas, so I generate a line like RESULT=<formula >). I
do only want to know if the syntax is correct and if there is an error
best would be to know where.

I did find PyParser_Simple ParseString which does return a node
structure. If there is an error it seems to return NULL, while I did
not find this documented.

Th eproblem with this is that first I do not get th elopcation of the
syntax error, and second I don't know what is the proper method to free
the node structure after I got it, since I will not use it. Or is there
any better method doing this anyway.

Environment: Windows / Borland C++


The builtin function compile will throw a SyntaxError if the syntax is
bad.
compile("1=a"," ","single") Traceback (most recent call last):
File "<interacti ve input>", line 1, in ?
SyntaxError: can't assign to literal


Mar 29 '06 #3
Thanks for th eanswers so far.

But as you can see from the function I use, I do need an interface
function to do th ejob from C++. I canno timagine there is no clean way
to do this. Calling th epython interpreter to execute a compule
function in python and then get the output parsed to get th eerror
message i snot an option. The strange thing however is that I have
tried to use th ecompile interface function first and this one did
return an error. I supposed this was because th ewhole context did not
exist so I went to the "parse only" function.

The main question I have is what to do with the pointer to the node
structure returned by this function, as freeing th epointer with free()
throws an error.

Mar 30 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
10343
by: Clifford W. Racz | last post by:
Does anyone know of a decent tool, preferably free, that will check and validate DTD syntax, to make sure that my DTD is correct? The only tool that I have found thus far is the IBM visual DTD tool, which I do like, but is limited. Basically, your DTD is "good" when it parses... and I am not sure this is the best way to do it. As for validation of XML, I have found a great tool, xmlvalid, here: <...
0
1135
by: blurz | last post by:
Hi, would like to know how to go about validating a a group of textboxes. For example, I have 3 textboxes that will hold a user's different contact numbers. How do I ensure that at least one of the textboxes will be entered? Solutions with syntax of coding will be appreciated. Thanks. Rgrds, blurz
5
5989
by: Steve | last post by:
I am currently trying to validate data in an access database. I need to verify that columns containing date information are in the format ddmmyyyy and columns containg time information are in the format HH:MM 24. The dates and times are stored in text fields. ie date 12121998, time 20:34 Could anyone suggest a method for validating the fields. What is the syntax for converting text fields into dates and times? Any suggestions...
2
5205
by: bildad | last post by:
The following 'book example' of validating input seems to be incomplete. Since it is a beginner's book it may be intentional for simplicity. But I would like to know how to make this program work for all invalid input. Just for example, if user inputs 'abc' an error is caught, but if user inputs '432' the program hangs. Any clarification appreciated. Thanks, Bill
6
5804
by: Alex Bink | last post by:
Hi, I have a validating event on a textbox in which I want to prevent the user to leave the textbox without entering the right data. Only if he clicks on another specific control he is allowed to leave the textbox without entering the right information. Is there a way to determine which other control was clicked in the validating event of the textbox? Thanks
3
2402
by: Tom Anderson | last post by:
Hi all, A hoary old chestnut this - any advice on how to syntactically validate an email address? I'd like to support both the display-name-and-angle-bracket and bare-address forms, and to allow everything that RFC 2822 allows (and nothing more!). Currently, i've got some regexps which recognise a common subset of possible addresses, but it would be nice to do this properly - i don't currently support quoted pairs, quoted strings, or...
232
13384
by: robert maas, see http://tinyurl.com/uh3t | last post by:
I'm working on examples of programming in several languages, all (except PHP) running under CGI so that I can show both the source files and the actually running of the examples online. The first set of examples, after decoding the HTML FORM contents, merely verifies the text within a field to make sure it is a valid representation of an integer, without any junk thrown in, i.e. it must satisfy the regular expression: ^ *?+ *$ If the...
2
4723
by: arunairs | last post by:
Hi, Is there a way of validating and XPath? In this case , I am accepting an XPath from the user and I need to validate the XPath syntax. Is there a regular expression available that anyone can direct me to, to validate a XPath? thanks, Arun
76
3079
by: Michael Stemper | last post by:
The W3C Validator is a great help, as far as it goes. However, I'm looking for something stricter. My coding style does not allow for implicit termination of an element; my intention and desire is to explicitly terminate every element. Just last night, it took me two hours to track down some funny behavior. It turned out to be caused by entries in a definition list that looked like: <dt>Term<dt> <dd>Definition</dd>
0
9712
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10595
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10343
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10341
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9171
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7634
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
1
4308
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3831
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3001
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.