473,378 Members | 1,482 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

Block comments

Tomorrow is block comment day. I want them to nest. I think the reason
that they don't routinely nest is that it's a lot of trouble to code.
Two questions:

1) Given a start and end location (line position and char index) in an
array of lines of text, how do you Pythonly extract the whole block
comment? (Goal: not to have Bruno accusing me - correctly - of writing
C in Python.)

2) My tokenizer has a bunch of module-level constants including ones
that define block comment starts/ends. Suppose I comment that code
out. This is the situation:

/* start of block comment
....
BLOCK_COMMENT_END_CHARS = '*/'
....
end of block comment */

Is this the reason for """?

(If this is a good test of tokenizer smarts, cpp and javac flunked.)
Dec 11 '07 #1
3 2735
Ma************@gmail.com a écrit :
Tomorrow is block comment day. I want them to nest. I think the reason
that they don't routinely nest is that it's a lot of trouble to code.
Indeed.
Two questions:

1) Given a start and end location (line position and char index) in an
array of lines of text, how do you Pythonly extract the whole block
comment? (Goal: not to have Bruno accusing me - correctly - of writing
C in Python.)
Is the array of lines the appropriate data structure here ?
2) My tokenizer has a bunch of module-level constants including ones
that define block comment starts/ends. Suppose I comment that code
out. This is the situation:

/* start of block comment
...
BLOCK_COMMENT_END_CHARS = '*/'
...
end of block comment */

Is this the reason for """?
Triple-quoted strings are not comments, they are a way to build
multilines string litterals. The fact is that they are commonly used for
doctrings - for obvious reasons - but then it's the position of this
string litteral that makes it a docstring, not the fact that it's
triple-quoted.

wrt/ your above example, making it a legal construct imply that you
should not consider the block start/end markers as comment markers if
they are enclosed in string-litteral markers.

Now this doesn't solve the problem of nested block comments. Here, I
guess the solution would be to only allow fully nested block comments -
that is, the nested block *must* be opened *and* closed within the
parent block. In which case it should not be harder to parse than any
other nested construct.

While we're at it, you may not know but there are already a couple
Python packages for building tokenizers/parsers - could it be the case
that you're guilty of ReinventingTheSquaredWheel(tm) ?-)

My 2 cents...

Dec 11 '07 #2


Bruno Desthuilliers wrote:
Is the array of lines the appropriate data structure here ?
I've done tokenizers both as an array of lines and as a long string.
The former has seemed easier when the language treats EOL as a
statement separator.

re not letting literal strings in code terminate blocks, I think its
the tokenizer-writer's job to be nice to the tokenizer users, the
first one of which will be me, and I'll definitely have string
literals that enclose what would otherwise be a block end marker.
While we're at it, you may not know but there are already a couple
Python packages for building tokenizers/parsers
The tokenizer in the Python library is pretty close to what I want,
but it returns tuples, where I want an array of Token objects. It also
reads the source a line at a time, which seems a bit out of date.
Maybe two or three decades out of date.

Actually, it takes about a day to write a reasonable tokenizer. (That
is, if you are writing using a language that you know.) Since I know
the problem thoroughly, it seemed like a good starting point for
learning Python.

There's a tokenizer I wrote in java at http://www.MartinRinehart.com/src/la...Tokenizer.html
.. Actually, that's an HTML page written by my "javasrc" (parallel to
Sun's javadoc) based on the Tokenizer's tokenizing of its own source.

Have I got those quotes right?
Dec 11 '07 #3
Ma************@gmail.com a écrit :
(snip about tokenizers - not exactly my domain, sorry)
>
Have I got those quotes right?
Perfect !-)
Dec 12 '07 #4

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

Similar topics

4
by: Christopher | last post by:
This should be a quick one. URL: http://cfa-www.harvard.edu/~cpilman/Stuff/flush.html Code: ============================= <!DOCTYPE HTML Public "-//W3C//DTD HTML 4.01//EN">...
7
by: Zhang Weiwu | last post by:
Hello. This is problem puzzled me a long time. I wish to organize some block elements and let them flow one after each other like text. Think about a album, I wish the album have 12 thumbnails,...
3
by: deko | last post by:
Problem: why doesn't this With block work? is it possible to have a For Each loop within a With block? With objWord .Documents.Add Template:=strTemplate, NewTemplate:=False, DocumentType:=0...
4
by: William | last post by:
I have a question regarding comments. In some of my projects if I have a multi-line comment block I am able to collapse those blocks even if it is within a sub or a function. I like this...
18
by: John Salerno | last post by:
I'm still tyring to figure out what "Pythonic" means, and I have a feeling the answer to my question may fall into that category. Are block comments somehow unpythonic?
3
by: Water Cooler v2 | last post by:
Questions: 1. Can there be more than a single script block in a given HEAD tag? 2. Can there be more than a single script block in a given BODY tag? To test, I tried the following code. None...
2
by: joselijo79 | last post by:
Hi , Could anybody tell us how to use block comments in IBM DB2 Command Center .The version of the client that I'm using is 8.1.6 . I need to comment multiple lines that appear consecutively in an...
3
by: Richard | last post by:
Again, new to DB2. Trying to do something I can do in Sybase ASE. In any Sybase SQL script I can use /* */ to comment out a block of code. In the DB2 9.0 SQL Reference Manual V1 it says: ...
4
by: Daniel | last post by:
Hello, I need to access the code inside of a context manager, i.e. the call to with myManager(v=5) as x: a=b c=sin(x) should cause the following output (minus the first line, if that's...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

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.