You can subscribe to this list here.
2000 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
(1) |
Nov
(107) |
Dec
(67) |
---|---|---|---|---|---|---|---|---|---|---|---|---|
2001 |
Jan
(76) |
Feb
(125) |
Mar
(72) |
Apr
(13) |
May
(18) |
Jun
(12) |
Jul
(129) |
Aug
(47) |
Sep
(1) |
Oct
(36) |
Nov
(128) |
Dec
(124) |
2002 |
Jan
(59) |
Feb
|
Mar
(14) |
Apr
(14) |
May
(72) |
Jun
(9) |
Jul
(3) |
Aug
(5) |
Sep
(18) |
Oct
(65) |
Nov
(28) |
Dec
(12) |
2003 |
Jan
(10) |
Feb
(2) |
Mar
(4) |
Apr
(33) |
May
(21) |
Jun
(9) |
Jul
(29) |
Aug
(34) |
Sep
(4) |
Oct
(8) |
Nov
(15) |
Dec
(4) |
2004 |
Jan
(26) |
Feb
(12) |
Mar
(11) |
Apr
(9) |
May
(7) |
Jun
|
Jul
(5) |
Aug
|
Sep
(3) |
Oct
(7) |
Nov
(1) |
Dec
(10) |
2005 |
Jan
(2) |
Feb
(72) |
Mar
(16) |
Apr
(39) |
May
(48) |
Jun
(97) |
Jul
(57) |
Aug
(13) |
Sep
(16) |
Oct
(24) |
Nov
(100) |
Dec
(24) |
2006 |
Jan
(15) |
Feb
(34) |
Mar
(33) |
Apr
(31) |
May
(79) |
Jun
(64) |
Jul
(41) |
Aug
(64) |
Sep
(31) |
Oct
(46) |
Nov
(55) |
Dec
(37) |
2007 |
Jan
(32) |
Feb
(61) |
Mar
(11) |
Apr
(58) |
May
(46) |
Jun
(30) |
Jul
(94) |
Aug
(93) |
Sep
(86) |
Oct
(69) |
Nov
(125) |
Dec
(177) |
2008 |
Jan
(169) |
Feb
(97) |
Mar
(74) |
Apr
(113) |
May
(120) |
Jun
(334) |
Jul
(215) |
Aug
(237) |
Sep
(72) |
Oct
(189) |
Nov
(126) |
Dec
(160) |
2009 |
Jan
(180) |
Feb
(45) |
Mar
(98) |
Apr
(140) |
May
(151) |
Jun
(71) |
Jul
(107) |
Aug
(119) |
Sep
(73) |
Oct
(121) |
Nov
(14) |
Dec
(6) |
2010 |
Jan
(13) |
Feb
(9) |
Mar
(10) |
Apr
(64) |
May
(3) |
Jun
(16) |
Jul
(7) |
Aug
(23) |
Sep
(17) |
Oct
(37) |
Nov
(5) |
Dec
(8) |
2011 |
Jan
(10) |
Feb
(11) |
Mar
(77) |
Apr
(11) |
May
(2) |
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
From: <pj...@us...> - 2008-08-29 21:08:55
|
Revision: 5271 http://jython.svn.sourceforge.net/jython/?rev=5271&view=rev Author: pjenvey Date: 2008-08-29 21:08:52 +0000 (Fri, 29 Aug 2008) Log Message: ----------- PEP 338 (jython -m mod) support patch from Georgy Berdyshev Modified Paths: -------------- trunk/jython/src/org/python/util/jython.java Modified: trunk/jython/src/org/python/util/jython.java =================================================================== --- trunk/jython/src/org/python/util/jython.java 2008-08-29 20:41:41 UTC (rev 5270) +++ trunk/jython/src/org/python/util/jython.java 2008-08-29 21:08:52 UTC (rev 5271) @@ -26,11 +26,12 @@ public class jython { private static final String COPYRIGHT = - "Type \"help\", \"copyright\", \"credits\" or \"license\" for more information."; + "Type \"help\", \"copyright\", \"credits\" or \"license\" for more information."; - private static final String usage = - // "usage: jython [option] ... [-c cmd | -m mod | file | -] [arg] ...\n" + - "usage: jython [option] ... [-c cmd | file | -] [arg] ...\n" + + static final String usageHeader = + "usage: jython [option] ... [-c cmd | -m mod | file | -] [arg] ...\n"; + + private static final String usage = usageHeader + "Options and arguments:\n" + //(and corresponding environment variables):\n" + "-c cmd : program passed in as string (terminates option list)\n" + //"-d : debug output from parser (also PYTHONDEBUG=x)\n" + @@ -120,7 +121,10 @@ System.err.println(InteractiveConsole.getDefaultBanner()); System.exit(0); } - System.err.println(usage); + if (!opts.runModule) { + System.err.println(usage); + } + int exitcode = opts.help ? 0 : -1; System.exit(exitcode); } @@ -147,14 +151,14 @@ } // Print banner and copyright information (or not) - if (opts.interactive && opts.notice) { + if (opts.interactive && opts.notice && !opts.runModule) { System.err.println(InteractiveConsole.getDefaultBanner()); } if (Options.importSite) { try { imp.load("site"); - if (opts.interactive && opts.notice) { + if (opts.interactive && opts.notice && !opts.runModule) { System.err.println(COPYRIGHT); } } catch (PyException pye) { @@ -253,6 +257,21 @@ Py.printException(t); } } + + if (opts.moduleName != null) { + // PEP 338 - Execute module as a script + try { + interp.exec("import runpy"); + interp.set("name", Py.newString(opts.moduleName)); + interp.exec("runpy.run_module(name, run_name='__main__', alter_sys=True)"); + interp.cleanup(); + System.exit(0); + } catch (Throwable t) { + Py.printException(t); + interp.cleanup(); + System.exit(0); + } + } } if (opts.fixInteractive || (opts.filename == null && opts.command == null)) { @@ -308,6 +327,7 @@ { public String filename; public boolean jar, interactive, notice; + public boolean runModule; public boolean fixInteractive; public boolean help, version; public String[] argv; @@ -316,11 +336,13 @@ public java.util.Vector warnoptions = new java.util.Vector(); public String encoding; public String division; + public String moduleName; public CommandLineOptions() { filename = null; jar = fixInteractive = false; interactive = notice = true; + runModule = false; properties = new java.util.Properties(); help = version = false; } @@ -412,6 +434,20 @@ else division = args[++index]; } + else if (arg.startsWith("-m")) { + runModule = true; + if ((index + 1) < args.length) { + moduleName = args[++index]; + } else { + System.err.println("Argument expected for the -m option"); + System.err.print(jython.usageHeader); + System.err.println("Try `jython -h' for more information."); + return false; + } + if (!fixInteractive) { + interactive = false; + } + } else { String opt = args[index]; if (opt.startsWith("--")) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <nr...@us...> - 2008-08-29 20:41:43
|
Revision: 5270 http://jython.svn.sourceforge.net/jython/?rev=5270&view=rev Author: nriley Date: 2008-08-29 20:41:41 +0000 (Fri, 29 Aug 2008) Log Message: ----------- Revert stubbed out bit from r5210. Modified Paths: -------------- trunk/jython/src/org/python/util/jython.java Modified: trunk/jython/src/org/python/util/jython.java =================================================================== --- trunk/jython/src/org/python/util/jython.java 2008-08-29 19:58:06 UTC (rev 5269) +++ trunk/jython/src/org/python/util/jython.java 2008-08-29 20:41:41 UTC (rev 5270) @@ -212,7 +212,7 @@ } catch (java.io.FileNotFoundException e) { throw Py.IOError(e); } - if (false) {//(imp.load("os").__getattr__("isatty").__call__(Py.java2py(file.getFD())).__nonzero__()) { + if (imp.load("os").__getattr__("isatty").__call__(Py.java2py(file.getFD())).__nonzero__()) { opts.interactive = true; interp.interact(null, new PyFile(file)); System.exit(0); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <nr...@us...> - 2008-08-29 19:58:09
|
Revision: 5269 http://jython.svn.sourceforge.net/jython/?rev=5269&view=rev Author: nriley Date: 2008-08-29 19:58:06 +0000 (Fri, 29 Aug 2008) Log Message: ----------- Raise ImportError when attempting to import pwd, grp modules on Windows. Fixes test_tarfile. Modified Paths: -------------- trunk/jython/Lib/grp.py trunk/jython/Lib/pwd.py Modified: trunk/jython/Lib/grp.py =================================================================== --- trunk/jython/Lib/grp.py 2008-08-29 19:56:54 UTC (rev 5268) +++ trunk/jython/Lib/grp.py 2008-08-29 19:58:06 UTC (rev 5269) @@ -17,9 +17,12 @@ __all__ = ['getgrgid', 'getgrnam', 'getgrall'] -from os import _posix +from os import _name, _posix from java.lang import NullPointerException +if _name == 'nt': + raise ImportError, 'grp module not supported on Windows' + class struct_group(tuple): """ grp.struct_group: Results from getgr*() routines. Modified: trunk/jython/Lib/pwd.py =================================================================== --- trunk/jython/Lib/pwd.py 2008-08-29 19:56:54 UTC (rev 5268) +++ trunk/jython/Lib/pwd.py 2008-08-29 19:58:06 UTC (rev 5269) @@ -10,9 +10,12 @@ __all__ = ['getpwuid', 'getpwnam', 'getpwall'] -from os import _posix +from os import _name, _posix from java.lang import NullPointerException +if _name == 'nt': + raise ImportError, 'pwd module not supported on Windows' + class struct_passwd(tuple): """ pwd.struct_passwd: Results from getpw*() routines. This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <nr...@us...> - 2008-08-29 19:56:57
|
Revision: 5268 http://jython.svn.sourceforge.net/jython/?rev=5268&view=rev Author: nriley Date: 2008-08-29 19:56:54 +0000 (Fri, 29 Aug 2008) Log Message: ----------- Fix some mispasted docstrings in the grp module. Modified Paths: -------------- trunk/jython/Lib/grp.py Modified: trunk/jython/Lib/grp.py =================================================================== --- trunk/jython/Lib/grp.py 2008-08-29 19:55:43 UTC (rev 5267) +++ trunk/jython/Lib/grp.py 2008-08-29 19:56:54 UTC (rev 5268) @@ -1,5 +1,5 @@ """ -"Access to the Unix group database. +Access to the Unix group database. Group entries are reported as 4-tuples containing the following fields from the group database, in order: @@ -45,7 +45,7 @@ """ getgrgid(id) -> tuple Return the group database entry for the given numeric group ID. If - id is not valid, raise KeyError."}, + id is not valid, raise KeyError. """ try: return struct_group(_posix.getgrgid(uid)) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <nr...@us...> - 2008-08-29 19:55:46
|
Revision: 5267 http://jython.svn.sourceforge.net/jython/?rev=5267&view=rev Author: nriley Date: 2008-08-29 19:55:43 +0000 (Fri, 29 Aug 2008) Log Message: ----------- Correct file position after truncate; similar to CPython's bug <http://bugs.python.org/issue801631>. Fixes test_file on Windows. Modified Paths: -------------- trunk/jython/src/org/python/core/io/FileIO.java Modified: trunk/jython/src/org/python/core/io/FileIO.java =================================================================== --- trunk/jython/src/org/python/core/io/FileIO.java 2008-08-29 19:53:04 UTC (rev 5266) +++ trunk/jython/src/org/python/core/io/FileIO.java 2008-08-29 19:55:43 UTC (rev 5267) @@ -313,7 +313,10 @@ checkClosed(); checkWritable(); try { + long oldPosition = fileChannel.position(); fileChannel.truncate(size); + // seek necessary on Windows only, see <http://bugs.python.org/issue801631> + fileChannel.position(oldPosition); } catch (IOException ioe) { throw Py.IOError(ioe); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <nr...@us...> - 2008-08-29 19:53:07
|
Revision: 5266 http://jython.svn.sourceforge.net/jython/?rev=5266&view=rev Author: nriley Date: 2008-08-29 19:53:04 +0000 (Fri, 29 Aug 2008) Log Message: ----------- Close file immediately after comparing it. Fixes test_filecmp on Windows. Modified Paths: -------------- trunk/jython/CPythonLib.includes trunk/jython/Lib/filecmp.py Modified: trunk/jython/CPythonLib.includes =================================================================== --- trunk/jython/CPythonLib.includes 2008-08-29 19:51:57 UTC (rev 5265) +++ trunk/jython/CPythonLib.includes 2008-08-29 19:53:04 UTC (rev 5266) @@ -52,7 +52,6 @@ dospath.py dumbdbm.py exceptions.py -filecmp.py fileinput.py fnmatch.py formatter.py Modified: trunk/jython/Lib/filecmp.py =================================================================== --- trunk/jython/Lib/filecmp.py 2008-08-29 19:51:57 UTC (rev 5265) +++ trunk/jython/Lib/filecmp.py 2008-08-29 19:53:04 UTC (rev 5266) @@ -65,13 +65,17 @@ bufsize = BUFSIZE fp1 = open(f1, 'rb') fp2 = open(f2, 'rb') - while True: - b1 = fp1.read(bufsize) - b2 = fp2.read(bufsize) - if b1 != b2: - return False - if not b1: - return True + try: + while True: + b1 = fp1.read(bufsize) + b2 = fp2.read(bufsize) + if b1 != b2: + return False + if not b1: + return True + finally: + fp1.close() + fp2.close() # Directory comparison class. # This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <nr...@us...> - 2008-08-29 19:52:02
|
Revision: 5265 http://jython.svn.sourceforge.net/jython/?rev=5265&view=rev Author: nriley Date: 2008-08-29 19:51:57 +0000 (Fri, 29 Aug 2008) Log Message: ----------- filecmp.py from http://svn.python.org/projects/python/branches/release25-maint/Lib/filecmp.py r66059 Added Paths: ----------- trunk/jython/Lib/filecmp.py Added: trunk/jython/Lib/filecmp.py =================================================================== --- trunk/jython/Lib/filecmp.py (rev 0) +++ trunk/jython/Lib/filecmp.py 2008-08-29 19:51:57 UTC (rev 5265) @@ -0,0 +1,297 @@ +"""Utilities for comparing files and directories. + +Classes: + dircmp + +Functions: + cmp(f1, f2, shallow=1) -> int + cmpfiles(a, b, common) -> ([], [], []) + +""" + +import os +import stat +import warnings +from itertools import ifilter, ifilterfalse, imap, izip + +__all__ = ["cmp","dircmp","cmpfiles"] + +_cache = {} +BUFSIZE=8*1024 + +def cmp(f1, f2, shallow=1): + """Compare two files. + + Arguments: + + f1 -- First file name + + f2 -- Second file name + + shallow -- Just check stat signature (do not read the files). + defaults to 1. + + Return value: + + True if the files are the same, False otherwise. + + This function uses a cache for past comparisons and the results, + with a cache invalidation mechanism relying on stale signatures. + + """ + + s1 = _sig(os.stat(f1)) + s2 = _sig(os.stat(f2)) + if s1[0] != stat.S_IFREG or s2[0] != stat.S_IFREG: + return False + if shallow and s1 == s2: + return True + if s1[1] != s2[1]: + return False + + result = _cache.get((f1, f2)) + if result and (s1, s2) == result[:2]: + return result[2] + outcome = _do_cmp(f1, f2) + _cache[f1, f2] = s1, s2, outcome + return outcome + +def _sig(st): + return (stat.S_IFMT(st.st_mode), + st.st_size, + st.st_mtime) + +def _do_cmp(f1, f2): + bufsize = BUFSIZE + fp1 = open(f1, 'rb') + fp2 = open(f2, 'rb') + while True: + b1 = fp1.read(bufsize) + b2 = fp2.read(bufsize) + if b1 != b2: + return False + if not b1: + return True + +# Directory comparison class. +# +class dircmp: + """A class that manages the comparison of 2 directories. + + dircmp(a,b,ignore=None,hide=None) + A and B are directories. + IGNORE is a list of names to ignore, + defaults to ['RCS', 'CVS', 'tags']. + HIDE is a list of names to hide, + defaults to [os.curdir, os.pardir]. + + High level usage: + x = dircmp(dir1, dir2) + x.report() -> prints a report on the differences between dir1 and dir2 + or + x.report_partial_closure() -> prints report on differences between dir1 + and dir2, and reports on common immediate subdirectories. + x.report_full_closure() -> like report_partial_closure, + but fully recursive. + + Attributes: + left_list, right_list: The files in dir1 and dir2, + filtered by hide and ignore. + common: a list of names in both dir1 and dir2. + left_only, right_only: names only in dir1, dir2. + common_dirs: subdirectories in both dir1 and dir2. + common_files: files in both dir1 and dir2. + common_funny: names in both dir1 and dir2 where the type differs between + dir1 and dir2, or the name is not stat-able. + same_files: list of identical files. + diff_files: list of filenames which differ. + funny_files: list of files which could not be compared. + subdirs: a dictionary of dircmp objects, keyed by names in common_dirs. + """ + + def __init__(self, a, b, ignore=None, hide=None): # Initialize + self.left = a + self.right = b + if hide is None: + self.hide = [os.curdir, os.pardir] # Names never to be shown + else: + self.hide = hide + if ignore is None: + self.ignore = ['RCS', 'CVS', 'tags'] # Names ignored in comparison + else: + self.ignore = ignore + + def phase0(self): # Compare everything except common subdirectories + self.left_list = _filter(os.listdir(self.left), + self.hide+self.ignore) + self.right_list = _filter(os.listdir(self.right), + self.hide+self.ignore) + self.left_list.sort() + self.right_list.sort() + + def phase1(self): # Compute common names + a = dict(izip(imap(os.path.normcase, self.left_list), self.left_list)) + b = dict(izip(imap(os.path.normcase, self.right_list), self.right_list)) + self.common = map(a.__getitem__, ifilter(b.has_key, a)) + self.left_only = map(a.__getitem__, ifilterfalse(b.has_key, a)) + self.right_only = map(b.__getitem__, ifilterfalse(a.has_key, b)) + + def phase2(self): # Distinguish files, directories, funnies + self.common_dirs = [] + self.common_files = [] + self.common_funny = [] + + for x in self.common: + a_path = os.path.join(self.left, x) + b_path = os.path.join(self.right, x) + + ok = 1 + try: + a_stat = os.stat(a_path) + except os.error, why: + # print 'Can\'t stat', a_path, ':', why[1] + ok = 0 + try: + b_stat = os.stat(b_path) + except os.error, why: + # print 'Can\'t stat', b_path, ':', why[1] + ok = 0 + + if ok: + a_type = stat.S_IFMT(a_stat.st_mode) + b_type = stat.S_IFMT(b_stat.st_mode) + if a_type != b_type: + self.common_funny.append(x) + elif stat.S_ISDIR(a_type): + self.common_dirs.append(x) + elif stat.S_ISREG(a_type): + self.common_files.append(x) + else: + self.common_funny.append(x) + else: + self.common_funny.append(x) + + def phase3(self): # Find out differences between common files + xx = cmpfiles(self.left, self.right, self.common_files) + self.same_files, self.diff_files, self.funny_files = xx + + def phase4(self): # Find out differences between common subdirectories + # A new dircmp object is created for each common subdirectory, + # these are stored in a dictionary indexed by filename. + # The hide and ignore properties are inherited from the parent + self.subdirs = {} + for x in self.common_dirs: + a_x = os.path.join(self.left, x) + b_x = os.path.join(self.right, x) + self.subdirs[x] = dircmp(a_x, b_x, self.ignore, self.hide) + + def phase4_closure(self): # Recursively call phase4() on subdirectories + self.phase4() + for sd in self.subdirs.itervalues(): + sd.phase4_closure() + + def report(self): # Print a report on the differences between a and b + # Output format is purposely lousy + print 'diff', self.left, self.right + if self.left_only: + self.left_only.sort() + print 'Only in', self.left, ':', self.left_only + if self.right_only: + self.right_only.sort() + print 'Only in', self.right, ':', self.right_only + if self.same_files: + self.same_files.sort() + print 'Identical files :', self.same_files + if self.diff_files: + self.diff_files.sort() + print 'Differing files :', self.diff_files + if self.funny_files: + self.funny_files.sort() + print 'Trouble with common files :', self.funny_files + if self.common_dirs: + self.common_dirs.sort() + print 'Common subdirectories :', self.common_dirs + if self.common_funny: + self.common_funny.sort() + print 'Common funny cases :', self.common_funny + + def report_partial_closure(self): # Print reports on self and on subdirs + self.report() + for sd in self.subdirs.itervalues(): + print + sd.report() + + def report_full_closure(self): # Report on self and subdirs recursively + self.report() + for sd in self.subdirs.itervalues(): + print + sd.report_full_closure() + + methodmap = dict(subdirs=phase4, + same_files=phase3, diff_files=phase3, funny_files=phase3, + common_dirs = phase2, common_files=phase2, common_funny=phase2, + common=phase1, left_only=phase1, right_only=phase1, + left_list=phase0, right_list=phase0) + + def __getattr__(self, attr): + if attr not in self.methodmap: + raise AttributeError, attr + self.methodmap[attr](self) + return getattr(self, attr) + +def cmpfiles(a, b, common, shallow=1): + """Compare common files in two directories. + + a, b -- directory names + common -- list of file names found in both directories + shallow -- if true, do comparison based solely on stat() information + + Returns a tuple of three lists: + files that compare equal + files that are different + filenames that aren't regular files. + + """ + res = ([], [], []) + for x in common: + ax = os.path.join(a, x) + bx = os.path.join(b, x) + res[_cmp(ax, bx, shallow)].append(x) + return res + + +# Compare two files. +# Return: +# 0 for equal +# 1 for different +# 2 for funny cases (can't stat, etc.) +# +def _cmp(a, b, sh, abs=abs, cmp=cmp): + try: + return not abs(cmp(a, b, sh)) + except os.error: + return 2 + + +# Return a copy with items that occur in skip removed. +# +def _filter(flist, skip): + return list(ifilterfalse(skip.__contains__, flist)) + + +# Demonstration and testing. +# +def demo(): + import sys + import getopt + options, args = getopt.getopt(sys.argv[1:], 'r') + if len(args) != 2: + raise getopt.GetoptError('need exactly two args', None) + dd = dircmp(args[0], args[1]) + if ('-r', '') in options: + dd.report_full_closure() + else: + dd.report() + +if __name__ == '__main__': + demo() This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fwi...@us...> - 2008-08-29 13:47:25
|
Revision: 5264 http://jython.svn.sourceforge.net/jython/?rev=5264&view=rev Author: fwierzbicki Date: 2008-08-29 13:47:16 +0000 (Fri, 29 Aug 2008) Log Message: ----------- Merged revisions 5210,5216-5220,5223-5226,5228,5230,5236-5261 via svnmerge from https://jython.svn.sourceforge.net/svnroot/jython/branches/nowalker ........ r5210 | fwierzbicki | 2008-08-19 17:43:06 -0400 (Tue, 19 Aug 2008) | 5 lines Work to date on the one pass grammar. Not ready for others to look at really. If you really want to try it note that you need to comment out parts of site.py and os.py to get things to work. They *almost* parse and compile, but not quite, and they are basic dependencies for Jython to run. ........ r5216 | fwierzbicki | 2008-08-20 08:10:26 -0400 (Wed, 20 Aug 2008) | 2 lines Much better BoolOp. ........ r5217 | fwierzbicki | 2008-08-20 10:06:30 -0400 (Wed, 20 Aug 2008) | 2 lines Fix "del". ........ r5218 | fwierzbicki | 2008-08-20 10:39:21 -0400 (Wed, 20 Aug 2008) | 2 lines Dict support. ........ r5219 | fwierzbicki | 2008-08-20 11:23:14 -0400 (Wed, 20 Aug 2008) | 2 lines Conditional Expression support. ........ r5220 | fwierzbicki | 2008-08-20 11:37:02 -0400 (Wed, 20 Aug 2008) | 2 lines repr support. ........ r5223 | fwierzbicki | 2008-08-20 15:57:39 -0400 (Wed, 20 Aug 2008) | 2 lines Start of list comprehensions and generator expressions. ........ r5224 | fwierzbicki | 2008-08-20 15:58:17 -0400 (Wed, 20 Aug 2008) | 2 lines oops revert build.xml ........ r5225 | fwierzbicki | 2008-08-20 16:57:09 -0400 (Wed, 20 Aug 2008) | 2 lines re-remove PythonWalker.g from build ........ r5226 | fwierzbicki | 2008-08-20 16:59:44 -0400 (Wed, 20 Aug 2008) | 2 lines gen expressions and list comps now actually work... ........ r5228 | fwierzbicki | 2008-08-20 22:58:24 -0400 (Wed, 20 Aug 2008) | 2 lines debugging of some expr_contextType values. ........ r5230 | fwierzbicki | 2008-08-20 23:47:32 -0400 (Wed, 20 Aug 2008) | 2 lines bugfix on exception and on assign value expr_contextType. ........ r5236 | fwierzbicki | 2008-08-22 19:03:45 -0400 (Fri, 22 Aug 2008) | 2 lines Bugfix for expr_contextType on assign values. ........ r5237 | fwierzbicki | 2008-08-22 22:33:48 -0400 (Fri, 22 Aug 2008) | 2 lines Add expr types to BaseTree children. ........ r5238 | fwierzbicki | 2008-08-23 15:19:16 -0400 (Sat, 23 Aug 2008) | 2 lines BinOp now works in one pass. ........ r5239 | fwierzbicki | 2008-08-23 15:43:19 -0400 (Sat, 23 Aug 2008) | 2 lines Fine tuning List and Assign col position. ........ r5240 | fwierzbicki | 2008-08-23 19:03:59 -0400 (Sat, 23 Aug 2008) | 5 lines Make PythonTree's toStringTree more easily comparable with ast/astview.py output. This will help with the walkerless Python.g, as it doesn't quite parse ast/astview.py yet. ........ r5241 | fwierzbicki | 2008-08-23 22:04:43 -0400 (Sat, 23 Aug 2008) | 2 lines Fix lambda without args. ........ r5242 | fwierzbicki | 2008-08-24 05:38:22 -0400 (Sun, 24 Aug 2008) | 2 lines check for PythonTree in makeStmts. ........ r5243 | fwierzbicki | 2008-08-25 10:21:29 -0400 (Mon, 25 Aug 2008) | 2 lines Fix generator expressions, rename all "stmts" in Python.g to "stypes". ........ r5244 | fwierzbicki | 2008-08-25 11:25:24 -0400 (Mon, 25 Aug 2008) | 2 lines Clean up creation of stmtType[] and exprType[]. ........ r5245 | fwierzbicki | 2008-08-25 14:44:46 -0400 (Mon, 25 Aug 2008) | 3 lines Fix build.xml (oops) Fix Generator Expression assignments and multi-statement simple_stmt. ........ r5246 | fwierzbicki | 2008-08-25 16:36:04 -0400 (Mon, 25 Aug 2008) | 3 lines Fixed fplist, subscripts (especially extslice) and enable Interactive and Expression (single and eval). regrtest.py is now running. ........ r5247 | fwierzbicki | 2008-08-25 17:18:03 -0400 (Mon, 25 Aug 2008) | 2 lines Fix ** ........ r5248 | fwierzbicki | 2008-08-25 22:04:27 -0400 (Mon, 25 Aug 2008) | 3 lines Cleanup: removal of comments, re-format of Python.g and removal of PYNODE. ........ r5249 | fwierzbicki | 2008-08-26 08:21:42 -0400 (Tue, 26 Aug 2008) | 3 lines Remove unnecessary constructor on BinOp (now it is just the generated version again) Remove some whitespace in Python.g ........ r5250 | fwierzbicki | 2008-08-26 11:05:19 -0400 (Tue, 26 Aug 2008) | 2 lines Moved makeSliceType code to GrammarActions. ........ r5251 | fwierzbicki | 2008-08-26 12:51:15 -0400 (Tue, 26 Aug 2008) | 2 lines Moved Subscript creation up a rule - fixed a bunch of unit tests. ........ r5252 | fwierzbicki | 2008-08-26 15:37:34 -0400 (Tue, 26 Aug 2008) | 2 lines Another expr_contextType adjustment. ........ r5253 | fwierzbicki | 2008-08-26 16:17:50 -0400 (Tue, 26 Aug 2008) | 2 lines checking for bad assignment statements. ........ r5254 | fwierzbicki | 2008-08-26 20:44:35 -0400 (Tue, 26 Aug 2008) | 3 lines Fix illegal Lambda statements and more illegal assigns. Also raise exceptions on illegal gen expression arguments. ........ r5255 | fwierzbicki | 2008-08-26 22:38:35 -0400 (Tue, 26 Aug 2008) | 2 lines Fix for FunctionDef and Call problems. ........ r5256 | fwierzbicki | 2008-08-26 22:47:56 -0400 (Tue, 26 Aug 2008) | 2 lines whitespace ........ r5257 | fwierzbicki | 2008-08-27 12:07:35 -0400 (Wed, 27 Aug 2008) | 2 lines revert build.xml after accidently checking in my local copy. ........ r5258 | fwierzbicki | 2008-08-27 15:51:16 -0400 (Wed, 27 Aug 2008) | 2 lines for not_test, replacing manual tree construction with ->. ........ r5259 | fwierzbicki | 2008-08-27 16:09:39 -0400 (Wed, 27 Aug 2008) | 2 lines TODO comment. ........ r5260 | fwierzbicki | 2008-08-27 16:35:54 -0400 (Wed, 27 Aug 2008) | 3 lines Removed XXX comments that no longer apply (special testlists don't seem to be needed). Removed unused c1 and c2 alias. ........ r5261 | fwierzbicki | 2008-08-27 16:51:19 -0400 (Wed, 27 Aug 2008) | 2 lines simplify testlist. ........ Modified Paths: -------------- trunk/jython/ast/asdl_antlr.py trunk/jython/build.xml trunk/jython/grammar/Python.g trunk/jython/src/org/python/antlr/ExpressionParser.java trunk/jython/src/org/python/antlr/GrammarActions.java trunk/jython/src/org/python/antlr/InteractiveParser.java trunk/jython/src/org/python/antlr/ModuleParser.java trunk/jython/src/org/python/antlr/ast/Assert.java trunk/jython/src/org/python/antlr/ast/Assign.java trunk/jython/src/org/python/antlr/ast/Attribute.java trunk/jython/src/org/python/antlr/ast/AugAssign.java trunk/jython/src/org/python/antlr/ast/BinOp.java trunk/jython/src/org/python/antlr/ast/Call.java trunk/jython/src/org/python/antlr/ast/Compare.java trunk/jython/src/org/python/antlr/ast/Exec.java trunk/jython/src/org/python/antlr/ast/Expr.java trunk/jython/src/org/python/antlr/ast/Expression.java trunk/jython/src/org/python/antlr/ast/For.java trunk/jython/src/org/python/antlr/ast/GeneratorExp.java trunk/jython/src/org/python/antlr/ast/If.java trunk/jython/src/org/python/antlr/ast/IfExp.java trunk/jython/src/org/python/antlr/ast/Index.java trunk/jython/src/org/python/antlr/ast/Lambda.java trunk/jython/src/org/python/antlr/ast/ListComp.java trunk/jython/src/org/python/antlr/ast/Print.java trunk/jython/src/org/python/antlr/ast/Raise.java trunk/jython/src/org/python/antlr/ast/Repr.java trunk/jython/src/org/python/antlr/ast/Return.java trunk/jython/src/org/python/antlr/ast/Slice.java trunk/jython/src/org/python/antlr/ast/Subscript.java trunk/jython/src/org/python/antlr/ast/UnaryOp.java trunk/jython/src/org/python/antlr/ast/While.java trunk/jython/src/org/python/antlr/ast/With.java trunk/jython/src/org/python/antlr/ast/Yield.java trunk/jython/src/org/python/antlr/ast/comprehensionType.java trunk/jython/src/org/python/antlr/ast/excepthandlerType.java trunk/jython/src/org/python/antlr/ast/keywordType.java trunk/jython/src/org/python/util/jython.java trunk/jython/tests/java/org/python/antlr/PythonTreeTester.java Removed Paths: ------------- trunk/jython/grammar/PythonWalker.g Property Changed: ---------------- trunk/jython/ Property changes on: trunk/jython ___________________________________________________________________ Modified: svnmerge-integrated - /branches/nowalker:1-5209 + /branches/nowalker:1-5263 Modified: trunk/jython/ast/asdl_antlr.py =================================================================== --- trunk/jython/ast/asdl_antlr.py 2008-08-29 12:14:12 UTC (rev 5263) +++ trunk/jython/ast/asdl_antlr.py 2008-08-29 13:47:16 UTC (rev 5264) @@ -260,12 +260,15 @@ if f.typedef is not None and f.typedef.simple: not_simple = False #For now ignoring String -- will want to revisit - if f.seq and not_simple and not fparg.startswith("String"): - self.emit("if (%s != null) {" % f.name, depth+1); - self.emit("for(int i%(name)s=0;i%(name)s<%(name)s.length;i%(name)s++) {" % {"name":f.name}, depth+2) - self.emit("addChild(%s[i%s]);" % (f.name, f.name), depth+3) - self.emit("}", depth+2) - self.emit("}", depth+1) + if not_simple and not fparg.startswith("String"): + if f.seq: + self.emit("if (%s != null) {" % f.name, depth+1); + self.emit("for(int i%(name)s=0;i%(name)s<%(name)s.length;i%(name)s++) {" % {"name":f.name}, depth+2) + self.emit("addChild(%s[i%s]);" % (f.name, f.name), depth+3) + self.emit("}", depth+2) + self.emit("}", depth+1) + elif str(f.type) == "expr": + self.emit("addChild(%s);" % (f.name), depth+1) def javaMethods(self, type, clsname, ctorname, fields, depth): # The java ctors Modified: trunk/jython/build.xml =================================================================== --- trunk/jython/build.xml 2008-08-29 12:14:12 UTC (rev 5263) +++ trunk/jython/build.xml 2008-08-29 13:47:16 UTC (rev 5264) @@ -434,7 +434,6 @@ <arg value="-lib"/> <arg path="${work.dir}/build/gensrc/org/python/antlr"/> <arg file="${jython.base.dir}/grammar/Python.g"/> - <arg file="${jython.base.dir}/grammar/PythonWalker.g"/> <arg file="${jython.base.dir}/grammar/PythonPartial.g"/> <classpath refid="main.classpath"/> </java> Modified: trunk/jython/grammar/Python.g =================================================================== --- trunk/jython/grammar/Python.g 2008-08-29 12:14:12 UTC (rev 5263) +++ trunk/jython/grammar/Python.g 2008-08-29 13:47:16 UTC (rev 5264) @@ -61,8 +61,7 @@ * grammar from Jim Baker. The current parsing and compiling strategy looks * like this: * - * Python source->Python.g->simple antlr AST->PythonWalker.g-> - * decorated AST (org/python/parser/ast/*)->CodeCompiler(ASM)->.class + * Python source->Python.g->AST (org/python/parser/ast/*)->CodeCompiler(ASM)->.class */ grammar Python; @@ -74,75 +73,6 @@ tokens { INDENT; DEDENT; - - Module; - Interactive; - Expression; - NameTok; - Test; - Msg; - Level; - Body; - Bases; - Arguments; - Args; - Arg; - Keyword; - StarArgs; - KWArgs; - Assign; - AugAssign; - Tuple; - List; - Dict; - IfExp; - TryExcept; - TryFinally; - ExceptHandler; - StrTok; - NumTok; - IsNot; - NotIn; - Type; - Inst; - Tback; - Globals; - Locals; - Ellipsis; - ListComp; - Repr; - Subscript; - SubscriptList; - Index; - Target; - Value; - Lower; - Upper; - Step; - UAdd; - USub; - Invert; - Alias; - Asname; - Decorators; - GeneratorExp; - Ifs; - Elts; - Call; - Dest; - Values; - Newline; - - FpList; - StepOp; - UpperOp; - - GenFor; - GenIf; - ListFor; - ListIf; - Parens; - Brackets; } @header { @@ -152,38 +82,82 @@ import org.python.antlr.ParseException; import org.python.antlr.PythonTree; +import org.python.antlr.ast.aliasType; import org.python.antlr.ast.argumentsType; +import org.python.antlr.ast.Assert; +import org.python.antlr.ast.Assign; import org.python.antlr.ast.Attribute; +import org.python.antlr.ast.AugAssign; +import org.python.antlr.ast.BinOp; +import org.python.antlr.ast.BoolOp; +import org.python.antlr.ast.boolopType; import org.python.antlr.ast.Break; +import org.python.antlr.ast.Call; +import org.python.antlr.ast.ClassDef; +import org.python.antlr.ast.cmpopType; +import org.python.antlr.ast.Compare; +import org.python.antlr.ast.comprehensionType; import org.python.antlr.ast.Context; import org.python.antlr.ast.Continue; +import org.python.antlr.ast.Delete; +import org.python.antlr.ast.Dict; +import org.python.antlr.ast.Ellipsis; +import org.python.antlr.ast.excepthandlerType; +import org.python.antlr.ast.Exec; import org.python.antlr.ast.Expr; +import org.python.antlr.ast.Expression; import org.python.antlr.ast.exprType; import org.python.antlr.ast.expr_contextType; +import org.python.antlr.ast.ExtSlice; +import org.python.antlr.ast.For; import org.python.antlr.ast.FunctionDef; +import org.python.antlr.ast.GeneratorExp; +import org.python.antlr.ast.Global; +import org.python.antlr.ast.If; +import org.python.antlr.ast.IfExp; +import org.python.antlr.ast.Import; +import org.python.antlr.ast.ImportFrom; +import org.python.antlr.ast.Index; +import org.python.antlr.ast.Interactive; +import org.python.antlr.ast.keywordType; +import org.python.antlr.ast.ListComp; +import org.python.antlr.ast.Lambda; import org.python.antlr.ast.modType; import org.python.antlr.ast.Module; import org.python.antlr.ast.Name; import org.python.antlr.ast.Num; +import org.python.antlr.ast.operatorType; import org.python.antlr.ast.Pass; import org.python.antlr.ast.Print; +import org.python.antlr.ast.Raise; +import org.python.antlr.ast.Repr; import org.python.antlr.ast.Return; +import org.python.antlr.ast.Slice; +import org.python.antlr.ast.sliceType; import org.python.antlr.ast.stmtType; import org.python.antlr.ast.Str; +import org.python.antlr.ast.Subscript; +import org.python.antlr.ast.TryExcept; +import org.python.antlr.ast.TryFinally; +import org.python.antlr.ast.Tuple; +import org.python.antlr.ast.unaryopType; +import org.python.antlr.ast.UnaryOp; +import org.python.antlr.ast.While; +import org.python.antlr.ast.With; +import org.python.antlr.ast.Yield; import org.python.core.Py; import org.python.core.PyString; import org.python.core.PyUnicode; import java.math.BigInteger; +import java.util.Collections; +import java.util.Iterator; +import java.util.ListIterator; } @members { - boolean debugOn = false; - private ErrorHandler errorHandler; - private boolean seenSingleOuterSuite = false; - private GrammarActions actions = new GrammarActions(); public void setErrorHandler(ErrorHandler eh) { @@ -191,12 +165,6 @@ actions.setErrorHandler(eh); } - private void debug(String message) { - if (debugOn) { - System.out.println(message); - } - } - protected void mismatch(IntStream input, int ttype, BitSet follow) throws RecognitionException { if (errorHandler.isRecoverable()) { super.mismatch(input, ttype, follow); @@ -243,7 +211,7 @@ int implicitLineJoiningLevel = 0; int startPos=-1; -//If you want to use another error recovery mechanisms change this +//If you want to use another error recovery mechanism change this //and the same one in the parser. private ErrorHandler errorHandler; @@ -291,23 +259,59 @@ } //single_input: NEWLINE | simple_stmt | compound_stmt NEWLINE -single_input : NEWLINE* EOF -> ^(Interactive) - | simple_stmt NEWLINE* EOF -> ^(Interactive simple_stmt) - | compound_stmt NEWLINE+ EOF -> ^(Interactive compound_stmt) - ; +single_input +@init { + modType mtype = null; +} +@after { + $single_input.tree = mtype; +} + : NEWLINE* EOF { + mtype = new Interactive($single_input.start, new stmtType[0]); + } + | simple_stmt NEWLINE* EOF { + mtype = new Interactive($single_input.start, actions.makeStmts($simple_stmt.stypes)); + } + | compound_stmt NEWLINE+ EOF { + mtype = new Interactive($single_input.start, actions.makeStmts($compound_stmt.tree)); + } + ; //file_input: (NEWLINE | stmt)* ENDMARKER -file_input : (NEWLINE | stmt)* EOF - -> ^(Module stmt*) - ; +file_input +@init { + modType mtype = null; + List stypes = new ArrayList(); +} +@after { + $file_input.tree = mtype; +} + : (NEWLINE + | stmt {stypes.addAll($stmt.stypes);} + )* { + mtype = new Module($file_input.start, actions.makeStmts(stypes)); + } + ; //eval_input: testlist NEWLINE* ENDMARKER -eval_input : LEADING_WS? (NEWLINE)* testlist[expr_contextType.Load] (NEWLINE)* EOF -> ^(Expression testlist) - ; +eval_input +@init { + modType mtype = null; +} +@after { + $eval_input.tree = mtype; +} + : LEADING_WS? (NEWLINE)* testlist[expr_contextType.Load] (NEWLINE)* EOF { + mtype = new Expression($eval_input.start, (exprType)$testlist.tree); + } + ; //not in CPython's Grammar file -dotted_attr - : NAME (DOT^ attr)* +dotted_attr returns [exprType etype] + : n1=NAME + ( (DOT n2+=dotted_attr)+ { $etype = actions.makeDottedAttr($n1, $n2); } + | { $etype = new Name($NAME, $NAME.text, expr_contextType.Load); } + ) ; //attr is here for Java compatibility. A Java foo.getIf() can be called from Jython as foo.if @@ -349,72 +353,145 @@ ; //decorator: '@' dotted_name [ '(' [arglist] ')' ] NEWLINE -decorator: AT dotted_attr - ( (LPAREN arglist? RPAREN) -> ^(AT dotted_attr ^(Call ^(Args arglist)?)) - | -> ^(AT dotted_attr) - ) NEWLINE - ; +decorator returns [exprType etype] +@after { + $decorator.tree = $etype; +} + : AT dotted_attr + ( LPAREN + ( arglist + { + $etype = actions.makeCall($LPAREN, $dotted_attr.etype, $arglist.args, $arglist.keywords, + $arglist.starargs, $arglist.kwargs); + } + | { + $etype = actions.makeCall($LPAREN, $dotted_attr.etype); + } + ) + RPAREN + | { + $etype = $dotted_attr.etype; + } + ) NEWLINE + ; //decorators: decorator+ -decorators: decorator+ - ; +decorators returns [List etypes] + : d+=decorator+ + { + $etypes = $d; + } + ; //funcdef: [decorators] 'def' NAME parameters ':' suite -funcdef : decorators? DEF NAME parameters COLON suite - -> ^(DEF NAME parameters ^(Body suite) ^(Decorators decorators?)) - ; +funcdef +@init { stmtType stype = null; } +@after { $funcdef.tree = stype; } + : decorators? DEF NAME parameters COLON suite + { + Token t = $DEF; + if ($decorators.start != null) { + t = $decorators.start; + } + stype = actions.makeFuncdef(t, $NAME, $parameters.args, $suite.stypes, $decorators.etypes); + } + ; //parameters: '(' [varargslist] ')' -parameters : LPAREN - (varargslist -> ^(Arguments varargslist) - | -> ^(Arguments) - ) - RPAREN - ; +parameters returns [argumentsType args] + : LPAREN + (varargslist {$args = $varargslist.args;} + | { $args = new argumentsType($parameters.start, new exprType[0], null, null, new exprType[0]); + } + ) + RPAREN + ; //not in CPython's Grammar file -defparameter : fpdef (ASSIGN test[expr_contextType.Load])? {debug("parsed defparameter");} - ; +defparameter[List defaults] returns [exprType etype] +@after { + $defparameter.tree = $etype; +} + : fpdef[expr_contextType.Param] (ASSIGN test[expr_contextType.Load])? + { + $etype = (exprType)$fpdef.tree; + if ($ASSIGN != null) { + defaults.add($test.tree); + } else if (!defaults.isEmpty()) { + throw new ParseException("non-default argument follows default argument", $fpdef.tree); + } + } + ; //varargslist: ((fpdef ['=' test] ',')* // ('*' NAME [',' '**' NAME] | '**' NAME) | // fpdef ['=' test] (',' fpdef ['=' test])* [',']) -varargslist : defparameter (options {greedy=true;}:COMMA defparameter)* - (COMMA - ( STAR starargs=NAME (COMMA DOUBLESTAR kwargs=NAME)? - | DOUBLESTAR kwargs=NAME - )? - )? {debug("parsed varargslist");} - -> ^(Args defparameter+) ^(StarArgs $starargs)? ^(KWArgs $kwargs)? - | STAR starargs=NAME (COMMA DOUBLESTAR kwargs=NAME)?{debug("parsed varargslist STARARGS");} - -> ^(StarArgs $starargs) ^(KWArgs $kwargs)? - | DOUBLESTAR kwargs=NAME {debug("parsed varargslist KWS");} - -> ^(KWArgs $kwargs) - ; +varargslist returns [argumentsType args] +@init { + List defaults = new ArrayList(); +} + : d+=defparameter[defaults] (options {greedy=true;}:COMMA d+=defparameter[defaults])* + (COMMA + (STAR starargs=NAME (COMMA DOUBLESTAR kwargs=NAME)? + | DOUBLESTAR kwargs=NAME + )? + )? + { + $args = actions.makeArgumentsType($varargslist.start, $d, $starargs, $kwargs, defaults); + } + | STAR starargs=NAME (COMMA DOUBLESTAR kwargs=NAME)? + { + $args = actions.makeArgumentsType($varargslist.start, $d, $starargs, $kwargs, defaults); + } + | DOUBLESTAR kwargs=NAME + { + $args = actions.makeArgumentsType($varargslist.start, $d, null, $kwargs, defaults); + } + ; //fpdef: NAME | '(' fplist ')' -fpdef : NAME {debug("parsed fpdef NAME");} - | (LPAREN fpdef COMMA) => LPAREN fplist RPAREN - -> ^(FpList fplist) - | LPAREN fplist RPAREN - -> fplist - ; +fpdef[expr_contextType ctype] +@after { + actions.checkAssign((exprType)$fpdef.tree); +} + : NAME + -> ^(NAME<Name>[$NAME, $NAME.text, ctype]) + | (LPAREN fpdef[null] COMMA) => LPAREN fplist RPAREN + -> ^(LPAREN<Tuple>[$fplist.start, actions.makeExprs($fplist.etypes), expr_contextType.Store]) + | LPAREN fplist RPAREN + -> fplist + ; //fplist: fpdef (',' fpdef)* [','] -fplist : fpdef (options {greedy=true;}:COMMA fpdef)* (COMMA)? - {debug("parsed fplist");} - -> fpdef+ - ; +fplist returns [List etypes] + : f+=fpdef[expr_contextType.Store] + (options {greedy=true;}:COMMA f+=fpdef[expr_contextType.Store])* (COMMA)? + { + $etypes = $f; + } + ; //stmt: simple_stmt | compound_stmt -stmt : simple_stmt - | compound_stmt - ; +stmt returns [List stypes] + : simple_stmt + { + $stypes = $simple_stmt.stypes; + } + | compound_stmt + { + $stypes = new ArrayList(); + $stypes.add($compound_stmt.tree); + } + ; //simple_stmt: small_stmt (';' small_stmt)* [';'] NEWLINE -simple_stmt : small_stmt (options {greedy=true;}:SEMI small_stmt)* (SEMI)? NEWLINE - -> small_stmt+ - ; +simple_stmt returns [List stypes] + : s+=small_stmt (options {greedy=true;}:SEMI s+=small_stmt)* (SEMI)? NEWLINE + { + $stypes = $s; + } + ; + //small_stmt: (expr_stmt | print_stmt | del_stmt | pass_stmt | flow_stmt | // import_stmt | global_stmt | exec_stmt | assert_stmt) small_stmt : expr_stmt @@ -430,310 +507,481 @@ //expr_stmt: testlist (augassign (yield_expr|testlist) | // ('=' (yield_expr|testlist))*) -expr_stmt : lhs=testlist[expr_contextType.Store] - ( (augassign yield_expr -> ^(augassign $lhs yield_expr)) - | (augassign rhs=testlist[expr_contextType.Load] -> ^(augassign $lhs $rhs)) - | ((assigns) {debug("matched assigns");} -> ^(Assign ^(Target $lhs) assigns)) - | -> $lhs - ) - ; - -//not in CPython's Grammar file -assigns - @after { - PythonTree pt = ((PythonTree)$assigns.tree); - int children = pt.getChildCount(); - PythonTree child; - if (children == 1) { - child = pt; - pt.token = new CommonToken(Value, "Value"); - } else { - child = (PythonTree)pt.getChild(children - 1); - child.token = new CommonToken(Value, "Value"); - } - child.token = new CommonToken(Value, "Value"); - PythonTree targ = (PythonTree)child.getChild(0); - if (targ instanceof Context) { - ((Context)targ).setContext(expr_contextType.Load); - } +expr_stmt +@init { + stmtType stype = null; } - : assign_testlist+ - | assign_yield+ +@after { + if (stype != null) { + $expr_stmt.tree = stype; + } +} + : ((testlist[null] augassign) => lhs=testlist[expr_contextType.AugStore] + ( (aay=augassign y1=yield_expr + { + actions.checkAssign((exprType)$lhs.tree); + stype = new AugAssign($lhs.tree, (exprType)$lhs.tree, $aay.op, (exprType)$y1.tree); + } + ) + | (aat=augassign rhs=testlist[expr_contextType.Load] + { + actions.checkAssign((exprType)$lhs.tree); + stype = new AugAssign($lhs.tree, (exprType)$lhs.tree, $aat.op, (exprType)$rhs.tree); + } + ) + ) + | (testlist[null] ASSIGN) => lhs=testlist[expr_contextType.Store] + ( + | ((at=ASSIGN t+=testlist[expr_contextType.Store])+ + -> ^(ASSIGN<Assign>[$lhs.start, actions.makeAssignTargets((exprType)$lhs.tree, $t), + actions.makeAssignValue($t)]) + ) + | ((ay=ASSIGN y2+=yield_expr)+ + -> ^(ASSIGN<Assign>[$lhs.start, actions.makeAssignTargets((exprType)$lhs.tree, $y2), + actions.makeAssignValue($y2)]) + ) + ) + | lhs=testlist[expr_contextType.Load] + { + stype = new Expr($lhs.start, (exprType)$lhs.tree); + } + ) ; -//not in CPython's Grammar file -assign_testlist - : ASSIGN testlist[expr_contextType.Store] -> ^(Target testlist) - ; - -//not in CPython's Grammar file -assign_yield - : ASSIGN yield_expr -> ^(Value yield_expr) - ; - //augassign: ('+=' | '-=' | '*=' | '/=' | '%=' | '&=' | '|=' | '^=' | // '<<=' | '>>=' | '**=' | '//=') -augassign : PLUSEQUAL - | MINUSEQUAL - | STAREQUAL - | SLASHEQUAL - | PERCENTEQUAL - | AMPEREQUAL - | VBAREQUAL - | CIRCUMFLEXEQUAL - | LEFTSHIFTEQUAL - | RIGHTSHIFTEQUAL - | DOUBLESTAREQUAL - | DOUBLESLASHEQUAL - ; +augassign returns [operatorType op] + : PLUSEQUAL {$op = operatorType.Add;} + | MINUSEQUAL {$op = operatorType.Sub;} + | STAREQUAL {$op = operatorType.Mult;} + | SLASHEQUAL {$op = operatorType.Div;} + | PERCENTEQUAL {$op = operatorType.Mod;} + | AMPEREQUAL {$op = operatorType.BitAnd;} + | VBAREQUAL {$op = operatorType.BitOr;} + | CIRCUMFLEXEQUAL {$op = operatorType.BitXor;} + | LEFTSHIFTEQUAL {$op = operatorType.LShift;} + | RIGHTSHIFTEQUAL {$op = operatorType.RShift;} + | DOUBLESTAREQUAL {$op = operatorType.Pow;} + | DOUBLESLASHEQUAL {$op = operatorType.FloorDiv;} + ; //print_stmt: 'print' ( [ test (',' test)* [','] ] | // '>>' test [ (',' test)+ [','] ] ) -print_stmt : PRINT - ( t1=printlist -> {$t1.newline}? ^(PRINT ^(Values $t1) ^(Newline)) - -> ^(PRINT ^(Values $t1)) - | RIGHTSHIFT t2=printlist2 -> {$t2.newline}? ^(PRINT ^(Dest RIGHTSHIFT) ^(Values $t2) ^(Newline)) - -> ^(PRINT ^(Dest RIGHTSHIFT) ^(Values $t2)) - | -> ^(PRINT ^(Newline)) - ) +print_stmt + : PRINT + (t1=printlist + -> ^(PRINT<Print>[$PRINT, null, actions.makeExprs($t1.elts), $t1.newline]) + | RIGHTSHIFT t2=printlist2 + -> ^(PRINT<Print>[$PRINT, (exprType)$t2.elts.get(0), actions.makeExprs($t2.elts, 1), $t2.newline]) + | + -> ^(PRINT<Print>[$PRINT, null, new exprType[0\], false]) + ) ; //not in CPython's Grammar file -printlist returns [boolean newline] - : (test[expr_contextType.Load] COMMA) => test[expr_contextType.Load] (options {k=2;}: COMMA test[expr_contextType.Load])* (trailcomma=COMMA)? - { if ($trailcomma == null) { +printlist returns [boolean newline, List elts] + : (test[null] COMMA) => + t+=test[expr_contextType.Load] (options {k=2;}: COMMA t+=test[expr_contextType.Load])* + (trailcomma=COMMA)? + { + $elts=$t; + if ($trailcomma == null) { + $newline = true; + } else { + $newline = false; + } + } + | t+=test[expr_contextType.Load] + { + $elts=$t; $newline = true; - } else { - $newline = false; } - } - -> ^(Elts test+) - | test[expr_contextType.Load] {$newline = true;} - -> ^(Elts test) ; +//XXX: would be nice if printlist and printlist2 could be merged. //not in CPython's Grammar file -printlist2 returns [boolean newline] - : (test[expr_contextType.Load] COMMA test[expr_contextType.Load]) => test[expr_contextType.Load] (options {k=2;}: COMMA test[expr_contextType.Load])* (trailcomma=COMMA)? - { if ($trailcomma == null) { +printlist2 returns [boolean newline, List elts] + : (test[null] COMMA test[null]) => + t+=test[expr_contextType.Load] (options {k=2;}: COMMA t+=test[expr_contextType.Load])* + (trailcomma=COMMA)? + { $elts=$t; + if ($trailcomma == null) { + $newline = true; + } else { + $newline = false; + } + } + | t+=test[expr_contextType.Load] + { + $elts=$t; $newline = true; - } else { - $newline = false; } - } - -> ^(Elts test+) - | test[expr_contextType.Load] {$newline = true;} - -> ^(Elts test) ; //del_stmt: 'del' exprlist -del_stmt : DELETE exprlist2 - -> ^(DELETE exprlist2) - ; +del_stmt + : DELETE del_list + -> ^(DELETE<Delete>[$DELETE, actions.makeExprs($del_list.etypes)]) + ; //pass_stmt: 'pass' -pass_stmt : PASS - -> ^(PASS) - ; +pass_stmt + : PASS + -> ^(PASS<Pass>[$PASS]) + ; //flow_stmt: break_stmt | continue_stmt | return_stmt | raise_stmt | yield_stmt -flow_stmt : break_stmt - | continue_stmt - | return_stmt - | raise_stmt - | yield_stmt - ; +flow_stmt + : break_stmt + | continue_stmt + | return_stmt + | raise_stmt + | yield_stmt + ; //break_stmt: 'break' -break_stmt : BREAK - -> ^(BREAK<Break>[$BREAK]) - ; +break_stmt + : BREAK + -> ^(BREAK<Break>[$BREAK]) + ; //continue_stmt: 'continue' -continue_stmt : CONTINUE - -> ^(CONTINUE<Continue>[$CONTINUE]) - ; +continue_stmt + : CONTINUE + -> ^(CONTINUE<Continue>[$CONTINUE]) + ; //return_stmt: 'return' [testlist] -return_stmt : RETURN (testlist[expr_contextType.Load])? - -> ^(RETURN ^(Value testlist)?) - ; +return_stmt + : RETURN + (testlist[expr_contextType.Load] + -> ^(RETURN<Return>[$RETURN, (exprType)$testlist.tree]) + | + -> ^(RETURN<Return>[$RETURN, null]) + ) + ; //yield_stmt: yield_expr -yield_stmt : yield_expr - ; +yield_stmt + : yield_expr -> ^(YIELD<Expr>[$yield_expr.start, (exprType)$yield_expr.tree]) + ; //raise_stmt: 'raise' [test [',' test [',' test]]] -raise_stmt: RAISE (t1=test[expr_contextType.Load] (COMMA t2=test[expr_contextType.Load] (COMMA t3=test[expr_contextType.Load])?)?)? - -> ^(RAISE ^(Type $t1)? ^(Inst $t2)? ^(Tback $t3)?) - ; +raise_stmt + : RAISE (t1=test[expr_contextType.Load] (COMMA t2=test[expr_contextType.Load] + (COMMA t3=test[expr_contextType.Load])?)?)? + -> ^(RAISE<Raise>[$RAISE, (exprType)$t1.tree, (exprType)$t2.tree, (exprType)$t3.tree]) + ; //import_stmt: import_name | import_from -import_stmt : import_name - | import_from - ; +import_stmt + : import_name + | import_from + ; //import_name: 'import' dotted_as_names -import_name : IMPORT dotted_as_names - -> ^(IMPORT dotted_as_names) - ; +import_name + : IMPORT dotted_as_names + -> ^(IMPORT<Import>[$IMPORT, $dotted_as_names.atypes]) + ; //import_from: ('from' ('.'* dotted_name | '.'+) // 'import' ('*' | '(' import_as_names ')' | import_as_names)) -import_from: FROM (DOT* dotted_name | DOT+) IMPORT - (STAR - -> ^(FROM ^(Level DOT*)? ^(Value dotted_name)? ^(IMPORT STAR)) - | import_as_names - -> ^(FROM ^(Level DOT*)? ^(Value dotted_name)? ^(IMPORT import_as_names)) - | LPAREN import_as_names COMMA? RPAREN - -> ^(FROM ^(Level DOT*)? ^(Value dotted_name)? ^(IMPORT import_as_names)) - ) - ; +import_from + : FROM (d+=DOT* dotted_name | d+=DOT+) IMPORT + (STAR + -> ^(FROM<ImportFrom>[$FROM, actions.makeFromText($d, $dotted_name.text), + actions.makeStarAlias($STAR), actions.makeLevel($d)]) + | i1=import_as_names + -> ^(FROM<ImportFrom>[$FROM, actions.makeFromText($d, $dotted_name.text), + actions.makeAliases($i1.atypes), actions.makeLevel($d)]) + | LPAREN i2=import_as_names COMMA? RPAREN + -> ^(FROM<ImportFrom>[$FROM, actions.makeFromText($d, $dotted_name.text), + actions.makeAliases($i2.atypes), actions.makeLevel($d)]) + ) + ; //import_as_names: import_as_name (',' import_as_name)* [','] -import_as_names : import_as_name (COMMA! import_as_name)* - ; +import_as_names returns [aliasType[\] atypes] + : n+=import_as_name (COMMA! n+=import_as_name)* + { + $atypes = (aliasType[])$n.toArray(new aliasType[$n.size()]); + } + ; //import_as_name: NAME [('as' | NAME) NAME] -import_as_name : name=NAME (AS asname=NAME)? - -> ^(Alias $name ^(Asname $asname)?) - ; +import_as_name returns [aliasType atype] +@after { + $import_as_name.tree = $atype; +} + : name=NAME (AS asname=NAME)? + { + $atype = new aliasType($name, $name.text, $asname.text); + } + ; //XXX: when does CPython Grammar match "dotted_name NAME NAME"? //dotted_as_name: dotted_name [('as' | NAME) NAME] -dotted_as_name : dotted_name (AS asname=NAME)? - -> ^(Alias dotted_name ^(Asname NAME)?) - ; +dotted_as_name returns [aliasType atype] +@after { + $dotted_as_name.tree = $atype; +} + : dotted_name (AS NAME)? + { + $atype = new aliasType($NAME, $dotted_name.text, $NAME.text); + } + ; + //dotted_as_names: dotted_as_name (',' dotted_as_name)* -dotted_as_names : dotted_as_name (COMMA! dotted_as_name)* - ; +dotted_as_names returns [aliasType[\] atypes] + : d+=dotted_as_name (COMMA! d+=dotted_as_name)* + { + $atypes = (aliasType[])$d.toArray(new aliasType[$d.size()]); + } + ; + //dotted_name: NAME ('.' NAME)* -dotted_name : NAME (DOT attr)* - ; +dotted_name + : NAME (DOT attr)* + ; //global_stmt: 'global' NAME (',' NAME)* -global_stmt : GLOBAL NAME (COMMA NAME)* - -> ^(GLOBAL NAME+) - ; +global_stmt + : GLOBAL n+=NAME (COMMA n+=NAME)* + -> ^(GLOBAL<Global>[$GLOBAL, actions.makeNames($n)]) + ; //exec_stmt: 'exec' expr ['in' test [',' test]] -exec_stmt : EXEC expr[expr_contextType.Load] (IN t1=test[expr_contextType.Load] (COMMA t2=test[expr_contextType.Load])?)? - -> ^(EXEC expr ^(Globals $t1)? ^(Locals $t2)?) - ; +exec_stmt +@init { + stmtType stype = null; +} +@after { + $exec_stmt.tree = stype; +} + : EXEC expr[expr_contextType.Load] (IN t1=test[expr_contextType.Load] + (COMMA t2=test[expr_contextType.Load])?)? + { + stype = new Exec($EXEC, (exprType)$expr.tree, (exprType)$t1.tree, (exprType)$t2.tree); + } + ; //assert_stmt: 'assert' test [',' test] -assert_stmt : ASSERT t1=test[expr_contextType.Load] (COMMA t2=test[expr_contextType.Load])? - -> ^(ASSERT ^(Test $t1) ^(Msg $t2)?) - ; +assert_stmt + : ASSERT t1=test[expr_contextType.Load] (COMMA t2=test[expr_contextType.Load])? + -> ^(ASSERT<Assert>[$ASSERT, (exprType)$t1.tree, (exprType)$t2.tree]) + ; //compound_stmt: if_stmt | while_stmt | for_stmt | try_stmt | funcdef | classdef -compound_stmt : if_stmt - | while_stmt - | for_stmt - | try_stmt - | with_stmt - | funcdef - | classdef - ; +compound_stmt + : if_stmt + | while_stmt + | for_stmt + | try_stmt + | with_stmt + | funcdef + | classdef + ; //if_stmt: 'if' test ':' suite ('elif' test ':' suite)* ['else' ':' suite] -if_stmt: IF test[expr_contextType.Load] COLON ifsuite=suite elif_clause* (ORELSE COLON elsesuite=suite)? - -> ^(IF test $ifsuite elif_clause* ^(ORELSE $elsesuite)?) - ; +if_stmt + : IF test[expr_contextType.Load] COLON ifsuite=suite elifs+=elif_clause* + (ORELSE COLON elsesuite=suite)? + -> ^(IF<If>[$IF, (exprType)$test.tree, actions.makeStmts($ifsuite.stypes), + actions.makeElses($elsesuite.stypes, $elifs)]) + ; //not in CPython's Grammar file -elif_clause : ELIF test[expr_contextType.Load] COLON suite - -> ^(ELIF test suite) - ; +elif_clause + : ELIF test[expr_contextType.Load] COLON suite + -> ^(ELIF<If>[$ELIF, (exprType)$test.tree, actions.makeStmts($suite.stypes), new stmtType[0\]]) + ; //while_stmt: 'while' test ':' suite ['else' ':' suite] -while_stmt : WHILE test[expr_contextType.Load] COLON s1=suite (ORELSE COLON s2=suite)? - -> ^(WHILE test ^(Body $s1) ^(ORELSE $s2)?) - ; +while_stmt +@init { + stmtType stype = null; +} +@after { + $while_stmt.tree = stype; +} + : WHILE test[expr_contextType.Load] COLON s1=suite (ORELSE COLON s2=suite)? + { + stype = actions.makeWhile($WHILE, (exprType)$test.tree, $s1.stypes, $s2.stypes); + } + ; //for_stmt: 'for' exprlist 'in' testlist ':' suite ['else' ':' suite] -for_stmt : FOR exprlist[expr_contextType.Store] IN testlist[expr_contextType.Load] COLON s1=suite (ORELSE COLON s2=suite)? - -> ^(FOR ^(Target exprlist) ^(IN testlist) ^(Body $s1) ^(ORELSE $s2)?) - ; +for_stmt +@init { + stmtType stype = null; +} +@after { + $for_stmt.tree = stype; +} + : FOR exprlist[expr_contextType.Store] IN testlist[expr_contextType.Load] COLON s1=suite + (ORELSE COLON s2=suite)? + { + stype = actions.makeFor($FOR, $exprlist.etype, (exprType)$testlist.tree, $s1.stypes, $s2.stypes); + } + ; //try_stmt: ('try' ':' suite // ((except_clause ':' suite)+ // ['else' ':' suite] // ['finally' ':' suite] | // 'finally' ':' suite)) -try_stmt : TRY COLON trysuite=suite - ( (except_clause+ (ORELSE COLON elsesuite=suite)? (FINALLY COLON finalsuite=suite)? - -> ^(TryExcept[$TRY] ^(Body $trysuite) except_clause+ ^(ORELSE $elsesuite)? ^(FINALLY $finalsuite)?)) - | (FINALLY COLON finalsuite=suite - -> ^(TryFinally[$TRY] ^(Body $trysuite) ^(FINALLY $finalsuite))) - ) - ; +try_stmt +@init { + stmtType stype = null; +} +@after { + $try_stmt.tree = stype; +} + : TRY COLON trysuite=suite + ( e+=except_clause+ (ORELSE COLON elsesuite=suite)? (FINALLY COLON finalsuite=suite)? + { + stype = actions.makeTryExcept($TRY, $trysuite.stypes, $e, $elsesuite.stypes, $finalsuite.stypes); + } + | FINALLY COLON finalsuite=suite + { + stype = actions.makeTryFinally($TRY, $trysuite.stypes, $finalsuite.stypes); + } + ) + ; //with_stmt: 'with' test [ with_var ] ':' suite -with_stmt: WITH test[expr_contextType.Load] (with_var)? COLON suite - -> ^(WITH test with_var? ^(Body suite)) - ; +with_stmt +@init { + stmtType stype = null; +} +@after { + $with_stmt.tree = stype; +} + : WITH test[expr_contextType.Load] (with_var)? COLON suite + { + stype = new With($WITH, (exprType)$test.tree, $with_var.etype, + actions.makeStmts($suite.stypes)); + } + ; //with_var: ('as' | NAME) expr -with_var: (AS | NAME) expr[expr_contextType.Load] - ; +with_var returns [exprType etype] + : (AS | NAME) expr[expr_contextType.Store] + { + $etype = (exprType)$expr.tree; + } + ; //except_clause: 'except' [test [',' test]] -except_clause : EXCEPT (t1=test[expr_contextType.Load] (COMMA t2=test[expr_contextType.Load])?)? COLON suite - //Note: passing the 'except' keyword on so we can pass the same offset - // as CPython. - -> ^(EXCEPT ^(Type $t1)? ^(Value $t2)? ^(Body suite)) - ; +except_clause + : EXCEPT (t1=test[expr_contextType.Load] (COMMA t2=test[expr_contextType.Store])?)? COLON suite + -> ^(EXCEPT<excepthandlerType>[$EXCEPT, (exprType)$t1.tree, (exprType)$t2.tree, + actions.makeStmts($suite.stypes), $EXCEPT.getLine(), $EXCEPT.getCharPositionInLine()]) + ; //suite: simple_stmt | NEWLINE INDENT stmt+ DEDENT -suite +suite returns [List stypes] +@init { + $stypes = new ArrayList(); +} : simple_stmt - | NEWLINE! INDENT (stmt)+ DEDENT + { + $stypes = $simple_stmt.stypes; + } + | NEWLINE INDENT + (stmt + { + $stypes.addAll($stmt.stypes); + } + )+ DEDENT ; //test: or_test ['if' or_test 'else' test] | lambdef test[expr_contextType ctype] :o1=or_test[ctype] - ( (IF or_test[expr_contextType.Load] ORELSE) => IF o2=or_test[ctype] ORELSE test[expr_contextType.Load] - -> ^(IfExp ^(Test $o2) ^(Body $o1) ^(ORELSE test)) - | -> or_test - ) - | lambdef {debug("parsed lambdef");} + ( (IF or_test[null] ORELSE) => IF o2=or_test[ctype] ORELSE e=test[expr_contextType.Load] + -> ^(IF<IfExp>[$IF, (exprType)$o2.tree, (exprType)$o1.tree, (exprType)$e.tree]) + | + -> or_test + ) + | lambdef ; //or_test: and_test ('or' and_test)* -or_test[expr_contextType ctype] : and_test[ctype] (OR^ and_test[ctype])* - ; +or_test[expr_contextType ctype] +@after { + if ($or != null) { + $or_test.tree = actions.makeBoolOp($left.tree, boolopType.Or, $right); + } +} + : left=and_test[ctype] + ( (or=OR right+=and_test[ctype] + )+ + | + -> $left + ) + ; //and_test: not_test ('and' not_test)* -and_test[expr_contextType ctype] : not_test[ctype] (AND^ not_test[ctype])* - ; +and_test[expr_contextType ctype] +@after { + if ($and != null) { + $and_test.tree = actions.makeBoolOp($left.tree, boolopType.And, $right); + } +} + : left=not_test[ctype] + ( (and=AND right+=not_test[ctype] + )+ + | + -> $left + ) + ; //not_test: 'not' not_test | comparison -not_test[expr_contextType ctype] : NOT^ not_test[ctype] - | comparison[ctype] - ; +not_test[expr_contextType ctype] + : NOT nt=not_test[ctype] + -> ^(NOT<UnaryOp>[$NOT, unaryopType.Not, (exprType)$nt.tree]) + | comparison[ctype] + ; //comparison: expr (comp_op expr)* -comparison[expr_contextType ctype]: expr[ctype] (comp_op^ expr[ctype])* +comparison[expr_contextType ctype] +@init { + List cmps = new ArrayList(); +} +@after { + if (!cmps.isEmpty()) { + $comparison.tree = new Compare($left.tree, (exprType)$left.tree, actions.makeCmpOps(cmps), + actions.makeExprs($right)); + } +} + : left=expr[ctype] + ( ( comp_op right+=expr[ctype] {cmps.add($comp_op.op);} + )+ + | + -> $left + ) ; //comp_op: '<'|'>'|'=='|'>='|'<='|'<>'|'!='|'in'|'not' 'in'|'is'|'is' 'not' -comp_op : LESS - | GREATER - | EQUAL - | GREATEREQUAL - | LESSEQUAL - | ALT_NOTEQUAL - | NOTEQUAL - | IN - | NOT IN -> NotIn - | IS - | IS NOT -> IsNot - ; +comp_op returns [cmpopType op] + : LESS {$op = cmpopType.Lt;} + | GREATER {$op = cmpopType.Gt;} + | EQUAL {$op = cmpopType.Eq;} + | GREATEREQUAL {$op = cmpopType.GtE;} + | LESSEQUAL {$op = cmpopType.LtE;} + | ALT_NOTEQUAL {$op = cmpopType.NotEq;} + | NOTEQUAL {$op = cmpopType.NotEq;} + | IN {$op = cmpopType.In;} + | NOT IN {$op = cmpopType.NotIn;} + | IS {$op = cmpopType.Is;} + | IS NOT {$op = cmpopType.IsNot;} + ; + //expr: xor_expr ('|' xor_expr)* expr[expr_contextType ect] scope { @@ -742,219 +990,531 @@ @init { $expr::ctype = ect; } - - : xor_expr (VBAR^ xor_expr)* +@after { + if ($op != null) { + $expr.tree = actions.makeBinOp($left.tree, operatorType.BitOr, $right); + } +} + : left=xor_expr + ( (op=VBAR right+=xor_expr + )+ + | + -> $left + ) ; + //xor_expr: and_expr ('^' and_expr)* -xor_expr : and_expr (CIRCUMFLEX^ and_expr)* - ; +xor_expr +@after { + if ($op != null) { + $xor_expr.tree = actions.makeBinOp($left.tree, operatorType.BitXor, $right); + } +} + : left=and_expr + ( (op=CIRCUMFLEX right+=and_expr + )+ + | + -> $left + ) + ; //and_expr: shift_expr ('&' shift_expr)* -and_expr : shift_expr (AMPER^ shift_expr)* - ; +and_expr +@after { + if ($op != null) { + $and_expr.tree = actions.makeBinOp($left.tree, operatorType.BitAnd, $right); + } +} + : left=shift_expr + ( (op=AMPER right+=shift_expr + )+ + | + -> $left + ) + ; //shift_expr: arith_expr (('<<'|'>>') arith_expr)* -shift_expr : arith_expr ((LEFTSHIFT^|RIGHTSHIFT^) arith_expr)* - ; +shift_expr +@init { + List ops = new ArrayList(); +} +@after { + if (!ops.isEmpty()) { + $shift_expr.tree = actions.makeBinOp($left.tree, ops, $right); + } +} + : left=arith_expr + ( ( shift_op right+=arith_expr {ops.add($shift_op.op);} + )+ + | + -> $left + ) + ; +shift_op returns [operatorType op] + : LEFTSHIFT {$op = operatorType.LShift;} + | RIGHTSHIFT {$op = operatorType.RShift;} + ; + //arith_expr: term (('+'|'-') term)* -arith_expr: term ((PLUS^|MINUS^) term)* +arith_expr +@init { + List ops = new ArrayList(); +} +@after { + if (!ops.isEmpty()) { + $arith_expr.tree = actions.makeBinOp($left.tree, ops, $right); + } +} + : left=term + ( (arith_op right+=term {ops.add($arith_op.op);} + )+ + | + -> $left + ) ; +arith_op returns [operatorType op] + : PLUS {$op = operatorType.Add;} + | MINUS {$op = operatorType.Sub;} + ; + //term: factor (('*'|'/'|'%'|'//') factor)* -term : factor ((STAR^ | SLASH^ | PERCENT^ | DOUBLESLASH^ ) factor)* - ; +term +@init { + List ops = new ArrayList(); +} +@after { + if (!ops.isEmpty()) { + $term.tree = actions.makeBinOp($left.tree, ops, $right); + } +} + : left=factor + ( (term_op right+=factor {ops.add($term_op.op);} + )+ + | + -> $left + ) + ; +term_op returns [operatorType op] + :STAR {$op = operatorType.Mult;} + |SLASH {$op = operatorType.Div;} + |PERCENT {$op = operatorType.Mod;} + |DOUBLESLASH {$op = operatorType.FloorDiv;} + ; + //factor: ('+'|'-'|'~') factor | power -factor : PLUS factor -> ^(UAdd PLUS factor) - | MINUS factor -> ^(USub MINUS factor) - | TILDE factor -> ^(Invert TILDE factor) - | power - ; +factor returns [exprType etype] +@after { + $factor.tree = $etype; +} + : PLUS p=factor {$etype = new UnaryOp($PLUS, unaryopType.UAdd, $p.etype);} + | MINUS m=factor {$etype = actions.negate($MINUS, $m.etype);} + | TILDE t=factor {$etype = new UnaryOp($TILDE, unaryopType.Invert, $t.etype);} + | power {$etype = (exprType)$power.tree;} + ; //power: atom trailer* ['**' factor] -power : atom (trailer^)* (options {greedy=true;}:DOUBLESTAR^ factor)? - ; +power returns [exprType etype] +@after { + $power.tree = $etype; +} + : atom (t+=trailer[$atom.start, $atom.tree])* (options {greedy=true;}:d=DOUBLESTAR factor)? + { + //XXX: This could be better. + $etype = (exprType)$atom.tree; + if ($t != null) { + for(int i = 0; i < $t.size(); i++) { + Object o = $t.get(i); + if ($etype instanceof Context) { + ((Context)$etype).setContext(expr_contextType.Load); + } + if (o instanceof Call) { + Call c = (Call)o; + c.func = $etype; + $etype = c; + } else if (o instanceof Subscript) { + Subscript c = (Subscript)o; + c.value = $etype; + $etype = c; + } else if (o instanceof Attribute) { + Attribute c = (Attribute)o; + c.value = $etype; + $etype = c; + } + } + } + if ($d != null) { + List right = new ArrayList(); + right.add($factor.tree); + $etype = actions.makeBinOp($etype, operatorType.Pow, right); + } + } + ; //atom: ('(' [yield_expr|testlist_gexp] ')' | // '[' [listmaker] ']' | // '{' [dictmaker] '}' | // '`' testlist1 '`' | // NAME | NUMBER | STRING+) -atom : LPAREN - ( yield_expr -> ^(Parens LPAREN yield_expr) - | testlist_gexp {debug("parsed testlist_gexp");} -> ^(Parens LPAREN testlist_gexp) - | -> ^(Tuple) +atom + : LPAREN + ( yield_expr + -> yield_expr + | testlist_gexp + -> testlist_gexp + | + -> ^(LPAREN<Tuple>[$LPAREN, new exprType[0\], $expr::ctype]) + ) + RPAREN + | LBRACK + (listmaker[$LBRACK] + -> listmaker + | + -> ^(LBRACK<org.python.antlr.ast.List>[$LBRACK, new exprType[0\], $expr::ctype]) + ) + RBRACK + | LCURLY + (dictmaker + -> ^(LCURLY<Dict>[$LCURLY, actions.makeExprs($dictmaker.keys), + actions.makeExprs($dictmaker.values)]) + | + -> ^(LCURLY<Dict>[$LCURLY, new exprType[0\], new exprType[0\]]) ) - RPAREN - | LBRACK - (listmaker -> ^(Brackets LBRACK listmaker) - | -> ^(Brackets LBRACK ^(List)) - ) - RBRACK - | LCURLY (dictmaker)? RCURLY -> ^(Dict LCURLY ^(Elts dictmaker)?) - | BACKQUOTE testlist[expr_contextType.Load] BACKQUOTE -> ^(Repr BACKQUOTE testlist) - | NAME -> ^(NameTok NAME) - | INT -> ^(NumTok<Num>[$INT, actions.makeInt($INT)]) - | LONGINT -> ^(NumTok<Num>[$LONGINT, actions.makeInt($LONGINT)]) - | FLOAT -> ^(NumTok<Num>[$FLOAT, actions.makeFloat($FLOAT)]) - | COMPLEX -> ^(NumTok<Num>[$COMPLEX, actions.makeComplex($COMPLEX)]) + RCURLY + | lb=BACKQUOTE testlist[expr_contextType.Load] rb=BACKQUOTE + -> ^(BACKQUOTE<Repr>[$lb, (exprType)$testlist.tree]) + | NAME + -> ^(NAME<Name>[$NAME, $NAME.text, $expr::ctype]) + | INT + -> ^(INT<Num>[$INT, actions.makeInt($INT)]) + | LONGINT + -> ^(LONGINT<Num>[$LONGINT, actions.makeInt($LONGINT)]) + | FLOAT + -> ^(FLOAT<Num>[$FLOAT, actions.makeFloat($FLOAT)]) + | COMPLEX + -> ^(COMPLEX<Num>[$COMPLEX, actions.makeComplex($COMPLEX)]) | (S+=STRING)+ - -> ^(StrTok<Str>[actions.extractStringToken($S), actions.extractStrings($S)]) + -> ^(STRING<Str>[actions.extractStringToken($S), actions.extractStrings($S)]) ; //listmaker: test ( list_for | (',' test)* [','] ) -listmaker : test[expr_contextType.Load] - ( list_for -> ^(ListComp test list_for) - | (options {greedy=true;}:COMMA test[expr_contextType.Load])* -> ^(List ^(Elts test+)) - ) (COMMA)? +listmaker[Token lbrack] +@init { + List gens = new ArrayList(); + exprType etype = null; +} +@after { + $listmaker.tree = etype; +} + : t+=test[$expr::ctype] + (list_for[gens] + { + Collections.reverse(gens); + comprehensionType[] c = + (comprehensionType[])gens.toArray(new comprehensionType[gens.size()]); + etype = new ListComp($listmaker.start, (exprType)$t.get(0), c); + } + | (options {greedy=true;}:COMMA t+=test[$expr::ctype])* + { + etype = new org.python.antlr.ast.List($lbrack, actions.makeExprs($t), $expr::ctype); + } + ) (COMMA)? ; //testlist_gexp: test ( gen_for | (',' test)* [','] ) testlist_gexp - : test[expr_contextType.Load] ( ((options {k=2;}: c1=COMMA test[expr_contextType.Load])* (c2=COMMA)? -> { $c1 != null || $c2 != null }? ^(Tuple ^(Elts test+)) - -> test - ) - | ( gen_for -> ^(GeneratorExp test gen_for)) - ) +@init { + exprType etype = null; + List gens = new ArrayList(); +} +@after { + if (etype != null) { + $testlist_gexp.tree = etype; + } +} + : t+=test[$expr::ctype] + ( ((options {k=2;}: c1=COMMA t+=test[$expr::ctype])* (c2=COMMA)? + -> { $c1 != null || $c2 != null }? + ^(COMMA<Tuple>[$testlist_gexp.start, actions.makeExprs($t), $expr::ctype]) + -> test + ) + | (gen_for[gens] + { + Collections.reverse(gens); + comprehensionType[] c = (comprehensionType[])gens.toArray(new comprehensionType[gens.size()]); + exprType e = (exprType)$t.get(0); + if (e instanceof Context) { + ((Context)e).setContext(expr_contextType.Load); + } + etype = new GeneratorExp($testlist_gexp.start, (exprType)$t.get(0), c); + } + ) + ) ; //lambdef: 'lambda' [varargslist] ':' test -lambdef: LAMBDA (varargslist)? COLON test[expr_contextType.Load] {debug("parsed lambda");} - -> ^(LAMBDA varargslist? ^(Body test)) - ; +lambdef +@init { + exprType etype = null; +} +@after { + $lambdef.tree = etype; +} + : LAMBDA (varargslist)? COLON test[expr_contextType.Load] + { + argumentsType a = $varargslist.args; + if (a == null) { + a = new argumentsType($LAMBDA, new exprType[0], null, null, new exprType[0]); + } + etype = new Lambda($LAMBDA, a, (exprType)$test.tree); + } + ; //trailer: '(' [arglist] ')' | '[' subscriptlist ']' | '.' NAME -trailer : LPAREN (arglist)? RPAREN -> ^(Call ^(Args arglist)?) - | LBRACK subscriptlist RBRACK -> ^(SubscriptList subscriptlist) - | DOT^ attr {debug("motched DOT^ NAME");} - ; +trailer [Token begin, PythonTree tree] + : LPAREN + (arglist + -> ^(LPAREN<Call>[$begin, (exprType)$tree, actions.makeExprs($arglist.args), + actions.makeKeywords($arglist.keywords), $arglist.starargs, $arglist.kwargs]) + | + -> ^(LPAREN<Call>[$LPAREN, (exprType)$tree, new exprType[0\], new keywordType[0\], null, null]) + ) + RPAREN + | LBRACK subscriptlist[$begin] RBRACK + -> ^(LBRACK<Subscript>[$begin, (exprType)$tree, (sliceType)$subscriptlist.tree, $expr::ctype]) + | DOT attr + -> ^(DOT<Attribute>[$begin, (exprType)$tree, $attr.text, $expr::ctype]) + ; //subscriptlist: subscript (',' subscript)* [','] -subscriptlist : subscript (options {greedy=true;}:c1=COMMA subscript)* (c2=COMMA)? - -> { $c1 != null || $c2 != null }? ^(Tuple ^(Elts subscript+)) - -> subscript - ; +subscriptlist[Token begin] +@init { + sliceType sltype = null; +} +@after { + $subscriptlist.tree = sltype; +} + : sub+=subscript (options {greedy=true;}:c1=COMMA sub+=subscript)* (c2=COMMA)? + { + sltype = actions.makeSliceType($begin, $c1, $c2, $sub); + } + ; //subscript: '.' '.' '.' | test | [test] ':' [test] [sliceop] -subscript : DOT DOT DOT -> Ellipsis - | (test[expr_contextType.Load] COLON) => t1=test[expr_contextType.Load] (COLON (t2=test[expr_contextType.Load])? (sliceop)?)? -> ^(Subscript ^(Lower $t1) ^(Upper COLON ^(UpperOp $t2)?)? sliceop?) - | (COLON) => COLON (test[expr_contextType.Load])? (sliceop)? -> ^(Subscript ^(Upper COLON ^(UpperOp test)?)? sliceop?) - | test[expr_contextType.Load] -> ^(Index test) - ; +subscript returns [sliceType sltype] +@after { + if ($sltype != null) { + $subscript.tree = $sltype; + } +} + : d1=DOT DOT DOT + -> DOT<Ellipsis>[$d1] + | (test[null] COLON) + => lower=test[expr_contextType.Load] (c1=COLON (upper1=test[expr_contextType.Load])? (sliceop)?)? + { + $sltype = actions.makeSubscript($lower.tree, $c1, $upper1.tree, $sliceop.tree); + } + | (COLON) + => c2=COLON (upper2=test[expr_contextType.Load])? (sliceop)? + { + $sltype = actions.makeSubscript(null, $c2, $upper2.tree, $sliceop.tree); + } + | test[expr_contextType.Load] + -> ^(LPAREN<Index>[$test.start, (exprType)$test.tree]) + ; //sliceop: ':' [test] -sliceop : COLON (test[expr_contextType.Load])? -> ^(Step COLON ^(StepOp test)?) - ; +sliceop + : COLON + (test[expr_contextType.Load] + -> test + )? + ; //exprlist: expr (',' expr)* [','] -exprlist[expr_contextType ctype]: (expr[expr_contextType.Load] COMMA) => expr[ctype] (options {k=2;}: COMMA expr[ctype])* (COMMA)? -> ^(Tuple ^(Elts expr+)) - | expr[ctype] - ; +exprlist[expr_contextType ctype] returns [exprType etype] + : (expr[null] COMMA) => e+=expr[ctype] (options {k=2;}: COMMA e+=expr[ctype])* (COMMA)? + { + $etype = new Tuple($exprlist.start, actions.makeExprs($e), ctype); + } + | expr[ctype] + { + $etype = (exprType)$expr.tree; + } + ; -//XXX: I'm hoping I can get rid of this -- but for now I need an exprlist that does not produce tuples -// at least for del_stmt -exprlist2 : expr[expr_contextType.Load] (options {k=2;}: COMMA expr[expr_contextType.Load])* (COMMA)? - -> expr+ - ; +//not in CPython's Grammar file +//Needed as an exprlist that does not produce tuples for del_stmt. +del_list returns [List etypes] + : e+=expr[expr_contextType.Del] (options {k=2;}: COMMA e+=expr[expr_contextType.Del])* (COMMA)? + { + $etypes = $e; + } + ; //testlist: test (',' test)* [','] testlist[expr_contextType ctype] - : test[ctype] (options {k=2;}: c1=COMMA test[ctype])* (c2=COMMA)? - -> { $c1 != null || $c2 != null }? ^(Tuple ^(Elts test+)) - -> test + : (test[null] COMMA) + => t+=test[ctype] (options {k=2;}: COMMA t+=test[ctype])* (COMMA)? + -> ^(COMMA<Tuple>[$testlist.start, actions.makeExprs($t), ctype]) + | test[ctype] ; -//XXX: -//testlist_safe: test [(',' test)+ [',']] - //dictmaker: test ':' test (',' test ':' test)* [','] -dictmaker : test[expr_contextType.Load] COLON test[expr_contextType.Load] - (options {k=2;}:COMMA test[expr_contextType.Load] COLON test[expr_contextType.Load])* (COMMA)? - -> test+ - ; +dictmaker returns [List keys, List values] + : k+=test[expr_contextType.Load] COLON v+=test[expr_contextType.Load] + (options {k=2;}:COMMA k+=test[expr_contextType.Load] COLON v+=test[expr_contextType.Load])* + (COMMA)? + { + $keys = $k; + $values= $v; + } + ; //classdef: 'class' NAME ['(' [testlist] ')'] ':' suite -classdef: CLASS NAME (LPAREN testlist[expr_contextType.Load]? RPAREN)? COLON suite - -> ^(CLASS NAME ^(Bases testlist)? ^(Body suite)) +cla... [truncated message content] |
From: <fwi...@us...> - 2008-08-29 12:14:14
|
Revision: 5263 http://jython.svn.sourceforge.net/jython/?rev=5263&view=rev Author: fwierzbicki Date: 2008-08-29 12:14:12 +0000 (Fri, 29 Aug 2008) Log Message: ----------- Initialized merge tracking via "svnmerge" with revisions "1-5209" from https://jython.svn.sourceforge.net/svnroot/jython/branches/nowalker Property Changed: ---------------- trunk/jython/ Property changes on: trunk/jython ___________________________________________________________________ Added: svnmerge-integrated + /branches/nowalker:1-5209 This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fwi...@us...> - 2008-08-29 12:11:47
|
Revision: 5262 http://jython.svn.sourceforge.net/jython/?rev=5262&view=rev Author: fwierzbicki Date: 2008-08-29 12:11:43 +0000 (Fri, 29 Aug 2008) Log Message: ----------- Leaving out two of the harder parts of test_inspect out for now (with comments to come back to them later). Modified Paths: -------------- trunk/jython/Lib/test/test_inspect.py Modified: trunk/jython/Lib/test/test_inspect.py =================================================================== --- trunk/jython/Lib/test/test_inspect.py 2008-08-27 20:51:19 UTC (rev 5261) +++ trunk/jython/Lib/test/test_inspect.py 2008-08-29 12:11:43 UTC (rev 5262) @@ -8,6 +8,7 @@ from test import inspect_fodder as mod from test import inspect_fodder2 as mod2 +from test import test_support # Functions tested in this suite: # ismodule, isclass, ismethod, isfunction, istraceback, isframe, iscode, @@ -59,7 +60,10 @@ self.assertEqual(count, expected, err_msg) def test_excluding_predicates(self): - self.istest(inspect.isbuiltin, 'sys.exit') + #XXX: Jython's PySystemState needs more work before this + #will be doable. + if not test_support.is_jython: + self.istest(inspect.isbuiltin, 'sys.exit') self.istest(inspect.isbuiltin, '[].append') self.istest(inspect.isclass, 'mod.StupidGit') self.istest(inspect.iscode, 'mod.spam.func_code') @@ -74,7 +78,8 @@ if hasattr(types, 'GetSetDescriptorType'): self.istest(inspect.isgetsetdescriptor, 'type(tb.tb_frame).f_locals') - else: + #XXX: This detail of PyFrames is not yet supported in Jython + elif not test_support.is_jython: self.failIf(inspect.isgetsetdescriptor(type(tb.tb_frame).f_locals)) if hasattr(types, 'MemberDescriptorType'): self.istest(inspect.ismemberdescriptor, 'datetime.timedelta.days') This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fwi...@us...> - 2008-08-27 20:51:23
|
Revision: 5261 http://jython.svn.sourceforge.net/jython/?rev=5261&view=rev Author: fwierzbicki Date: 2008-08-27 20:51:19 +0000 (Wed, 27 Aug 2008) Log Message: ----------- simplify testlist. Modified Paths: -------------- branches/nowalker/grammar/Python.g Modified: branches/nowalker/grammar/Python.g =================================================================== --- branches/nowalker/grammar/Python.g 2008-08-27 20:35:54 UTC (rev 5260) +++ branches/nowalker/grammar/Python.g 2008-08-27 20:51:19 UTC (rev 5261) @@ -1357,21 +1357,10 @@ //testlist: test (',' test)* [','] testlist[expr_contextType ctype] -@init { - exprType etype = null; -} -@after { - $testlist.tree = etype; -} : (test[null] COMMA) => t+=test[ctype] (options {k=2;}: COMMA t+=test[ctype])* (COMMA)? - { - etype = new Tuple($testlist.start, actions.makeExprs($t), ctype); - } + -> ^(COMMA<Tuple>[$testlist.start, actions.makeExprs($t), ctype]) | test[ctype] - { - etype = (exprType)$test.tree; - } ; //dictmaker: test ':' test (',' test ':' test)* [','] This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fwi...@us...> - 2008-08-27 20:35:56
|
Revision: 5260 http://jython.svn.sourceforge.net/jython/?rev=5260&view=rev Author: fwierzbicki Date: 2008-08-27 20:35:54 +0000 (Wed, 27 Aug 2008) Log Message: ----------- Removed XXX comments that no longer apply (special testlists don't seem to be needed). Removed unused c1 and c2 alias. Modified Paths: -------------- branches/nowalker/grammar/Python.g Modified: branches/nowalker/grammar/Python.g =================================================================== --- branches/nowalker/grammar/Python.g 2008-08-27 20:09:39 UTC (rev 5259) +++ branches/nowalker/grammar/Python.g 2008-08-27 20:35:54 UTC (rev 5260) @@ -1346,8 +1346,8 @@ } ; -//XXX: I'm hoping I can get rid of this and merge it back with exprlist -- but for now I need an exprlist that does not produce tuples -// at least for del_stmt +//not in CPython's Grammar file +//Needed as an exprlist that does not produce tuples for del_stmt. del_list returns [List etypes] : e+=expr[expr_contextType.Del] (options {k=2;}: COMMA e+=expr[expr_contextType.Del])* (COMMA)? { @@ -1364,7 +1364,7 @@ $testlist.tree = etype; } : (test[null] COMMA) - => t+=test[ctype] (options {k=2;}: c1=COMMA t+=test[ctype])* (c2=COMMA)? + => t+=test[ctype] (options {k=2;}: COMMA t+=test[ctype])* (COMMA)? { etype = new Tuple($testlist.start, actions.makeExprs($t), ctype); } @@ -1374,9 +1374,6 @@ } ; -//XXX: -//testlist_safe: test [(',' test)+ [',']] - //dictmaker: test ':' test (',' test ':' test)* [','] dictmaker returns [List keys, List values] : k+=test[expr_contextType.Load] COLON v+=test[expr_contextType.Load] @@ -1529,9 +1526,6 @@ -> ^(YIELD<Yield>[$YIELD, (exprType)$testlist.tree]) ; -//XXX: -//testlist1: test (',' test)* - AS : 'as' ; ASSERT : 'assert' ; BREAK : 'break' ; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fwi...@us...> - 2008-08-27 20:09:41
|
Revision: 5259 http://jython.svn.sourceforge.net/jython/?rev=5259&view=rev Author: fwierzbicki Date: 2008-08-27 20:09:39 +0000 (Wed, 27 Aug 2008) Log Message: ----------- TODO comment. Modified Paths: -------------- branches/nowalker/grammar/Python.g Modified: branches/nowalker/grammar/Python.g =================================================================== --- branches/nowalker/grammar/Python.g 2008-08-27 19:51:16 UTC (rev 5258) +++ branches/nowalker/grammar/Python.g 2008-08-27 20:09:39 UTC (rev 5259) @@ -1123,6 +1123,7 @@ } : atom (t+=trailer[$atom.start, $atom.tree])* (options {greedy=true;}:d=DOUBLESTAR factor)? { + //XXX: This could be better. $etype = (exprType)$atom.tree; if ($t != null) { for(int i = 0; i < $t.size(); i++) { @@ -1130,7 +1131,6 @@ if ($etype instanceof Context) { ((Context)$etype).setContext(expr_contextType.Load); } - //XXX: good place for an interface to avoid all of this instanceof if (o instanceof Call) { Call c = (Call)o; c.func = $etype; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fwi...@us...> - 2008-08-27 19:51:19
|
Revision: 5258 http://jython.svn.sourceforge.net/jython/?rev=5258&view=rev Author: fwierzbicki Date: 2008-08-27 19:51:16 +0000 (Wed, 27 Aug 2008) Log Message: ----------- for not_test, replacing manual tree construction with ->. Modified Paths: -------------- branches/nowalker/grammar/Python.g Modified: branches/nowalker/grammar/Python.g =================================================================== --- branches/nowalker/grammar/Python.g 2008-08-27 16:07:35 UTC (rev 5257) +++ branches/nowalker/grammar/Python.g 2008-08-27 19:51:16 UTC (rev 5258) @@ -941,16 +941,9 @@ ; //not_test: 'not' not_test | comparison -not_test[expr_contextType ctype] returns [exprType etype] -@after { - if ($etype != null) { - $not_test.tree = $etype; - } -} +not_test[expr_contextType ctype] : NOT nt=not_test[ctype] - { - $etype = new UnaryOp($NOT, unaryopType.Not, (exprType)$nt.tree); - } + -> ^(NOT<UnaryOp>[$NOT, unaryopType.Not, (exprType)$nt.tree]) | comparison[ctype] ; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fwi...@us...> - 2008-08-27 16:07:40
|
Revision: 5257 http://jython.svn.sourceforge.net/jython/?rev=5257&view=rev Author: fwierzbicki Date: 2008-08-27 16:07:35 +0000 (Wed, 27 Aug 2008) Log Message: ----------- revert build.xml after accidently checking in my local copy. Modified Paths: -------------- branches/nowalker/build.xml Modified: branches/nowalker/build.xml =================================================================== --- branches/nowalker/build.xml 2008-08-27 02:47:56 UTC (rev 5256) +++ branches/nowalker/build.xml 2008-08-27 16:07:35 UTC (rev 5257) @@ -318,7 +318,9 @@ change to grammar files. If you are working on the grammars you might want to comment this out, as a clean is really only needed if you change the tokens defined in Python.g (and cleans make the build slow) --> + <antcall target="clean"/> <!-- force jarjar build --> + <property name="jarjar.needed" value="true" /> </target> <target name ="prepare-output" depends="init,needed-check,clean-if-antlr-needed,make-output-dirs"/> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fwi...@us...> - 2008-08-27 02:47:59
|
Revision: 5256 http://jython.svn.sourceforge.net/jython/?rev=5256&view=rev Author: fwierzbicki Date: 2008-08-27 02:47:56 +0000 (Wed, 27 Aug 2008) Log Message: ----------- whitespace Modified Paths: -------------- branches/nowalker/grammar/Python.g Modified: branches/nowalker/grammar/Python.g =================================================================== --- branches/nowalker/grammar/Python.g 2008-08-27 02:38:35 UTC (rev 5255) +++ branches/nowalker/grammar/Python.g 2008-08-27 02:47:56 UTC (rev 5256) @@ -358,15 +358,16 @@ $decorator.tree = $etype; } : AT dotted_attr - ( LPAREN (arglist - { - $etype = actions.makeCall($LPAREN, $dotted_attr.etype, $arglist.args, - $arglist.keywords, $arglist.starargs, $arglist.kwargs); - } - |{ - $etype = actions.makeCall($LPAREN, $dotted_attr.etype); - } - ) + ( LPAREN + ( arglist + { + $etype = actions.makeCall($LPAREN, $dotted_attr.etype, $arglist.args, $arglist.keywords, + $arglist.starargs, $arglist.kwargs); + } + | { + $etype = actions.makeCall($LPAREN, $dotted_attr.etype); + } + ) RPAREN | { $etype = $dotted_attr.etype; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fwi...@us...> - 2008-08-27 02:38:38
|
Revision: 5255 http://jython.svn.sourceforge.net/jython/?rev=5255&view=rev Author: fwierzbicki Date: 2008-08-27 02:38:35 +0000 (Wed, 27 Aug 2008) Log Message: ----------- Fix for FunctionDef and Call problems. Modified Paths: -------------- branches/nowalker/grammar/Python.g branches/nowalker/src/org/python/antlr/GrammarActions.java Modified: branches/nowalker/grammar/Python.g =================================================================== --- branches/nowalker/grammar/Python.g 2008-08-27 00:44:35 UTC (rev 5254) +++ branches/nowalker/grammar/Python.g 2008-08-27 02:38:35 UTC (rev 5255) @@ -359,25 +359,42 @@ } : AT dotted_attr ( LPAREN (arglist - {$etype = new Call($LPAREN, $dotted_attr.etype, actions.makeExprs($arglist.args), - actions.makeKeywords($arglist.keywords), $arglist.starargs, $arglist.kwargs);} - | {$etype = $dotted_attr.etype;} + { + $etype = actions.makeCall($LPAREN, $dotted_attr.etype, $arglist.args, + $arglist.keywords, $arglist.starargs, $arglist.kwargs); + } + |{ + $etype = actions.makeCall($LPAREN, $dotted_attr.etype); + } ) RPAREN - | { $etype = $dotted_attr.etype; } + | { + $etype = $dotted_attr.etype; + } ) NEWLINE ; //decorators: decorator+ decorators returns [List etypes] - : d+=decorator+ {$etypes = $d;} + : d+=decorator+ + { + $etypes = $d; + } ; //funcdef: [decorators] 'def' NAME parameters ':' suite -funcdef : decorators? DEF NAME parameters COLON suite - -> ^(DEF<FunctionDef>[$DEF, $NAME.text, $parameters.args, actions.makeStmts($suite.stypes), - actions.makeExprs($decorators.etypes)]) - ; +funcdef +@init { stmtType stype = null; } +@after { $funcdef.tree = stype; } + : decorators? DEF NAME parameters COLON suite + { + Token t = $DEF; + if ($decorators.start != null) { + t = $decorators.start; + } + stype = actions.makeFuncdef(t, $NAME, $parameters.args, $suite.stypes, $decorators.etypes); + } + ; //parameters: '(' [varargslist] ')' parameters returns [argumentsType args] @@ -1387,7 +1404,7 @@ } : CLASS NAME (LPAREN testlist[expr_contextType.Load]? RPAREN)? COLON suite { - stype = new ClassDef($CLASS, $NAME.getText(), actions.makeBases((exprType)$testlist.tree), + stype = new ClassDef($CLASS, actions.cantBeNone($NAME), actions.makeBases((exprType)$testlist.tree), actions.makeStmts($suite.stypes)); } ; @@ -1443,6 +1460,9 @@ arguments.add(new GeneratorExp($gen_for.start, (exprType)$t1.tree, c)); } | { + if (kws.size() > 0) { + errorHandler.error("non-keyword arg after keyword arg", $t1.tree); + } $arguments.add($t1.tree); } ) Modified: branches/nowalker/src/org/python/antlr/GrammarActions.java =================================================================== --- branches/nowalker/src/org/python/antlr/GrammarActions.java 2008-08-27 00:44:35 UTC (rev 5254) +++ branches/nowalker/src/org/python/antlr/GrammarActions.java 2008-08-27 02:38:35 UTC (rev 5255) @@ -233,6 +233,7 @@ if (target == null || iter == null) { return errorHandler.errorStmt(new PythonTree(t)); } + cantBeNone(target); stmtType[] o = makeStmts(orelse); stmtType[] b = makeStmts(body); @@ -258,9 +259,9 @@ return new TryFinally(t, b, f); } - stmtType makeFunctionDef(PythonTree t, PythonTree nameToken, argumentsType args, List funcStatements, List decorators) { + stmtType makeFuncdef(Token t, Token nameToken, argumentsType args, List funcStatements, List decorators) { if (nameToken == null) { - return errorHandler.errorStmt(t); + return errorHandler.errorStmt(new PythonTree(t)); } cantBeNone(nameToken); argumentsType a; @@ -554,13 +555,13 @@ return new For(t, target, iter, b, o); } - exprType makeCall(PythonTree t, exprType func) { + exprType makeCall(Token t, exprType func) { return makeCall(t, func, null, null, null, null); } - exprType makeCall(PythonTree t, exprType func, List args, List keywords, exprType starargs, exprType kwargs) { + exprType makeCall(Token t, exprType func, List args, List keywords, exprType starargs, exprType kwargs) { if (func == null) { - return errorHandler.errorExpr(t); + return errorHandler.errorExpr(new PythonTree(t)); } keywordType[] k = makeKeywords(keywords); exprType[] a = makeExprs(args); @@ -603,6 +604,13 @@ return new UnaryOp(t, unaryopType.USub, o); } + String cantBeNone(Token t) { + if (t == null || t.getText().equals("None")) { + errorHandler.error("can't be None", new PythonTree(t)); + } + return t.getText(); + } + void cantBeNone(PythonTree e) { if (e.getText().equals("None")) { errorHandler.error("can't be None", e); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fwi...@us...> - 2008-08-27 00:44:38
|
Revision: 5254 http://jython.svn.sourceforge.net/jython/?rev=5254&view=rev Author: fwierzbicki Date: 2008-08-27 00:44:35 +0000 (Wed, 27 Aug 2008) Log Message: ----------- Fix illegal Lambda statements and more illegal assigns. Also raise exceptions on illegal gen expression arguments. Modified Paths: -------------- branches/nowalker/grammar/Python.g branches/nowalker/src/org/python/antlr/GrammarActions.java Modified: branches/nowalker/grammar/Python.g =================================================================== --- branches/nowalker/grammar/Python.g 2008-08-26 20:17:50 UTC (rev 5253) +++ branches/nowalker/grammar/Python.g 2008-08-27 00:44:35 UTC (rev 5254) @@ -851,7 +851,7 @@ //with_var: ('as' | NAME) expr with_var returns [exprType etype] - : (AS | NAME) expr[expr_contextType.Load] + : (AS | NAME) expr[expr_contextType.Store] { $etype = (exprType)$expr.tree; } @@ -1397,14 +1397,18 @@ @init { List arguments = new ArrayList(); List kws = new ArrayList(); + List gens = new ArrayList(); } - : argument[arguments, kws] (COMMA argument[arguments, kws])* + : argument[arguments, kws, gens, true] (COMMA argument[arguments, kws, gens, false])* (COMMA ( STAR s=test[expr_contextType.Load] (COMMA DOUBLESTAR k=test[expr_contextType.Load])? | DOUBLESTAR k=test[expr_contextType.Load] )? )? { + if (arguments.size() > 1 && gens.size() > 0) { + actions.errorGenExpNotSoleArg(new PythonTree($arglist.start)); + } $args=arguments; $keywords=kws; $starargs=(exprType)$s.tree; @@ -1422,19 +1426,20 @@ ; //argument: test [gen_for] | test '=' test # Really [keyword '='] test -argument[List arguments, List kws] -@init { - List gens = new ArrayList(); -} +argument[List arguments, List kws, List gens, boolean first] returns [boolean genarg] : t1=test[expr_contextType.Load] ((ASSIGN t2=test[expr_contextType.Load]) { $kws.add(new exprType[]{(exprType)$t1.tree, (exprType)$t2.tree}); } - | gen_for[gens] + | gen_for[$gens] { - Collections.reverse(gens); - comprehensionType[] c = (comprehensionType[])gens.toArray(new comprehensionType[gens.size()]); + if (!first) { + actions.errorGenExpNotSoleArg($gen_for.tree); + } + $genarg = true; + Collections.reverse($gens); + comprehensionType[] c = (comprehensionType[])$gens.toArray(new comprehensionType[$gens.size()]); arguments.add(new GeneratorExp($gen_for.start, (exprType)$t1.tree, c)); } | { Modified: branches/nowalker/src/org/python/antlr/GrammarActions.java =================================================================== --- branches/nowalker/src/org/python/antlr/GrammarActions.java 2008-08-26 20:17:50 UTC (rev 5253) +++ branches/nowalker/src/org/python/antlr/GrammarActions.java 2008-08-27 00:44:35 UTC (rev 5254) @@ -299,6 +299,9 @@ if (tree instanceof GeneratorExp) { GeneratorExp g = (GeneratorExp)tree; recurseSetContext(g.elt, context); + } else if (tree instanceof ListComp) { + ListComp lc = (ListComp)tree; + recurseSetContext(lc.elt, context); } else if (!(tree instanceof ListComp)) { for (int i=0; i<tree.getChildCount(); i++) { recurseSetContext(tree.getChild(i), context); @@ -617,6 +620,8 @@ errorHandler.error("can't assign to yield expression", e); } else if (e instanceof BinOp) { errorHandler.error("can't assign to operator", e); + } else if (e instanceof Lambda) { + errorHandler.error("can't assign to lambda", e); } else if (e instanceof Tuple) { //XXX: performance problem? Any way to do this better? exprType[] elts = ((Tuple)e).elts; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fwi...@us...> - 2008-08-26 20:17:53
|
Revision: 5253 http://jython.svn.sourceforge.net/jython/?rev=5253&view=rev Author: fwierzbicki Date: 2008-08-26 20:17:50 +0000 (Tue, 26 Aug 2008) Log Message: ----------- checking for bad assignment statements. Modified Paths: -------------- branches/nowalker/grammar/Python.g branches/nowalker/src/org/python/antlr/GrammarActions.java Modified: branches/nowalker/grammar/Python.g =================================================================== --- branches/nowalker/grammar/Python.g 2008-08-26 19:37:34 UTC (rev 5252) +++ branches/nowalker/grammar/Python.g 2008-08-26 20:17:50 UTC (rev 5253) @@ -433,6 +433,9 @@ //fpdef: NAME | '(' fplist ')' fpdef[expr_contextType ctype] +@after { + actions.checkAssign((exprType)$fpdef.tree); +} : NAME -> ^(NAME<Name>[$NAME, $NAME.text, ctype]) | (LPAREN fpdef[null] COMMA) => LPAREN fplist RPAREN @@ -498,11 +501,13 @@ : ((testlist[null] augassign) => lhs=testlist[expr_contextType.AugStore] ( (aay=augassign y1=yield_expr { + actions.checkAssign((exprType)$lhs.tree); stype = new AugAssign($lhs.tree, (exprType)$lhs.tree, $aay.op, (exprType)$y1.tree); } ) | (aat=augassign rhs=testlist[expr_contextType.Load] { + actions.checkAssign((exprType)$lhs.tree); stype = new AugAssign($lhs.tree, (exprType)$lhs.tree, $aat.op, (exprType)$rhs.tree); } ) Modified: branches/nowalker/src/org/python/antlr/GrammarActions.java =================================================================== --- branches/nowalker/src/org/python/antlr/GrammarActions.java 2008-08-26 19:37:34 UTC (rev 5252) +++ branches/nowalker/src/org/python/antlr/GrammarActions.java 2008-08-26 20:17:50 UTC (rev 5253) @@ -276,16 +276,12 @@ exprType[] makeAssignTargets(exprType lhs, List rhs) { exprType[] e = new exprType[rhs.size()]; + checkAssign(lhs); e[0] = lhs; for(int i=0;i<rhs.size() - 1;i++) { - Object o = rhs.get(i); - if (o instanceof PythonParser.testlist_return) { - //XXX: Check to see if this is really happening anymore - PythonParser.testlist_return r = (PythonParser.testlist_return)o; - e[i + 1] = (exprType)r.getTree(); - } else { - e[i + 1] = (exprType)o; - } + exprType r = (exprType)rhs.get(i); + checkAssign(r); + e[i + 1] = r; } return e; } @@ -339,6 +335,7 @@ if (args != null) { for(int i=0;i<args.size();i++) { exprType[] e = (exprType[])args.get(i); + checkAssign(e[0]); Name arg = (Name)e[0]; k.add(new keywordType(arg, arg.id, e[1])); } @@ -618,6 +615,8 @@ errorHandler.error("can't assign to number", e); } else if (e instanceof Yield) { errorHandler.error("can't assign to yield expression", e); + } else if (e instanceof BinOp) { + errorHandler.error("can't assign to operator", e); } else if (e instanceof Tuple) { //XXX: performance problem? Any way to do this better? exprType[] elts = ((Tuple)e).elts; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fwi...@us...> - 2008-08-26 19:37:36
|
Revision: 5252 http://jython.svn.sourceforge.net/jython/?rev=5252&view=rev Author: fwierzbicki Date: 2008-08-26 19:37:34 +0000 (Tue, 26 Aug 2008) Log Message: ----------- Another expr_contextType adjustment. Modified Paths: -------------- branches/nowalker/grammar/Python.g Modified: branches/nowalker/grammar/Python.g =================================================================== --- branches/nowalker/grammar/Python.g 2008-08-26 16:51:15 UTC (rev 5251) +++ branches/nowalker/grammar/Python.g 2008-08-26 19:37:34 UTC (rev 5252) @@ -1193,7 +1193,7 @@ @after { $listmaker.tree = etype; } - : t+=test[expr_contextType.Load] + : t+=test[$expr::ctype] (list_for[gens] { Collections.reverse(gens); @@ -1201,7 +1201,7 @@ (comprehensionType[])gens.toArray(new comprehensionType[gens.size()]); etype = new ListComp($listmaker.start, (exprType)$t.get(0), c); } - | (options {greedy=true;}:COMMA t+=test[expr_contextType.Load])* + | (options {greedy=true;}:COMMA t+=test[$expr::ctype])* { etype = new org.python.antlr.ast.List($lbrack, actions.makeExprs($t), $expr::ctype); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fwi...@us...> - 2008-08-26 16:51:17
|
Revision: 5251 http://jython.svn.sourceforge.net/jython/?rev=5251&view=rev Author: fwierzbicki Date: 2008-08-26 16:51:15 +0000 (Tue, 26 Aug 2008) Log Message: ----------- Moved Subscript creation up a rule - fixed a bunch of unit tests. Modified Paths: -------------- branches/nowalker/build.xml branches/nowalker/grammar/Python.g Modified: branches/nowalker/build.xml =================================================================== --- branches/nowalker/build.xml 2008-08-26 15:05:19 UTC (rev 5250) +++ branches/nowalker/build.xml 2008-08-26 16:51:15 UTC (rev 5251) @@ -318,9 +318,7 @@ change to grammar files. If you are working on the grammars you might want to comment this out, as a clean is really only needed if you change the tokens defined in Python.g (and cleans make the build slow) --> - <antcall target="clean"/> <!-- force jarjar build --> - <property name="jarjar.needed" value="true" /> </target> <target name ="prepare-output" depends="init,needed-check,clean-if-antlr-needed,make-output-dirs"/> Modified: branches/nowalker/grammar/Python.g =================================================================== --- branches/nowalker/grammar/Python.g 2008-08-26 15:05:19 UTC (rev 5250) +++ branches/nowalker/grammar/Python.g 2008-08-26 16:51:15 UTC (rev 5251) @@ -1105,7 +1105,7 @@ @after { $power.tree = $etype; } - : atom (t+=trailer[$atom.start])* (options {greedy=true;}:d=DOUBLESTAR factor)? + : atom (t+=trailer[$atom.start, $atom.tree])* (options {greedy=true;}:d=DOUBLESTAR factor)? { $etype = (exprType)$atom.tree; if ($t != null) { @@ -1258,33 +1258,32 @@ ; //trailer: '(' [arglist] ')' | '[' subscriptlist ']' | '.' NAME -trailer [Token begin] +trailer [Token begin, PythonTree tree] : LPAREN (arglist - -> ^(LPAREN<Call>[$begin, null, actions.makeExprs($arglist.args), + -> ^(LPAREN<Call>[$begin, (exprType)$tree, actions.makeExprs($arglist.args), actions.makeKeywords($arglist.keywords), $arglist.starargs, $arglist.kwargs]) | - -> ^(LPAREN<Call>[$LPAREN, null, new exprType[0\], new keywordType[0\], null, null]) + -> ^(LPAREN<Call>[$LPAREN, (exprType)$tree, new exprType[0\], new keywordType[0\], null, null]) ) RPAREN - | LBRACK s=subscriptlist[begin] RBRACK - -> $s + | LBRACK subscriptlist[$begin] RBRACK + -> ^(LBRACK<Subscript>[$begin, (exprType)$tree, (sliceType)$subscriptlist.tree, $expr::ctype]) | DOT attr - -> ^(DOT<Attribute>[$begin, null, $attr.text, $expr::ctype]) + -> ^(DOT<Attribute>[$begin, (exprType)$tree, $attr.text, $expr::ctype]) ; //subscriptlist: subscript (',' subscript)* [','] -subscriptlist[Token begin] returns [exprType etype] +subscriptlist[Token begin] @init { - exprType etype = null; + sliceType sltype = null; } @after { - $subscriptlist.tree = etype; + $subscriptlist.tree = sltype; } : sub+=subscript (options {greedy=true;}:c1=COMMA sub+=subscript)* (c2=COMMA)? { - sliceType s = actions.makeSliceType($begin, $c1, $c2, $sub); - etype = new Subscript($begin, null, s, $expr::ctype); + sltype = actions.makeSliceType($begin, $c1, $c2, $sub); } ; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fwi...@us...> - 2008-08-26 15:05:24
|
Revision: 5250 http://jython.svn.sourceforge.net/jython/?rev=5250&view=rev Author: fwierzbicki Date: 2008-08-26 15:05:19 +0000 (Tue, 26 Aug 2008) Log Message: ----------- Moved makeSliceType code to GrammarActions. Modified Paths: -------------- branches/nowalker/grammar/Python.g branches/nowalker/src/org/python/antlr/GrammarActions.java Modified: branches/nowalker/grammar/Python.g =================================================================== --- branches/nowalker/grammar/Python.g 2008-08-26 12:21:42 UTC (rev 5249) +++ branches/nowalker/grammar/Python.g 2008-08-26 15:05:19 UTC (rev 5250) @@ -1274,7 +1274,6 @@ ; //subscriptlist: subscript (',' subscript)* [','] -//FIXME: tuples not always created when commas are present. subscriptlist[Token begin] returns [exprType etype] @init { exprType etype = null; @@ -1284,40 +1283,7 @@ } : sub+=subscript (options {greedy=true;}:c1=COMMA sub+=subscript)* (c2=COMMA)? { - boolean isTuple = false; - if ($c1 != null || $c2 != null) { - isTuple = true; - } - sliceType s = null; - List sltypes = $sub; - boolean extslice = false; - - if (isTuple) { - sliceType[] st; - List etypes = new ArrayList(); - for (Object o : sltypes) { - if (o instanceof Index) { - Index i = (Index)o; - etypes.add(i.value); - } else { - extslice = true; - break; - } - } - if (!extslice) { - exprType[] es = (exprType[])etypes.toArray(new exprType[etypes.size()]); - exprType t = new Tuple($begin, es, expr_contextType.Load); - s = new Index($begin, t); - } - } else if (sltypes.size() == 1) { - s = (sliceType)sltypes.get(0); - } else if (sltypes.size() != 0) { - extslice = true; - } - if (extslice) { - sliceType[] st = (sliceType[])sltypes.toArray(new sliceType[sltypes.size()]); - s = new ExtSlice($begin, st); - } + sliceType s = actions.makeSliceType($begin, $c1, $c2, $sub); etype = new Subscript($begin, null, s, $expr::ctype); } ; Modified: branches/nowalker/src/org/python/antlr/GrammarActions.java =================================================================== --- branches/nowalker/src/org/python/antlr/GrammarActions.java 2008-08-26 12:21:42 UTC (rev 5249) +++ branches/nowalker/src/org/python/antlr/GrammarActions.java 2008-08-26 15:05:19 UTC (rev 5250) @@ -706,4 +706,42 @@ } return current; } + + sliceType makeSliceType(Token begin, Token c1, Token c2, List sltypes) { + boolean isTuple = false; + if (c1 != null || c2 != null) { + isTuple = true; + } + sliceType s = null; + boolean extslice = false; + + if (isTuple) { + sliceType[] st; + List etypes = new ArrayList(); + for (Object o : sltypes) { + if (o instanceof Index) { + Index i = (Index)o; + etypes.add(i.value); + } else { + extslice = true; + break; + } + } + if (!extslice) { + exprType[] es = (exprType[])etypes.toArray(new exprType[etypes.size()]); + exprType t = new Tuple(begin, es, expr_contextType.Load); + s = new Index(begin, t); + } + } else if (sltypes.size() == 1) { + s = (sliceType)sltypes.get(0); + } else if (sltypes.size() != 0) { + extslice = true; + } + if (extslice) { + sliceType[] st = (sliceType[])sltypes.toArray(new sliceType[sltypes.size()]); + s = new ExtSlice(begin, st); + } + return s; + } + } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fwi...@us...> - 2008-08-26 12:21:45
|
Revision: 5249 http://jython.svn.sourceforge.net/jython/?rev=5249&view=rev Author: fwierzbicki Date: 2008-08-26 12:21:42 +0000 (Tue, 26 Aug 2008) Log Message: ----------- Remove unnecessary constructor on BinOp (now it is just the generated version again) Remove some whitespace in Python.g Modified Paths: -------------- branches/nowalker/grammar/Python.g branches/nowalker/src/org/python/antlr/ast/BinOp.java Modified: branches/nowalker/grammar/Python.g =================================================================== --- branches/nowalker/grammar/Python.g 2008-08-26 02:04:27 UTC (rev 5248) +++ branches/nowalker/grammar/Python.g 2008-08-26 12:21:42 UTC (rev 5249) @@ -1261,7 +1261,7 @@ trailer [Token begin] : LPAREN (arglist - -> ^(LPAREN<Call>[$begin, null, actions.makeExprs($arglist.args), + -> ^(LPAREN<Call>[$begin, null, actions.makeExprs($arglist.args), actions.makeKeywords($arglist.keywords), $arglist.starargs, $arglist.kwargs]) | -> ^(LPAREN<Call>[$LPAREN, null, new exprType[0\], new keywordType[0\], null, null]) Modified: branches/nowalker/src/org/python/antlr/ast/BinOp.java =================================================================== --- branches/nowalker/src/org/python/antlr/ast/BinOp.java 2008-08-26 02:04:27 UTC (rev 5248) +++ branches/nowalker/src/org/python/antlr/ast/BinOp.java 2008-08-26 12:21:42 UTC (rev 5249) @@ -13,10 +13,6 @@ public static final String[] _fields = new String[] {"left","op","right"}; - public BinOp(Token token) { - super(token); - } - public BinOp(Token token, exprType left, operatorType op, exprType right) { super(token); this.left = left; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fwi...@us...> - 2008-08-26 02:04:30
|
Revision: 5248 http://jython.svn.sourceforge.net/jython/?rev=5248&view=rev Author: fwierzbicki Date: 2008-08-26 02:04:27 +0000 (Tue, 26 Aug 2008) Log Message: ----------- Cleanup: removal of comments, re-format of Python.g and removal of PYNODE. Modified Paths: -------------- branches/nowalker/grammar/Python.g branches/nowalker/src/org/python/antlr/ModuleParser.java Modified: branches/nowalker/grammar/Python.g =================================================================== --- branches/nowalker/grammar/Python.g 2008-08-25 21:18:03 UTC (rev 5247) +++ branches/nowalker/grammar/Python.g 2008-08-26 02:04:27 UTC (rev 5248) @@ -61,8 +61,7 @@ * grammar from Jim Baker. The current parsing and compiling strategy looks * like this: * - * Python source->Python.g->simple antlr AST->PythonWalker.g-> - * decorated AST (org/python/parser/ast/*)->CodeCompiler(ASM)->.class + * Python source->Python.g->AST (org/python/parser/ast/*)->CodeCompiler(ASM)->.class */ grammar Python; @@ -74,8 +73,6 @@ tokens { INDENT; DEDENT; - - PYNODE; } @header { @@ -159,12 +156,8 @@ } @members { - boolean debugOn = false; - private ErrorHandler errorHandler; - private boolean seenSingleOuterSuite = false; - private GrammarActions actions = new GrammarActions(); public void setErrorHandler(ErrorHandler eh) { @@ -172,12 +165,6 @@ actions.setErrorHandler(eh); } - private void debug(String message) { - if (debugOn) { - System.out.println(message); - } - } - protected void mismatch(IntStream input, int ttype, BitSet follow) throws RecognitionException { if (errorHandler.isRecoverable()) { super.mismatch(input, ttype, follow); @@ -224,7 +211,7 @@ int implicitLineJoiningLevel = 0; int startPos=-1; -//If you want to use another error recovery mechanisms change this +//If you want to use another error recovery mechanism change this //and the same one in the parser. private ErrorHandler errorHandler; @@ -371,14 +358,12 @@ $decorator.tree = $etype; } : AT dotted_attr - //XXX: ignoring the arglist and Call generation right now. ( LPAREN (arglist {$etype = new Call($LPAREN, $dotted_attr.etype, actions.makeExprs($arglist.args), actions.makeKeywords($arglist.keywords), $arglist.starargs, $arglist.kwargs);} | {$etype = $dotted_attr.etype;} ) RPAREN - // ^(Decorator dotted_attr ^(CallTok ^(Args arglist)?)) | { $etype = $dotted_attr.etype; } ) NEWLINE ; @@ -398,7 +383,8 @@ parameters returns [argumentsType args] : LPAREN (varargslist {$args = $varargslist.args;} - | {$args = new argumentsType($parameters.start, new exprType[0], null, null, new exprType[0]);} + | { $args = new argumentsType($parameters.start, new exprType[0], null, null, new exprType[0]); + } ) RPAREN ; @@ -408,17 +394,16 @@ @after { $defparameter.tree = $etype; } - : fpdef[expr_contextType.Param] (ASSIGN test[expr_contextType.Load])? { - $etype = (exprType)$fpdef.tree; - if ($ASSIGN != null) { - defaults.add($test.tree); - } else if (!defaults.isEmpty()) { - throw new ParseException( - "non-default argument follows default argument", - $fpdef.tree); - } - } -; + : fpdef[expr_contextType.Param] (ASSIGN test[expr_contextType.Load])? + { + $etype = (exprType)$fpdef.tree; + if ($ASSIGN != null) { + defaults.add($test.tree); + } else if (!defaults.isEmpty()) { + throw new ParseException("non-default argument follows default argument", $fpdef.tree); + } + } + ; //varargslist: ((fpdef ['=' test] ',')* // ('*' NAME [',' '**' NAME] | '**' NAME) | @@ -428,47 +413,62 @@ List defaults = new ArrayList(); } : d+=defparameter[defaults] (options {greedy=true;}:COMMA d+=defparameter[defaults])* - (COMMA - ( STAR starargs=NAME (COMMA DOUBLESTAR kwargs=NAME)? - | DOUBLESTAR kwargs=NAME - )? - )? - {$args = actions.makeArgumentsType($varargslist.start, $d, $starargs, $kwargs, defaults);} - | STAR starargs=NAME (COMMA DOUBLESTAR kwargs=NAME)?{debug("parsed varargslist STARARGS");} - {$args = actions.makeArgumentsType($varargslist.start, $d, $starargs, $kwargs, defaults);} - | DOUBLESTAR kwargs=NAME {debug("parsed varargslist KWS");} - {$args = actions.makeArgumentsType($varargslist.start, $d, null, $kwargs, defaults);} - ; + (COMMA + (STAR starargs=NAME (COMMA DOUBLESTAR kwargs=NAME)? + | DOUBLESTAR kwargs=NAME + )? + )? + { + $args = actions.makeArgumentsType($varargslist.start, $d, $starargs, $kwargs, defaults); + } + | STAR starargs=NAME (COMMA DOUBLESTAR kwargs=NAME)? + { + $args = actions.makeArgumentsType($varargslist.start, $d, $starargs, $kwargs, defaults); + } + | DOUBLESTAR kwargs=NAME + { + $args = actions.makeArgumentsType($varargslist.start, $d, null, $kwargs, defaults); + } + ; //fpdef: NAME | '(' fplist ')' -fpdef[expr_contextType ctype] : NAME - -> ^(PYNODE<Name>[$NAME, $NAME.text, ctype]) - | (LPAREN fpdef[null] COMMA) => LPAREN fplist RPAREN - -> ^(LPAREN<Tuple>[$fplist.start, actions.makeExprs($fplist.etypes), expr_contextType.Store]) - | LPAREN fplist RPAREN - -> fplist - ; +fpdef[expr_contextType ctype] + : NAME + -> ^(NAME<Name>[$NAME, $NAME.text, ctype]) + | (LPAREN fpdef[null] COMMA) => LPAREN fplist RPAREN + -> ^(LPAREN<Tuple>[$fplist.start, actions.makeExprs($fplist.etypes), expr_contextType.Store]) + | LPAREN fplist RPAREN + -> fplist + ; //fplist: fpdef (',' fpdef)* [','] fplist returns [List etypes] - : f+=fpdef[expr_contextType.Store] (options {greedy=true;}:COMMA f+=fpdef[expr_contextType.Store])* (COMMA)? - {$etypes = $f;} + : f+=fpdef[expr_contextType.Store] + (options {greedy=true;}:COMMA f+=fpdef[expr_contextType.Store])* (COMMA)? + { + $etypes = $f; + } ; //stmt: simple_stmt | compound_stmt stmt returns [List stypes] - : simple_stmt {$stypes = $simple_stmt.stypes;} - | compound_stmt { - $stypes = new ArrayList(); - $stypes.add($compound_stmt.tree); - } + : simple_stmt + { + $stypes = $simple_stmt.stypes; + } + | compound_stmt + { + $stypes = new ArrayList(); + $stypes.add($compound_stmt.tree); + } ; //simple_stmt: small_stmt (';' small_stmt)* [';'] NEWLINE simple_stmt returns [List stypes] - : s+=small_stmt (options {greedy=true;}:SEMI s+=small_stmt)* (SEMI)? NEWLINE { - $stypes = $s; - } + : s+=small_stmt (options {greedy=true;}:SEMI s+=small_stmt)* (SEMI)? NEWLINE + { + $stypes = $s; + } ; //small_stmt: (expr_stmt | print_stmt | del_stmt | pass_stmt | flow_stmt | @@ -495,18 +495,33 @@ $expr_stmt.tree = stype; } } - - : - ((testlist[null] augassign) => lhs=testlist[expr_contextType.AugStore] - ( (aay=augassign y1=yield_expr {stype = new AugAssign($lhs.tree, (exprType)$lhs.tree, $aay.op, (exprType)$y1.tree);}) - | (aat=augassign rhs=testlist[expr_contextType.Load] {stype = new AugAssign($lhs.tree, (exprType)$lhs.tree, $aat.op, (exprType)$rhs.tree);}) + : ((testlist[null] augassign) => lhs=testlist[expr_contextType.AugStore] + ( (aay=augassign y1=yield_expr + { + stype = new AugAssign($lhs.tree, (exprType)$lhs.tree, $aay.op, (exprType)$y1.tree); + } + ) + | (aat=augassign rhs=testlist[expr_contextType.Load] + { + stype = new AugAssign($lhs.tree, (exprType)$lhs.tree, $aat.op, (exprType)$rhs.tree); + } + ) ) - |(testlist[null] ASSIGN) => lhs=testlist[expr_contextType.Store] + | (testlist[null] ASSIGN) => lhs=testlist[expr_contextType.Store] ( - | ((at=ASSIGN t+=testlist[expr_contextType.Store])+ -> ^(PYNODE<Assign>[$lhs.start, actions.makeAssignTargets((exprType)$lhs.tree, $t), actions.makeAssignValue($t)])) - | ((ay=ASSIGN y2+=yield_expr)+ -> ^(PYNODE<Assign>[$lhs.start, actions.makeAssignTargets((exprType)$lhs.tree, $y2), actions.makeAssignValue($y2)])) + | ((at=ASSIGN t+=testlist[expr_contextType.Store])+ + -> ^(ASSIGN<Assign>[$lhs.start, actions.makeAssignTargets((exprType)$lhs.tree, $t), + actions.makeAssignValue($t)]) + ) + | ((ay=ASSIGN y2+=yield_expr)+ + -> ^(ASSIGN<Assign>[$lhs.start, actions.makeAssignTargets((exprType)$lhs.tree, $y2), + actions.makeAssignValue($y2)]) + ) ) - | lhs=testlist[expr_contextType.Load] -> PYNODE<Expr>[$lhs.start, (exprType)$lhs.tree] + | lhs=testlist[expr_contextType.Load] + { + stype = new Expr($lhs.start, (exprType)$lhs.tree); + } ) ; @@ -529,121 +544,145 @@ //print_stmt: 'print' ( [ test (',' test)* [','] ] | // '>>' test [ (',' test)+ [','] ] ) -print_stmt : PRINT - ( t1=printlist - -> ^(PRINT<Print>[$PRINT, null, actions.makeExprs($t1.elts), $t1.newline]) - | RIGHTSHIFT t2=printlist2 - -> ^(PRINT<Print>[$PRINT, (exprType)$t2.elts.get(0), actions.makeExprs($t2.elts, 1), $t2.newline]) - | - -> ^(PRINT<Print>[$PRINT, null, new exprType[0\], false]) - ) +print_stmt + : PRINT + (t1=printlist + -> ^(PRINT<Print>[$PRINT, null, actions.makeExprs($t1.elts), $t1.newline]) + | RIGHTSHIFT t2=printlist2 + -> ^(PRINT<Print>[$PRINT, (exprType)$t2.elts.get(0), actions.makeExprs($t2.elts, 1), $t2.newline]) + | + -> ^(PRINT<Print>[$PRINT, null, new exprType[0\], false]) + ) ; //not in CPython's Grammar file printlist returns [boolean newline, List elts] : (test[null] COMMA) => - t+=test[expr_contextType.Load] (options {k=2;}: COMMA t+=test[expr_contextType.Load])* (trailcomma=COMMA)? - { $elts=$t; - if ($trailcomma == null) { - $newline = true; - } else { - $newline = false; + t+=test[expr_contextType.Load] (options {k=2;}: COMMA t+=test[expr_contextType.Load])* + (trailcomma=COMMA)? + { + $elts=$t; + if ($trailcomma == null) { + $newline = true; + } else { + $newline = false; + } + } + | t+=test[expr_contextType.Load] + { + $elts=$t; + $newline = true; } - } - | t+=test[expr_contextType.Load] { - $elts=$t; - $newline = true; - } ; //XXX: would be nice if printlist and printlist2 could be merged. //not in CPython's Grammar file printlist2 returns [boolean newline, List elts] : (test[null] COMMA test[null]) => - t+=test[expr_contextType.Load] (options {k=2;}: COMMA t+=test[expr_contextType.Load])* (trailcomma=COMMA)? - { $elts=$t; - if ($trailcomma == null) { - $newline = true; - } else { - $newline = false; + t+=test[expr_contextType.Load] (options {k=2;}: COMMA t+=test[expr_contextType.Load])* + (trailcomma=COMMA)? + { $elts=$t; + if ($trailcomma == null) { + $newline = true; + } else { + $newline = false; + } + } + | t+=test[expr_contextType.Load] + { + $elts=$t; + $newline = true; } - } - | t+=test[expr_contextType.Load] { - $elts=$t; - $newline = true; - } ; //del_stmt: 'del' exprlist -del_stmt : DELETE del_list - -> ^(DELETE<Delete>[$DELETE, actions.makeExprs($del_list.etypes)]) - ; +del_stmt + : DELETE del_list + -> ^(DELETE<Delete>[$DELETE, actions.makeExprs($del_list.etypes)]) + ; //pass_stmt: 'pass' -pass_stmt : PASS - -> ^(PASS<Pass>[$PASS]) - ; +pass_stmt + : PASS + -> ^(PASS<Pass>[$PASS]) + ; //flow_stmt: break_stmt | continue_stmt | return_stmt | raise_stmt | yield_stmt -flow_stmt : break_stmt - | continue_stmt - | return_stmt - | raise_stmt - | yield_stmt - ; +flow_stmt + : break_stmt + | continue_stmt + | return_stmt + | raise_stmt + | yield_stmt + ; //break_stmt: 'break' -break_stmt : BREAK - -> ^(BREAK<Break>[$BREAK]) - ; +break_stmt + : BREAK + -> ^(BREAK<Break>[$BREAK]) + ; //continue_stmt: 'continue' -continue_stmt : CONTINUE - -> ^(CONTINUE<Continue>[$CONTINUE]) - ; +continue_stmt + : CONTINUE + -> ^(CONTINUE<Continue>[$CONTINUE]) + ; //return_stmt: 'return' [testlist] -return_stmt : RETURN - (testlist[expr_contextType.Load] -> ^(RETURN<Return>[$RETURN, (exprType)$testlist.tree]) - | -> ^(RETURN<Return>[$RETURN, null]) - ) - ; +return_stmt + : RETURN + (testlist[expr_contextType.Load] + -> ^(RETURN<Return>[$RETURN, (exprType)$testlist.tree]) + | + -> ^(RETURN<Return>[$RETURN, null]) + ) + ; //yield_stmt: yield_expr -yield_stmt : yield_expr -> ^(PYNODE<Expr>[$yield_expr.start, (exprType)$yield_expr.tree]) - ; +yield_stmt + : yield_expr -> ^(YIELD<Expr>[$yield_expr.start, (exprType)$yield_expr.tree]) + ; //raise_stmt: 'raise' [test [',' test [',' test]]] -raise_stmt: RAISE (t1=test[expr_contextType.Load] (COMMA t2=test[expr_contextType.Load] (COMMA t3=test[expr_contextType.Load])?)?)? - -> ^(RAISE<Raise>[$RAISE, (exprType)$t1.tree, (exprType)$t2.tree, (exprType)$t3.tree]) - ; +raise_stmt + : RAISE (t1=test[expr_contextType.Load] (COMMA t2=test[expr_contextType.Load] + (COMMA t3=test[expr_contextType.Load])?)?)? + -> ^(RAISE<Raise>[$RAISE, (exprType)$t1.tree, (exprType)$t2.tree, (exprType)$t3.tree]) + ; //import_stmt: import_name | import_from -import_stmt : import_name - | import_from - ; +import_stmt + : import_name + | import_from + ; //import_name: 'import' dotted_as_names -import_name : IMPORT dotted_as_names - -> ^(IMPORT<Import>[$IMPORT, $dotted_as_names.atypes]) - ; +import_name + : IMPORT dotted_as_names + -> ^(IMPORT<Import>[$IMPORT, $dotted_as_names.atypes]) + ; //import_from: ('from' ('.'* dotted_name | '.'+) // 'import' ('*' | '(' import_as_names ')' | import_as_names)) -import_from: FROM (d+=DOT* dotted_name | d+=DOT+) IMPORT - (STAR - -> ^(FROM<ImportFrom>[$FROM, actions.makeFromText($d, $dotted_name.text), actions.makeStarAlias($STAR), actions.makeLevel($d)]) - | i1=import_as_names - -> ^(FROM<ImportFrom>[$FROM, actions.makeFromText($d, $dotted_name.text), actions.makeAliases($i1.atypes), actions.makeLevel($d)]) - | LPAREN i2=import_as_names COMMA? RPAREN - -> ^(FROM<ImportFrom>[$FROM, actions.makeFromText($d, $dotted_name.text), actions.makeAliases($i2.atypes), actions.makeLevel($d)]) - ) - ; +import_from + : FROM (d+=DOT* dotted_name | d+=DOT+) IMPORT + (STAR + -> ^(FROM<ImportFrom>[$FROM, actions.makeFromText($d, $dotted_name.text), + actions.makeStarAlias($STAR), actions.makeLevel($d)]) + | i1=import_as_names + -> ^(FROM<ImportFrom>[$FROM, actions.makeFromText($d, $dotted_name.text), + actions.makeAliases($i1.atypes), actions.makeLevel($d)]) + | LPAREN i2=import_as_names COMMA? RPAREN + -> ^(FROM<ImportFrom>[$FROM, actions.makeFromText($d, $dotted_name.text), + actions.makeAliases($i2.atypes), actions.makeLevel($d)]) + ) + ; //import_as_names: import_as_name (',' import_as_name)* [','] import_as_names returns [aliasType[\] atypes] - : n+=import_as_name (COMMA! n+=import_as_name)* { + : n+=import_as_name (COMMA! n+=import_as_name)* + { $atypes = (aliasType[])$n.toArray(new aliasType[$n.size()]); } ; @@ -653,7 +692,8 @@ @after { $import_as_name.tree = $atype; } - : name=NAME (AS asname=NAME)? { + : name=NAME (AS asname=NAME)? + { $atype = new aliasType($name, $name.text, $asname.text); } ; @@ -665,26 +705,30 @@ $dotted_as_name.tree = $atype; } - : dotted_name (AS NAME)? { + : dotted_name (AS NAME)? + { $atype = new aliasType($NAME, $dotted_name.text, $NAME.text); } ; //dotted_as_names: dotted_as_name (',' dotted_as_name)* dotted_as_names returns [aliasType[\] atypes] - : d+=dotted_as_name (COMMA! d+=dotted_as_name)* { + : d+=dotted_as_name (COMMA! d+=dotted_as_name)* + { $atypes = (aliasType[])$d.toArray(new aliasType[$d.size()]); } ; //dotted_name: NAME ('.' NAME)* -dotted_name : NAME (DOT attr)* - ; +dotted_name + : NAME (DOT attr)* + ; //global_stmt: 'global' NAME (',' NAME)* -global_stmt : GLOBAL n+=NAME (COMMA n+=NAME)* - -> ^(GLOBAL<Global>[$GLOBAL, actions.makeNames($n)]) - ; +global_stmt + : GLOBAL n+=NAME (COMMA n+=NAME)* + -> ^(GLOBAL<Global>[$GLOBAL, actions.makeNames($n)]) + ; //exec_stmt: 'exec' expr ['in' test [',' test]] exec_stmt @@ -694,35 +738,43 @@ @after { $exec_stmt.tree = stype; } - : EXEC expr[expr_contextType.Load] (IN t1=test[expr_contextType.Load] (COMMA t2=test[expr_contextType.Load])?)? { + : EXEC expr[expr_contextType.Load] (IN t1=test[expr_contextType.Load] + (COMMA t2=test[expr_contextType.Load])?)? + { stype = new Exec($EXEC, (exprType)$expr.tree, (exprType)$t1.tree, (exprType)$t2.tree); - } + } ; //assert_stmt: 'assert' test [',' test] -assert_stmt : ASSERT t1=test[expr_contextType.Load] (COMMA t2=test[expr_contextType.Load])? - -> ^(ASSERT<Assert>[$ASSERT, (exprType)$t1.tree, (exprType)$t2.tree]) - ; +assert_stmt + : ASSERT t1=test[expr_contextType.Load] (COMMA t2=test[expr_contextType.Load])? + -> ^(ASSERT<Assert>[$ASSERT, (exprType)$t1.tree, (exprType)$t2.tree]) + ; //compound_stmt: if_stmt | while_stmt | for_stmt | try_stmt | funcdef | classdef -compound_stmt : if_stmt - | while_stmt - | for_stmt - | try_stmt - | with_stmt - | funcdef - | classdef - ; +compound_stmt + : if_stmt + | while_stmt + | for_stmt + | try_stmt + | with_stmt + | funcdef + | classdef + ; //if_stmt: 'if' test ':' suite ('elif' test ':' suite)* ['else' ':' suite] -if_stmt: IF test[expr_contextType.Load] COLON ifsuite=suite elifs+=elif_clause* (ORELSE COLON elsesuite=suite)? - -> ^(IF<If>[$IF, (exprType)$test.tree, actions.makeStmts($ifsuite.stypes), actions.makeElses($elsesuite.stypes, $elifs)]) - ; +if_stmt + : IF test[expr_contextType.Load] COLON ifsuite=suite elifs+=elif_clause* + (ORELSE COLON elsesuite=suite)? + -> ^(IF<If>[$IF, (exprType)$test.tree, actions.makeStmts($ifsuite.stypes), + actions.makeElses($elsesuite.stypes, $elifs)]) + ; //not in CPython's Grammar file -elif_clause : ELIF test[expr_contextType.Load] COLON suite - -> ^(ELIF<If>[$ELIF, (exprType)$test.tree, actions.makeStmts($suite.stypes), new stmtType[0\]]) - ; +elif_clause + : ELIF test[expr_contextType.Load] COLON suite + -> ^(ELIF<If>[$ELIF, (exprType)$test.tree, actions.makeStmts($suite.stypes), new stmtType[0\]]) + ; //while_stmt: 'while' test ':' suite ['else' ':' suite] while_stmt @@ -732,7 +784,8 @@ @after { $while_stmt.tree = stype; } - : WHILE test[expr_contextType.Load] COLON s1=suite (ORELSE COLON s2=suite)? { + : WHILE test[expr_contextType.Load] COLON s1=suite (ORELSE COLON s2=suite)? + { stype = actions.makeWhile($WHILE, (exprType)$test.tree, $s1.stypes, $s2.stypes); } ; @@ -745,9 +798,11 @@ @after { $for_stmt.tree = stype; } - : FOR exprlist[expr_contextType.Store] IN testlist[expr_contextType.Load] COLON s1=suite (ORELSE COLON s2=suite)? { - stype = actions.makeFor($FOR, $exprlist.etype, (exprType)$testlist.tree, $s1.stypes, $s2.stypes); - } + : FOR exprlist[expr_contextType.Store] IN testlist[expr_contextType.Load] COLON s1=suite + (ORELSE COLON s2=suite)? + { + stype = actions.makeFor($FOR, $exprlist.etype, (exprType)$testlist.tree, $s1.stypes, $s2.stypes); + } ; //try_stmt: ('try' ':' suite @@ -763,14 +818,16 @@ $try_stmt.tree = stype; } : TRY COLON trysuite=suite - ( e+=except_clause+ (ORELSE COLON elsesuite=suite)? (FINALLY COLON finalsuite=suite)? { + ( e+=except_clause+ (ORELSE COLON elsesuite=suite)? (FINALLY COLON finalsuite=suite)? + { stype = actions.makeTryExcept($TRY, $trysuite.stypes, $e, $elsesuite.stypes, $finalsuite.stypes); } - | FINALLY COLON finalsuite=suite { + | FINALLY COLON finalsuite=suite + { stype = actions.makeTryFinally($TRY, $trysuite.stypes, $finalsuite.stypes); } - ) - ; + ) + ; //with_stmt: 'with' test [ with_var ] ':' suite with_stmt @@ -780,42 +837,54 @@ @after { $with_stmt.tree = stype; } - :WITH test[expr_contextType.Load] (with_var)? COLON suite { - stype = new With($WITH, (exprType)$test.tree, $with_var.etype, actions.makeStmts($suite.stypes)); - } + : WITH test[expr_contextType.Load] (with_var)? COLON suite + { + stype = new With($WITH, (exprType)$test.tree, $with_var.etype, + actions.makeStmts($suite.stypes)); + } ; //with_var: ('as' | NAME) expr with_var returns [exprType etype] - : (AS | NAME) expr[expr_contextType.Load] { - $etype = (exprType)$expr.tree; - } + : (AS | NAME) expr[expr_contextType.Load] + { + $etype = (exprType)$expr.tree; + } ; //except_clause: 'except' [test [',' test]] -except_clause : EXCEPT (t1=test[expr_contextType.Load] (COMMA t2=test[expr_contextType.Store])?)? COLON suite - -> ^(EXCEPT<excepthandlerType>[$EXCEPT, (exprType)$t1.tree, (exprType)$t2.tree, actions.makeStmts($suite.stypes), $EXCEPT.getLine(), $EXCEPT.getCharPositionInLine()]) - ; +except_clause + : EXCEPT (t1=test[expr_contextType.Load] (COMMA t2=test[expr_contextType.Store])?)? COLON suite + -> ^(EXCEPT<excepthandlerType>[$EXCEPT, (exprType)$t1.tree, (exprType)$t2.tree, + actions.makeStmts($suite.stypes), $EXCEPT.getLine(), $EXCEPT.getCharPositionInLine()]) + ; //suite: simple_stmt | NEWLINE INDENT stmt+ DEDENT suite returns [List stypes] @init { $stypes = new ArrayList(); } - : simple_stmt {$stypes = $simple_stmt.stypes;} - | NEWLINE! INDENT - (stmt {$stypes.addAll($stmt.stypes);} + : simple_stmt + { + $stypes = $simple_stmt.stypes; + } + | NEWLINE INDENT + (stmt + { + $stypes.addAll($stmt.stypes); + } )+ DEDENT ; //test: or_test ['if' or_test 'else' test] | lambdef test[expr_contextType ctype] :o1=or_test[ctype] - ( (IF or_test[null] ORELSE) => IF o2=or_test[ctype] ORELSE e=test[expr_contextType.Load] - -> ^(IF<IfExp>[$IF, (exprType)$o2.tree, (exprType)$o1.tree, (exprType)$e.tree]) - | -> or_test - ) - | lambdef {debug("parsed lambdef");} + ( (IF or_test[null] ORELSE) => IF o2=or_test[ctype] ORELSE e=test[expr_contextType.Load] + -> ^(IF<IfExp>[$IF, (exprType)$o2.tree, (exprType)$o1.tree, (exprType)$e.tree]) + | + -> or_test + ) + | lambdef ; //or_test: and_test ('or' and_test)* @@ -828,7 +897,8 @@ : left=and_test[ctype] ( (or=OR right+=and_test[ctype] )+ - | -> $left + | + -> $left ) ; @@ -843,7 +913,8 @@ ( (and=AND right+=not_test[ctype] )+ | - ) -> $left + -> $left + ) ; //not_test: 'not' not_test | comparison @@ -853,7 +924,10 @@ $not_test.tree = $etype; } } - : NOT nt=not_test[ctype] {$etype = new UnaryOp($NOT, unaryopType.Not, (exprType)$nt.tree);} + : NOT nt=not_test[ctype] + { + $etype = new UnaryOp($NOT, unaryopType.Not, (exprType)$nt.tree); + } | comparison[ctype] ; @@ -864,13 +938,15 @@ } @after { if (!cmps.isEmpty()) { - $comparison.tree = new Compare($left.tree, (exprType)$left.tree, actions.makeCmpOps(cmps), actions.makeExprs($right)); + $comparison.tree = new Compare($left.tree, (exprType)$left.tree, actions.makeCmpOps(cmps), + actions.makeExprs($right)); } } : left=expr[ctype] ( ( comp_op right+=expr[ctype] {cmps.add($comp_op.op);} )+ - | -> $left + | + -> $left ) ; @@ -906,7 +982,8 @@ : left=xor_expr ( (op=VBAR right+=xor_expr )+ - | -> $left + | + -> $left ) ; @@ -921,7 +998,8 @@ : left=and_expr ( (op=CIRCUMFLEX right+=and_expr )+ - | -> $left + | + -> $left ) ; @@ -935,7 +1013,8 @@ : left=shift_expr ( (op=AMPER right+=shift_expr )+ - | -> $left + | + -> $left ) ; @@ -952,7 +1031,8 @@ : left=arith_expr ( ( shift_op right+=arith_expr {ops.add($shift_op.op);} )+ - | -> $left + | + -> $left ) ; @@ -974,7 +1054,8 @@ : left=term ( (arith_op right+=term {ops.add($arith_op.op);} )+ - | -> $left + | + -> $left ) ; @@ -996,7 +1077,8 @@ : left=factor ( (term_op right+=factor {ops.add($term_op.op);} )+ - | -> $left + | + -> $left ) ; @@ -1023,38 +1105,37 @@ @after { $power.tree = $etype; } - : atom (t+=trailer[$atom.start])* (options {greedy=true;}:d=DOUBLESTAR factor)? { - //System.out.println("??? " + $d + " ??? " + $factor.tree); - $etype = (exprType)$atom.tree; - if ($t != null) { - //for(int i = $t.size() - 1; i > -1; i--) { - for(int i = 0; i < $t.size(); i++) { - Object o = $t.get(i); - if ($etype instanceof Context) { - ((Context)$etype).setContext(expr_contextType.Load); - } - //XXX: good place for an interface to avoid all of this instanceof - if (o instanceof Call) { - Call c = (Call)o; - c.func = $etype; - $etype = c; - } else if (o instanceof Subscript) { - Subscript c = (Subscript)o; - c.value = $etype; - $etype = c; - } else if (o instanceof Attribute) { - Attribute c = (Attribute)o; - c.value = $etype; - $etype = c; - } - } - } - if ($d != null) { - List right = new ArrayList(); - right.add($factor.tree); - $etype = actions.makeBinOp($etype, operatorType.Pow, right); - } - } + : atom (t+=trailer[$atom.start])* (options {greedy=true;}:d=DOUBLESTAR factor)? + { + $etype = (exprType)$atom.tree; + if ($t != null) { + for(int i = 0; i < $t.size(); i++) { + Object o = $t.get(i); + if ($etype instanceof Context) { + ((Context)$etype).setContext(expr_contextType.Load); + } + //XXX: good place for an interface to avoid all of this instanceof + if (o instanceof Call) { + Call c = (Call)o; + c.func = $etype; + $etype = c; + } else if (o instanceof Subscript) { + Subscript c = (Subscript)o; + c.value = $etype; + $etype = c; + } else if (o instanceof Attribute) { + Attribute c = (Attribute)o; + c.value = $etype; + $etype = c; + } + } + } + if ($d != null) { + List right = new ArrayList(); + right.add($factor.tree); + $etype = actions.makeBinOp($etype, operatorType.Pow, right); + } + } ; //atom: ('(' [yield_expr|testlist_gexp] ')' | @@ -1062,30 +1143,45 @@ // '{' [dictmaker] '}' | // '`' testlist1 '`' | // NAME | NUMBER | STRING+) -atom : LPAREN - ( yield_expr -> yield_expr - | testlist_gexp -> testlist_gexp - | -> ^(PYNODE<Tuple>[$LPAREN, new exprType[0\], $expr::ctype]) +atom + : LPAREN + ( yield_expr + -> yield_expr + | testlist_gexp + -> testlist_gexp + | + -> ^(LPAREN<Tuple>[$LPAREN, new exprType[0\], $expr::ctype]) + ) + RPAREN + | LBRACK + (listmaker[$LBRACK] + -> listmaker + | + -> ^(LBRACK<org.python.antlr.ast.List>[$LBRACK, new exprType[0\], $expr::ctype]) + ) + RBRACK + | LCURLY + (dictmaker + -> ^(LCURLY<Dict>[$LCURLY, actions.makeExprs($dictmaker.keys), + actions.makeExprs($dictmaker.values)]) + | + -> ^(LCURLY<Dict>[$LCURLY, new exprType[0\], new exprType[0\]]) ) - RPAREN - | LBRACK - (listmaker[$LBRACK] -> listmaker - | -> ^(LBRACK<org.python.antlr.ast.List>[$LBRACK, new exprType[0\], $expr::ctype]) - ) - RBRACK - | LCURLY - (dictmaker -> ^(LCURLY<Dict>[$LCURLY, actions.makeExprs($dictmaker.keys), actions.makeExprs($dictmaker.values)]) - | -> ^(LCURLY<Dict>[$LCURLY, new exprType[0\], new exprType[0\]]) - ) RCURLY - | lb=BACKQUOTE testlist[expr_contextType.Load] rb=BACKQUOTE -> ^(BACKQUOTE<Repr>[$lb, (exprType)$testlist.tree]) - | NAME -> ^(PYNODE<Name>[$NAME, $NAME.text, $expr::ctype]) - | INT -> ^(PYNODE<Num>[$INT, actions.makeInt($INT)]) - | LONGINT -> ^(PYNODE<Num>[$LONGINT, actions.makeInt($LONGINT)]) - | FLOAT -> ^(PYNODE<Num>[$FLOAT, actions.makeFloat($FLOAT)]) - | COMPLEX -> ^(PYNODE<Num>[$COMPLEX, actions.makeComplex($COMPLEX)]) + | lb=BACKQUOTE testlist[expr_contextType.Load] rb=BACKQUOTE + -> ^(BACKQUOTE<Repr>[$lb, (exprType)$testlist.tree]) + | NAME + -> ^(NAME<Name>[$NAME, $NAME.text, $expr::ctype]) + | INT + -> ^(INT<Num>[$INT, actions.makeInt($INT)]) + | LONGINT + -> ^(LONGINT<Num>[$LONGINT, actions.makeInt($LONGINT)]) + | FLOAT + -> ^(FLOAT<Num>[$FLOAT, actions.makeFloat($FLOAT)]) + | COMPLEX + -> ^(COMPLEX<Num>[$COMPLEX, actions.makeComplex($COMPLEX)]) | (S+=STRING)+ - -> ^(PYNODE<Str>[actions.extractStringToken($S), actions.extractStrings($S)]) + -> ^(STRING<Str>[actions.extractStringToken($S), actions.extractStrings($S)]) ; //listmaker: test ( list_for | (',' test)* [','] ) @@ -1098,15 +1194,18 @@ $listmaker.tree = etype; } : t+=test[expr_contextType.Load] - ( list_for[gens] { - Collections.reverse(gens); - comprehensionType[] c = (comprehensionType[])gens.toArray(new comprehensionType[gens.size()]); - etype = new ListComp($listmaker.start, (exprType)$t.get(0), c); - } - | (options {greedy=true;}:COMMA t+=test[expr_contextType.Load])* { - etype = new org.python.antlr.ast.List($lbrack, actions.makeExprs($t), $expr::ctype); - } - ) (COMMA)? + (list_for[gens] + { + Collections.reverse(gens); + comprehensionType[] c = + (comprehensionType[])gens.toArray(new comprehensionType[gens.size()]); + etype = new ListComp($listmaker.start, (exprType)$t.get(0), c); + } + | (options {greedy=true;}:COMMA t+=test[expr_contextType.Load])* + { + etype = new org.python.antlr.ast.List($lbrack, actions.makeExprs($t), $expr::ctype); + } + ) (COMMA)? ; //testlist_gexp: test ( gen_for | (',' test)* [','] ) @@ -1122,18 +1221,20 @@ } : t+=test[$expr::ctype] ( ((options {k=2;}: c1=COMMA t+=test[$expr::ctype])* (c2=COMMA)? - -> { $c1 != null || $c2 != null }? ^(PYNODE<Tuple>[$testlist_gexp.start, actions.makeExprs($t), $expr::ctype]) - -> test + -> { $c1 != null || $c2 != null }? + ^(COMMA<Tuple>[$testlist_gexp.start, actions.makeExprs($t), $expr::ctype]) + -> test ) - | ( gen_for[gens] { - Collections.reverse(gens); - comprehensionType[] c = (comprehensionType[])gens.toArray(new comprehensionType[gens.size()]); - exprType e = (exprType)$t.get(0); - if (e instanceof Context) { - ((Context)e).setContext(expr_contextType.Load); - } - etype = new GeneratorExp($testlist_gexp.start, (exprType)$t.get(0), c); - } + | (gen_for[gens] + { + Collections.reverse(gens); + comprehensionType[] c = (comprehensionType[])gens.toArray(new comprehensionType[gens.size()]); + exprType e = (exprType)$t.get(0); + if (e instanceof Context) { + ((Context)e).setContext(expr_contextType.Load); + } + etype = new GeneratorExp($testlist_gexp.start, (exprType)$t.get(0), c); + } ) ) ; @@ -1146,23 +1247,31 @@ @after { $lambdef.tree = etype; } - : LAMBDA (varargslist)? COLON test[expr_contextType.Load] { - argumentsType a = $varargslist.args; - if (a == null) { - a = new argumentsType($LAMBDA, new exprType[0], null, null, new exprType[0]); - } - etype = new Lambda($LAMBDA, a, (exprType)$test.tree); - } + : LAMBDA (varargslist)? COLON test[expr_contextType.Load] + { + argumentsType a = $varargslist.args; + if (a == null) { + a = new argumentsType($LAMBDA, new exprType[0], null, null, new exprType[0]); + } + etype = new Lambda($LAMBDA, a, (exprType)$test.tree); + } ; //trailer: '(' [arglist] ')' | '[' subscriptlist ']' | '.' NAME -trailer [Token begin]: LPAREN (arglist -> ^(LPAREN<Call>[$begin, null, actions.makeExprs($arglist.args), actions.makeKeywords($arglist.keywords), $arglist.starargs, $arglist.kwargs]) - | -> ^(LPAREN<Call>[$LPAREN, null, new exprType[0\], new keywordType[0\], null, null]) - ) - RPAREN - | LBRACK s=subscriptlist[begin] RBRACK -> $s - | DOT attr -> ^(DOT<Attribute>[$begin, null, $attr.text, $expr::ctype]) - ; +trailer [Token begin] + : LPAREN + (arglist + -> ^(LPAREN<Call>[$begin, null, actions.makeExprs($arglist.args), + actions.makeKeywords($arglist.keywords), $arglist.starargs, $arglist.kwargs]) + | + -> ^(LPAREN<Call>[$LPAREN, null, new exprType[0\], new keywordType[0\], null, null]) + ) + RPAREN + | LBRACK s=subscriptlist[begin] RBRACK + -> $s + | DOT attr + -> ^(DOT<Attribute>[$begin, null, $attr.text, $expr::ctype]) + ; //subscriptlist: subscript (',' subscript)* [','] //FIXME: tuples not always created when commas are present. @@ -1173,44 +1282,44 @@ @after { $subscriptlist.tree = etype; } - : sub+=subscript (options {greedy=true;}:c1=COMMA sub+=subscript)* (c2=COMMA)? { - boolean isTuple = false; - if ($c1 != null || $c2 != null) { - isTuple = true; - } - sliceType s = null; - List sltypes = $sub; - boolean extslice = false; + : sub+=subscript (options {greedy=true;}:c1=COMMA sub+=subscript)* (c2=COMMA)? + { + boolean isTuple = false; + if ($c1 != null || $c2 != null) { + isTuple = true; + } + sliceType s = null; + List sltypes = $sub; + boolean extslice = false; - //NEW LOGIC - if (isTuple) { - sliceType[] st; - List etypes = new ArrayList(); - for (Object o : sltypes) { - if (o instanceof Index) { - Index i = (Index)o; - etypes.add(i.value); - } else { - extslice = true; - break; - } - } - if (!extslice) { - exprType[] es = (exprType[])etypes.toArray(new exprType[etypes.size()]); - exprType t = new Tuple($begin, es, expr_contextType.Load); - s = new Index($begin, t); - } - } else if (sltypes.size() == 1) { - s = (sliceType)sltypes.get(0); - } else if (sltypes.size() != 0) { - extslice = true; - } - if (extslice) { - sliceType[] st = (sliceType[])sltypes.toArray(new sliceType[sltypes.size()]); - s = new ExtSlice($begin, st); - } - etype = new Subscript($begin, null, s, $expr::ctype); - } + if (isTuple) { + sliceType[] st; + List etypes = new ArrayList(); + for (Object o : sltypes) { + if (o instanceof Index) { + Index i = (Index)o; + etypes.add(i.value); + } else { + extslice = true; + break; + } + } + if (!extslice) { + exprType[] es = (exprType[])etypes.toArray(new exprType[etypes.size()]); + exprType t = new Tuple($begin, es, expr_contextType.Load); + s = new Index($begin, t); + } + } else if (sltypes.size() == 1) { + s = (sliceType)sltypes.get(0); + } else if (sltypes.size() != 0) { + extslice = true; + } + if (extslice) { + sliceType[] st = (sliceType[])sltypes.toArray(new sliceType[sltypes.size()]); + s = new ExtSlice($begin, st); + } + etype = new Subscript($begin, null, s, $expr::ctype); + } ; //subscript: '.' '.' '.' | test | [test] ':' [test] [sliceop] @@ -1220,39 +1329,49 @@ $subscript.tree = $sltype; } } - : d1=DOT DOT DOT -> DOT<Ellipsis>[$d1] - | (test[null] COLON) => lower=test[expr_contextType.Load] (c1=COLON (upper1=test[expr_contextType.Load])? (sliceop)?)? { + : d1=DOT DOT DOT + -> DOT<Ellipsis>[$d1] + | (test[null] COLON) + => lower=test[expr_contextType.Load] (c1=COLON (upper1=test[expr_contextType.Load])? (sliceop)?)? + { $sltype = actions.makeSubscript($lower.tree, $c1, $upper1.tree, $sliceop.tree); - } - | (COLON) => c2=COLON (upper2=test[expr_contextType.Load])? (sliceop)? { - $sltype = actions.makeSubscript(null, $c2, $upper2.tree, $sliceop.tree); - } - | test[expr_contextType.Load] -> ^(PYNODE<Index>[$test.start, (exprType)$test.tree]) + } + | (COLON) + => c2=COLON (upper2=test[expr_contextType.Load])? (sliceop)? + { + $sltype = actions.makeSubscript(null, $c2, $upper2.tree, $sliceop.tree); + } + | test[expr_contextType.Load] + -> ^(LPAREN<Index>[$test.start, (exprType)$test.tree]) ; //sliceop: ':' [test] -sliceop : COLON (test[expr_contextType.Load] -> test - )? - ; +sliceop + : COLON + (test[expr_contextType.Load] + -> test + )? + ; //exprlist: expr (',' expr)* [','] exprlist[expr_contextType ctype] returns [exprType etype] - : (expr[null] COMMA) => e+=expr[ctype] (options {k=2;}: COMMA e+=expr[ctype])* (COMMA)? { - $etype = new Tuple($exprlist.start, actions.makeExprs($e), ctype); - } - | expr[ctype] { - //System.out.println("expecting " + ctype); + : (expr[null] COMMA) => e+=expr[ctype] (options {k=2;}: COMMA e+=expr[ctype])* (COMMA)? + { + $etype = new Tuple($exprlist.start, actions.makeExprs($e), ctype); + } + | expr[ctype] + { $etype = (exprType)$expr.tree; - //System.out.println("got " + ((Name)$etype).ctx); - - } + } ; //XXX: I'm hoping I can get rid of this and merge it back with exprlist -- but for now I need an exprlist that does not produce tuples // at least for del_stmt del_list returns [List etypes] : e+=expr[expr_contextType.Del] (options {k=2;}: COMMA e+=expr[expr_contextType.Del])* (COMMA)? - {$etypes = $e;} + { + $etypes = $e; + } ; //testlist: test (',' test)* [','] @@ -1263,12 +1382,15 @@ @after { $testlist.tree = etype; } - : (test[null] COMMA) => t+=test[ctype] (options {k=2;}: c1=COMMA t+=test[ctype])* (c2=COMMA)? { + : (test[null] COMMA) + => t+=test[ctype] (options {k=2;}: c1=COMMA t+=test[ctype])* (c2=COMMA)? + { etype = new Tuple($testlist.start, actions.makeExprs($t), ctype); - } - | test[ctype] { + } + | test[ctype] + { etype = (exprType)$test.tree; - } + } ; //XXX: @@ -1277,8 +1399,9 @@ //dictmaker: test ':' test (',' test ':' test)* [','] dictmaker returns [List keys, List values] : k+=test[expr_contextType.Load] COLON v+=test[expr_contextType.Load] - (options {k=2;}:COMMA k+=test[expr_contextType.Load] COLON v+=test[expr_contextType.Load])* - (COMMA)? { + (options {k=2;}:COMMA k+=test[expr_contextType.Load] COLON v+=test[expr_contextType.Load])* + (COMMA)? + { $keys = $k; $values= $v; } @@ -1292,9 +1415,11 @@ @after { $classdef.tree = stype; } - :CLASS NAME (LPAREN testlist[expr_contextType.Load]? RPAREN)? COLON suite { - stype = new ClassDef($CLASS, $NAME.getText(), actions.makeBases((exprType)$testlist.tree), actions.makeStmts($suite.stypes)); - } + : CLASS NAME (LPAREN testlist[expr_contextType.Load]? RPAREN)? COLON suite + { + stype = new ClassDef($CLASS, $NAME.getText(), actions.makeBases((exprType)$testlist.tree), + actions.makeStmts($suite.stypes)); + } ; //arglist: (argument ',')* (argument [',']| '*' test [',' '**' test] | '**' test) @@ -1304,24 +1429,27 @@ List kws = new ArrayList(); } : argument[arguments, kws] (COMMA argument[arguments, kws])* - ( COMMA - ( STAR s=test[expr_contextType.Load] (COMMA DOUBLESTAR k=test[expr_contextType.Load])? - | DOUBLESTAR k=test[expr_contextType.Load] - )? - )? { - $args=arguments; - $keywords=kws; - $starargs=(exprType)$s.tree; + (COMMA + ( STAR s=test[expr_contextType.Load] (COMMA DOUBLESTAR k=test[expr_contextType.Load])? + | DOUBLESTAR k=test[expr_contextType.Load] + )? + )? + { + $args=arguments; + $keywords=kws; + $starargs=(exprType)$s.tree; + $kwargs=(exprType)$k.tree; + } + | STAR s=test[expr_contextType.Load] (COMMA DOUBLESTAR k=test[expr_contextType.Load])? + { + $starargs=(exprType)$s.tree; $kwargs=(exprType)$k.tree; - } - | STAR s=test[expr_contextType.Load] (COMMA DOUBLESTAR k=test[expr_contextType.Load])? { - $starargs=(exprType)$s.tree; + } + | DOUBLESTAR k=test[expr_contextType.Load] + { $kwargs=(exprType)$k.tree; - } - | DOUBLESTAR k=test[expr_contextType.Load] { - $kwargs=(exprType)$k.tree; - } - ; + } + ; //argument: test [gen_for] | test '=' test # Really [keyword '='] test argument[List arguments, List kws] @@ -1329,15 +1457,19 @@ List gens = new ArrayList(); } : t1=test[expr_contextType.Load] - ( (ASSIGN t2=test[expr_contextType.Load]) { - $kws.add(new exprType[]{(exprType)$t1.tree, (exprType)$t2.tree}); - } - | gen_for[gens] { - Collections.reverse(gens); - comprehensionType[] c = (comprehensionType[])gens.toArray(new comprehensionType[gens.size()]); - arguments.add(new GeneratorExp($gen_for.start, (exprType)$t1.tree, c)); - } - | {$arguments.add($t1.tree);} + ((ASSIGN t2=test[expr_contextType.Load]) + { + $kws.add(new exprType[]{(exprType)$t1.tree, (exprType)$t2.tree}); + } + | gen_for[gens] + { + Collections.reverse(gens); + comprehensionType[] c = (comprehensionType[])gens.toArray(new comprehensionType[gens.size()]); + arguments.add(new GeneratorExp($gen_for.start, (exprType)$t1.tree, c)); + } + | { + $arguments.add($t1.tree); + } ) ; @@ -1351,20 +1483,22 @@ //list_for: 'for' exprlist 'in' testlist_safe [list_iter] list_for [List gens] - : FOR exprlist[expr_contextType.Store] IN testlist[expr_contextType.Load] (list_iter[gens])? { - exprType[] e; - if ($list_iter.etype != null) { - e = new exprType[]{$list_iter.etype}; - } else { - e = new exprType[0]; - } - gens.add(new comprehensionType($FOR, $exprlist.etype, (exprType)$testlist.tree, e)); - } + : FOR exprlist[expr_contextType.Store] IN testlist[expr_contextType.Load] (list_iter[gens])? + { + exprType[] e; + if ($list_iter.etype != null) { + e = new exprType[]{$list_iter.etype}; + } else { + e = new exprType[0]; + } + gens.add(new comprehensionType($FOR, $exprlist.etype, (exprType)$testlist.tree, e)); + } ; //list_if: 'if' test [list_iter] list_if[List gens] returns [exprType etype] - : IF test[expr_contextType.Load] (list_iter[gens])? { + : IF test[expr_contextType.Load] (list_iter[gens])? + { $etype = (exprType)$test.tree; } ; @@ -1372,35 +1506,39 @@ //gen_iter: gen_for | gen_if gen_iter [List gens] returns [exprType etype] : gen_for[gens] - | gen_if[gens] { - $etype = $gen_if.etype; - } + | gen_if[gens] + { + $etype = $gen_if.etype; + } ; //gen_for: 'for' exprlist 'in' or_test [gen_iter] gen_for [List gens] - :FOR exprlist[expr_contextType.Store] IN or_test[expr_contextType.Load] gen_iter[gens]? { - exprType[] e; - if ($gen_iter.etype != null) { - e = new exprType[]{$gen_iter.etype}; - } else { - e = new exprType[0]; - } - gens.add(new comprehensionType($FOR, $exprlist.etype, (exprType)$or_test.tree, e)); - } - ; + : FOR exprlist[expr_contextType.Store] IN or_test[expr_contextType.Load] gen_iter[gens]? + { + exprType[] e; + if ($gen_iter.etype != null) { + e = new exprType[]{$gen_iter.etype}; + } else { + e = new exprType[0]; + } + gens.add(new comprehensionType($FOR, $exprlist.etype, (exprType)$or_test.tree, e)); + } + ; //gen_if: 'if' old_test [gen_iter] gen_if[List gens] returns [exprType etype] - : IF test[expr_contextType.Load] gen_iter[gens]? { - $etype = (exprType)$test.tree; - } + : IF test[expr_contextType.Load] gen_iter[gens]? + { + $etype = (exprType)$test.tree; + } ; //yield_expr: 'yield' [testlist] -yield_expr : YIELD testlist[expr_contextType.Load]? - -> ^(YIELD<Yield>[$YIELD, (exprType)$testlist.tree]) - ; +yield_expr + : YIELD testlist[expr_contextType.Load]? + -> ^(YIELD<Yield>[$YIELD, (exprType)$testlist.tree]) + ; //XXX: //testlist1: test (',' test)* Modified: branches/nowalker/src/org/python/antlr/ModuleParser.java =================================================================== --- branches/nowalker/src/org/python/antlr/ModuleParser.java 2008-08-25 21:18:03 UTC (rev 5247) +++ branches/nowalker/src/org/python/antlr/ModuleParser.java 2008-08-26 02:04:27 UTC (rev 5248) @@ -34,28 +34,14 @@ tokens = new CommonTokenStream(indentedSource); PythonParser parser = new PythonParser(tokens); parser.setErrorHandler(errorHandler); - //PythonTreeAdaptor pta = new PythonTreeAdaptor(); parser.setTreeAdaptor(new PythonTreeAdaptor()); try { PythonParser.file_input_return r = parser.file_input(); tree = (modType)r.tree; - //CommonTreeNodeStream nodes = new CommonTreeNodeStream(new PythonTreeAdaptor(), (Tree)r.tree); - //nodes.setTokenStream(tokens); - //PythonWalker walker = new PythonWalker(nodes); - //walker.setTreeAdaptor(new PythonTreeAdaptor()); - //walker.setErrorHandler(errorHandler); - //tree = (modType)walker.module().tree; - if (tree == null) { - //XXX: seems like I should be able to get antlr to give me an empty Module instead - // of null so I wouldn't need to build an empty Module by hand here... - return new Module(new PythonTree(new CommonToken(PyLexer.PYNODE)), new stmtType[0]); - } } catch (RecognitionException e) { //XXX: this can't happen. Need to strip the throws from antlr // generated code. } - return tree; } - } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fwi...@us...> - 2008-08-25 21:18:10
|
Revision: 5247 http://jython.svn.sourceforge.net/jython/?rev=5247&view=rev Author: fwierzbicki Date: 2008-08-25 21:18:03 +0000 (Mon, 25 Aug 2008) Log Message: ----------- Fix ** Modified Paths: -------------- branches/nowalker/grammar/Python.g Modified: branches/nowalker/grammar/Python.g =================================================================== --- branches/nowalker/grammar/Python.g 2008-08-25 20:36:04 UTC (rev 5246) +++ branches/nowalker/grammar/Python.g 2008-08-25 21:18:03 UTC (rev 5247) @@ -1021,36 +1021,39 @@ //power: atom trailer* ['**' factor] power returns [exprType etype] @after { - if ($etype != null) { - $power.tree = $etype; - } + $power.tree = $etype; } - : atom (t+=trailer[$atom.start])* (options {greedy=true;}:DOUBLESTAR factor)? { + : atom (t+=trailer[$atom.start])* (options {greedy=true;}:d=DOUBLESTAR factor)? { + //System.out.println("??? " + $d + " ??? " + $factor.tree); + $etype = (exprType)$atom.tree; if ($t != null) { - exprType current = (exprType)$atom.tree; //for(int i = $t.size() - 1; i > -1; i--) { for(int i = 0; i < $t.size(); i++) { Object o = $t.get(i); - if (current instanceof Context) { - ((Context)current).setContext(expr_contextType.Load); + if ($etype instanceof Context) { + ((Context)$etype).setContext(expr_contextType.Load); } //XXX: good place for an interface to avoid all of this instanceof if (o instanceof Call) { Call c = (Call)o; - c.func = current; - current = c; + c.func = $etype; + $etype = c; } else if (o instanceof Subscript) { Subscript c = (Subscript)o; - c.value = current; - current = c; + c.value = $etype; + $etype = c; } else if (o instanceof Attribute) { Attribute c = (Attribute)o; - c.value = current; - current = c; + c.value = $etype; + $etype = c; } } - $etype = (exprType)current; } + if ($d != null) { + List right = new ArrayList(); + right.add($factor.tree); + $etype = actions.makeBinOp($etype, operatorType.Pow, right); + } } ; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |