Re: [PATCH v2 16/19] modula2 front end: bootstrap and documentation tools

2022-11-27 Thread Gaius Mulley via Gcc-patches
David Malcolm  writes:

>> Once modula-2 is in master I'd like to revisit rst in devel/modula-2
>> along with analyzer patches and m2 generics.  If successful then
>> submit
>> patches in early stage 1.
>
> Am I right in thinking the analyzer stuff would be an updated version
> of the work you posted here:
> https://gcc.gnu.org/pipermail/gcc-patches/2021-April/567953.html ?

Sure, yes.

regards,
Gaius


Re: [PATCH v2 16/19] modula2 front end: bootstrap and documentation tools

2022-11-25 Thread David Malcolm via Gcc-patches
On Thu, 2022-11-24 at 14:30 +, Gaius Mulley via Gcc-patches wrote:
> Martin Liška  writes:
> 
> > On 11/8/22 14:22, Gaius Mulley wrote:
> > > Martin Liška  writes:
> > > 
> > > should be good - I'll complete the rst output in the scripts,
> > 
> > Hi.
> > 
> 
> Hi Martin,
> 
> > As you probably noticed, the Sphinx migration didn't go well.
> 
> Yes, sorry to see this didn't happen.  Thank you for your hard work
> and
> I hope it can occur in the future.

Likewise, thanks for all your work on this.

> 
> > However, it's still up to you if you want to use it or not for
> > Modula
> > 2.
> 
> Once modula-2 is in master I'd like to revisit rst in devel/modula-2
> along with analyzer patches and m2 generics.  If successful then
> submit
> patches in early stage 1.

Am I right in thinking the analyzer stuff would be an updated version
of the work you posted here:
 https://gcc.gnu.org/pipermail/gcc-patches/2021-April/567953.html
?

Thanks
Dave



Re: [PATCH v2 16/19] modula2 front end: bootstrap and documentation tools

2022-11-25 Thread Martin Liška
On 11/24/22 15:30, Gaius Mulley wrote:
> Martin Liška  writes:
> 
>> On 11/8/22 14:22, Gaius Mulley wrote:
>>> Martin Liška  writes:
>>>
>>> should be good - I'll complete the rst output in the scripts,
>>
>> Hi.
>>
> 
> Hi Martin,
> 
>> As you probably noticed, the Sphinx migration didn't go well.
> 
> Yes, sorry to see this didn't happen.  Thank you for your hard work and
> I hope it can occur in the future.

Hi.

We'll see, it's not in my plans for near future.

> 
>> However, it's still up to you if you want to use it or not for Modula
>> 2.
> 
> Once modula-2 is in master I'd like to revisit rst in devel/modula-2
> along with analyzer patches and m2 generics.  If successful then submit
> patches in early stage 1.

Sounds good.

> 
>> We have manuals like libgccjit, or Ada manuals
>> that use RST natively and provide exported .texi files.
> 
> Ok thanks for the pointers, I will experiment with these build rhunes.
> 
>> Cheers and sorry for the troubles I caused.
> 
> No problem at all - the modula-2 scripts are now improved and cleaner
> due to the port.  Hopefully rst will happen sometime in the future,

Regards,
Martin

> 
> regards,
> Gaius



Re: [PATCH v2 16/19] modula2 front end: bootstrap and documentation tools

2022-11-24 Thread Gaius Mulley via Gcc-patches
Martin Liška  writes:

> On 11/8/22 14:22, Gaius Mulley wrote:
>> Martin Liška  writes:
>> 
>> should be good - I'll complete the rst output in the scripts,
>
> Hi.
>

Hi Martin,

> As you probably noticed, the Sphinx migration didn't go well.

Yes, sorry to see this didn't happen.  Thank you for your hard work and
I hope it can occur in the future.

> However, it's still up to you if you want to use it or not for Modula
> 2.

Once modula-2 is in master I'd like to revisit rst in devel/modula-2
along with analyzer patches and m2 generics.  If successful then submit
patches in early stage 1.

> We have manuals like libgccjit, or Ada manuals
> that use RST natively and provide exported .texi files.

Ok thanks for the pointers, I will experiment with these build rhunes.

> Cheers and sorry for the troubles I caused.

No problem at all - the modula-2 scripts are now improved and cleaner
due to the port.  Hopefully rst will happen sometime in the future,

regards,
Gaius


Re: [PATCH v2 16/19] modula2 front end: bootstrap and documentation tools

2022-11-24 Thread Martin Liška
On 11/8/22 14:22, Gaius Mulley wrote:
> Martin Liška  writes:
> 
>> 1) I would prefer using ' instead of ":
>>
>> $ flake8 ./gcc/m2/tools-src/tidydates.py
>> ...
>> ./gcc/m2/tools-src/tidydates.py:124:30: Q000 Double quotes found but single 
>> quotes preferred
>> ./gcc/m2/tools-src/tidydates.py:127:27: Q000 Double quotes found but single 
>> quotes preferred
>> ./gcc/m2/tools-src/tidydates.py:132:27: Q000 Double quotes found but single 
>> quotes preferred
>> ./gcc/m2/tools-src/tidydates.py:133:33: Q000 Double quotes found but single 
>> quotes preferred
>> ./gcc/m2/tools-src/tidydates.py:138:26: Q000 Double quotes found but single 
>> quotes preferred
>> ./gcc/m2/tools-src/tidydates.py:143:28: Q000 Double quotes found but
>> single quotes preferred
> 
> ah yes will switch the quotes character.
> 
>> 2) Python-names would be nicer:
>>
>> def writeTemplate(fo, magic, start, end, dates, contribution, summary,
>> lic):
>>
>> def write_template(...)
> 
> agreed, will change
> 
>> 3) def hasExt(name, ext) - please use Path from pathlib
>>
>> 4) while (str.find(line, "(*") != -1):
>>
>> '(*' in line
>> ? Similarly elsewhere.
>>
>> 5) str.find(line, ...)
>>
>> Use rather directly: line.find(...)
>>
>> 6) please use flake8:
>> https://gcc.gnu.org/codingconventions.html#python
> 
> sure will do all above - I used flake8 but maybe the plugins weren't
> enabled.  I'll try flake8 on tumbleweed.
> 
>> Thanks,
>> Martin
>>
>> P.S. I'm going to merge Sphinx branch this Wednesday, so then we should port 
>> your
>> conversion scripts to emit .rst instead of .texi.
> 
> should be good - I'll complete the rst output in the scripts,
> 
> regards,
> Gaius

Hi.

As you probably noticed, the Sphinx migration didn't go well. However, it's 
still up to you
if you want to use it or not for Modula 2. We have manuals like libgccjit, or 
Ada manuals
that use RST natively and provide exported .texi files.

Cheers and sorry for the troubles I caused.

Martin


Re: [PATCH v2 16/19] modula2 front end: bootstrap and documentation tools

2022-11-08 Thread Gaius Mulley via Gcc-patches
Martin Liška  writes:

> 1) I would prefer using ' instead of ":
>
> $ flake8 ./gcc/m2/tools-src/tidydates.py
> ...
> ./gcc/m2/tools-src/tidydates.py:124:30: Q000 Double quotes found but single 
> quotes preferred
> ./gcc/m2/tools-src/tidydates.py:127:27: Q000 Double quotes found but single 
> quotes preferred
> ./gcc/m2/tools-src/tidydates.py:132:27: Q000 Double quotes found but single 
> quotes preferred
> ./gcc/m2/tools-src/tidydates.py:133:33: Q000 Double quotes found but single 
> quotes preferred
> ./gcc/m2/tools-src/tidydates.py:138:26: Q000 Double quotes found but single 
> quotes preferred
> ./gcc/m2/tools-src/tidydates.py:143:28: Q000 Double quotes found but
> single quotes preferred

ah yes will switch the quotes character.

> 2) Python-names would be nicer:
>
> def writeTemplate(fo, magic, start, end, dates, contribution, summary,
> lic):
>
> def write_template(...)

agreed, will change

> 3) def hasExt(name, ext) - please use Path from pathlib
>
> 4) while (str.find(line, "(*") != -1):
>
> '(*' in line
> ? Similarly elsewhere.
>
> 5) str.find(line, ...)
>
> Use rather directly: line.find(...)
>
> 6) please use flake8:
> https://gcc.gnu.org/codingconventions.html#python

sure will do all above - I used flake8 but maybe the plugins weren't
enabled.  I'll try flake8 on tumbleweed.

> Thanks,
> Martin
>
> P.S. I'm going to merge Sphinx branch this Wednesday, so then we should port 
> your
> conversion scripts to emit .rst instead of .texi.

should be good - I'll complete the rst output in the scripts,

regards,
Gaius


Re: [PATCH v2 16/19] modula2 front end: bootstrap and documentation tools

2022-11-07 Thread Martin Liška
On 11/7/22 14:09, Gaius Mulley wrote:
> 
> Hi Martin,
> 
> here is the revised patch having applied all previous recommendations:
> 
>   https://gcc.gnu.org/pipermail/gcc-patches/2022-October/603436.html

Hi.

>   
> Is this ok now?  Thanks for the improvement suggestions (argparse
> results in fewer lines of code :-)

Thanks, much better, however some comments are still not addressed:

1) I would prefer using ' instead of ":

$ flake8 ./gcc/m2/tools-src/tidydates.py
...
./gcc/m2/tools-src/tidydates.py:124:30: Q000 Double quotes found but single 
quotes preferred
./gcc/m2/tools-src/tidydates.py:127:27: Q000 Double quotes found but single 
quotes preferred
./gcc/m2/tools-src/tidydates.py:132:27: Q000 Double quotes found but single 
quotes preferred
./gcc/m2/tools-src/tidydates.py:133:33: Q000 Double quotes found but single 
quotes preferred
./gcc/m2/tools-src/tidydates.py:138:26: Q000 Double quotes found but single 
quotes preferred
./gcc/m2/tools-src/tidydates.py:143:28: Q000 Double quotes found but single 
quotes preferred

2) Python-names would be nicer:

def writeTemplate(fo, magic, start, end, dates, contribution, summary, lic):

def write_template(...)

3) def hasExt(name, ext) - please use Path from pathlib

4) while (str.find(line, "(*") != -1):

'(*' in line
? Similarly elsewhere.

5) str.find(line, ...)

Use rather directly: line.find(...)

6) please use flake8:
https://gcc.gnu.org/codingconventions.html#python

Thanks,
Martin

P.S. I'm going to merge Sphinx branch this Wednesday, so then we should port 
your
conversion scripts to emit .rst instead of .texi.

> 
> regards,
> Gaius
> 
>  
> --8<--8<--8<--8<--8<--8< 
> diff -ruw /dev/null gcc-git-devel-modula2/mli...@suse.cz
> diff -ruw /dev/null gcc-git-devel-modula2/gcc/m2/tools-src/tidydates.py
> --- /dev/null 2022-08-24 16:22:16.88870 +0100
> +++ gcc-git-devel-modula2/gcc/m2/tools-src/tidydates.py   2022-11-05 
> 17:33:53.685584357 +
> @@ -0,0 +1,166 @@
> +#!/usr/bin/env python3
> +
> +# utility to tidy dates and detect lack of copyright.
> +
> +# Copyright (C) 2016-2022 Free Software Foundation, Inc.
> +#
> +# This file is part of GNU Modula-2.
> +#
> +# GNU Modula-2 is free software; you can redistribute it and/or modify
> +# it under the terms of the GNU General Public License as published by
> +# the Free Software Foundation; either version 3, or (at your option)
> +# any later version.
> +#
> +# GNU Modula-2 is distributed in the hope that it will be useful,
> +# but WITHOUT ANY WARRANTY; without even the implied warranty of
> +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
> +# GNU General Public License for more details.
> +#
> +# You should have received a copy of the GNU General Public License
> +# along with GNU Modula-2; see the file COPYING.  If not, write to the
> +# Free Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA
> +# 02110-1301, USA.
> +
> +import os
> +import sys
> +import pathlib
> +import shutil
> +
> +maxLineLength = 60
> +
> +COPYRIGHT = "Copyright (C)"
> +
> +
> +def visitDir(directory, ext, func):
> +# visitDir - call func for each file below, dir, matching extension, ext.
> +listOfFiles = os.listdir(directory)
> +listOfFiles.sort()
> +for filename in listOfFiles:
> +path = pathlib.PurePath(filename)
> +full = os.path.join(directory, filename)
> +if path.is_file(full):
> +if path.suffix == ext:
> +func(full)
> +elif path.is_dir(full):
> +visitDir(full, ext, func)
> +
> +
> +def isYear(year):
> +# isYear - returns True if, year, is legal.
> +if len(year) == 5:
> +year = year[:-1]
> +for c in year:
> +if not c.isdigit():
> +return False
> +return True
> +
> +
> +def handleCopyright(outfile, lines, n, leader1, leader2):
> +# handleCopyright look for Copyright in the comment.
> +global maxLineLength
> +i = lines[n]
> +c = i.find(COPYRIGHT)+len(COPYRIGHT)
> +outfile.write(i[:c])
> +d = i[c:].split()
> +start = c
> +seenDate = True
> +years = []
> +while seenDate:
> +if d == []:
> +n += 1
> +i = lines[n]
> +d = i[2:].split()
> +else:
> +e = d[0]
> +punctuation = ""
> +if len(d) == 1:
> +d = []
> +else:
> +d = d[1:]
> +if c > maxLineLength:
> +outfile.write("\n")
> +outfile.write(leader1)
> +outfile.write(leader2)
> +outfile.write(" "*(start-2))
> +c = start
> +if isYear(e):
> +if (e[-1] == ".") or (e[-1] == ","):
> +punctuation = e[-1]
> +e = e[:-1]
> +else:
> +punctuation = ""
> +else:
> +seenDate = False

[PATCH v2 16/19] modula2 front end: bootstrap and documentation tools

2022-11-07 Thread Gaius Mulley via Gcc-patches


Hi Martin,

here is the revised patch having applied all previous recommendations:

  https://gcc.gnu.org/pipermail/gcc-patches/2022-October/603436.html
  
Is this ok now?  Thanks for the improvement suggestions (argparse
results in fewer lines of code :-)

regards,
Gaius

 
--8<--8<--8<--8<--8<--8< 
diff -ruw /dev/null gcc-git-devel-modula2/mli...@suse.cz
diff -ruw /dev/null gcc-git-devel-modula2/gcc/m2/tools-src/tidydates.py
--- /dev/null   2022-08-24 16:22:16.88870 +0100
+++ gcc-git-devel-modula2/gcc/m2/tools-src/tidydates.py 2022-11-05 
17:33:53.685584357 +
@@ -0,0 +1,166 @@
+#!/usr/bin/env python3
+
+# utility to tidy dates and detect lack of copyright.
+
+# Copyright (C) 2016-2022 Free Software Foundation, Inc.
+#
+# This file is part of GNU Modula-2.
+#
+# GNU Modula-2 is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3, or (at your option)
+# any later version.
+#
+# GNU Modula-2 is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with GNU Modula-2; see the file COPYING.  If not, write to the
+# Free Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA
+# 02110-1301, USA.
+
+import os
+import sys
+import pathlib
+import shutil
+
+maxLineLength = 60
+
+COPYRIGHT = "Copyright (C)"
+
+
+def visitDir(directory, ext, func):
+# visitDir - call func for each file below, dir, matching extension, ext.
+listOfFiles = os.listdir(directory)
+listOfFiles.sort()
+for filename in listOfFiles:
+path = pathlib.PurePath(filename)
+full = os.path.join(directory, filename)
+if path.is_file(full):
+if path.suffix == ext:
+func(full)
+elif path.is_dir(full):
+visitDir(full, ext, func)
+
+
+def isYear(year):
+# isYear - returns True if, year, is legal.
+if len(year) == 5:
+year = year[:-1]
+for c in year:
+if not c.isdigit():
+return False
+return True
+
+
+def handleCopyright(outfile, lines, n, leader1, leader2):
+# handleCopyright look for Copyright in the comment.
+global maxLineLength
+i = lines[n]
+c = i.find(COPYRIGHT)+len(COPYRIGHT)
+outfile.write(i[:c])
+d = i[c:].split()
+start = c
+seenDate = True
+years = []
+while seenDate:
+if d == []:
+n += 1
+i = lines[n]
+d = i[2:].split()
+else:
+e = d[0]
+punctuation = ""
+if len(d) == 1:
+d = []
+else:
+d = d[1:]
+if c > maxLineLength:
+outfile.write("\n")
+outfile.write(leader1)
+outfile.write(leader2)
+outfile.write(" "*(start-2))
+c = start
+if isYear(e):
+if (e[-1] == ".") or (e[-1] == ","):
+punctuation = e[-1]
+e = e[:-1]
+else:
+punctuation = ""
+else:
+seenDate = False
+if seenDate:
+if not (e in years):
+c += len(e) + len(punctuation)
+outfile.write(" ")
+outfile.write(e)
+outfile.write(punctuation)
+years += [e]
+else:
+if start < c:
+outfile.write("\n")
+outfile.write(leader1)
+outfile.write(leader2)
+outfile.write(" "*(start-2))
+
+outfile.write(" ")
+outfile.write(e)
+outfile.write(punctuation)
+for w in d:
+outfile.write(" ")
+outfile.write(w)
+outfile.write("\n")
+return outfile, n+1
+
+
+def handleHeader(filename, leader1, leader2):
+# handleHeader reads in the header of a file and inserts
+# a line break around the Copyright dates.
+print("--")
+lines = open(filename, "r").readlines()
+if len(lines) > 20:
+with open("tmptidy", "w") as outfile:
+n = 0
+for i in lines:
+if i.find("Copyright (C)") >= 0:
+outfile, n = handleCopyright(outfile, lines,
+ n, leader1, leader2)
+outfile.writelines(lines[n:])
+outfile.close()
+print("-> mv tmptidy", filename)
+shutil.move("tmptidy", filename)
+