Issue #795 -- clean up low precedence levels

This commit is contained in:
Jeremy Ashkenas 2010-10-24 14:02:59 -04:00
parent 3a64e6a711
commit d6d46697d0
6 changed files with 20 additions and 20 deletions

View File

@ -596,7 +596,7 @@
})
]
};
operators = [["left", 'CALL_START', 'CALL_END'], ["nonassoc", '++', '--'], ["left", '?'], ["right", 'UNARY'], ["left", 'MATH'], ["left", '+', '-'], ["left", 'SHIFT'], ["left", 'RELATION'], ["left", 'COMPARE'], ["left", 'LOGIC'], ["left", '.'], ["nonassoc", 'INDENT', 'OUTDENT'], ["right", 'WHEN', 'LEADING_WHEN', 'FORIN', 'FOROF', 'FROM', 'TO', 'BY', 'THROW'], ["right", 'IF', 'UNLESS', 'ELSE', 'FOR', 'WHILE', 'UNTIL', 'LOOP', 'SUPER', 'CLASS', 'EXTENDS'], ["right", '=', ':', 'COMPOUND_ASSIGN', 'RETURN'], ["right", 'POST_IF', 'POST_UNLESS']];
operators = [["left", 'CALL_START', 'CALL_END'], ["nonassoc", '++', '--'], ["left", '?'], ["right", 'UNARY'], ["left", 'MATH'], ["left", '+', '-'], ["left", 'SHIFT'], ["left", 'RELATION'], ["left", 'COMPARE'], ["left", 'LOGIC'], ["left", '.'], ["nonassoc", 'INDENT', 'OUTDENT'], ["right", '=', ':', 'COMPOUND_ASSIGN', 'RETURN'], ["right", 'WHEN', 'LEADING_WHEN', 'FORIN', 'FOROF', 'FROM', 'TO', 'BY', 'THROW'], ["right", 'IF', 'UNLESS', 'POST_IF', 'POST_UNLESS', 'ELSE', 'FOR', 'WHILE', 'UNTIL', 'LOOP', 'SUPER', 'CLASS', 'EXTENDS']];
tokens = [];
for (name in grammar) {
alternatives = grammar[name];

File diff suppressed because one or more lines are too long

View File

@ -569,10 +569,10 @@ operators = [
["left", 'LOGIC']
["left", '.']
["nonassoc", 'INDENT', 'OUTDENT']
["right", 'WHEN', 'LEADING_WHEN', 'FORIN', 'FOROF', 'FROM', 'TO', 'BY', 'THROW']
["right", 'IF', 'UNLESS', 'ELSE', 'FOR', 'WHILE', 'UNTIL', 'LOOP', 'SUPER', 'CLASS', 'EXTENDS']
["right", '=', ':', 'COMPOUND_ASSIGN', 'RETURN']
["right", 'POST_IF', 'POST_UNLESS']
["right", 'WHEN', 'LEADING_WHEN', 'FORIN', 'FOROF', 'FROM', 'TO', 'BY', 'THROW']
["right", 'IF', 'UNLESS', 'POST_IF', 'POST_UNLESS', 'ELSE', 'FOR', 'WHILE',
'UNTIL', 'LOOP', 'SUPER', 'CLASS', 'EXTENDS']
]
# Wrapping Up

View File

@ -1,22 +1,22 @@
# Basic array comprehensions.
nums = n * n for n in [1, 2, 3] when n % 2 isnt 0
results = n * 2 for n in nums
nums = (n * n for n in [1, 2, 3] when n % 2 isnt 0)
results = (n * 2 for n in nums)
ok results.join(',') is '2,18'
# Basic object comprehensions.
obj = {one: 1, two: 2, three: 3}
names = prop + '!' for prop of obj
odds = prop + '!' for prop, value of obj when value % 2 isnt 0
names = (prop + '!' for prop of obj)
odds = (prop + '!' for prop, value of obj when value % 2 isnt 0)
ok names.join(' ') is "one! two! three!"
ok odds.join(' ') is "one! three!"
# Basic range comprehensions.
nums = i * 3 for i from 1 to 3
negs = x for x from -20 to -5*2
nums = (i * 3 for i from 1 to 3)
negs = (x for x from -20 to -5*2)
eq nums.concat(negs.slice 0, 3).join(' '), '3 6 9 -20 -19 -18'
@ -35,7 +35,7 @@ eq evens + '', '4,6,8'
# Backward traversing.
odds = num for num in [0, 1, 2, 3, 4, 5] by -2
odds = (num for num in [0, 1, 2, 3, 4, 5] by -2)
eq odds + '', '5,3,1'
@ -53,7 +53,7 @@ multiLiner =
[x, y]
singleLiner =
[x, y] for y from 3 to 5 for x from 3 to 5
(([x, y] for y from 3 to 5) for x from 3 to 5)
ok multiLiner.length is singleLiner.length
ok 5 is multiLiner[2][2][1]
@ -70,7 +70,7 @@ ok result.join(' ') is '6 4 2'
# Closure-wrapped comprehensions that refer to the "arguments" object.
expr = ->
result = item * item for item in arguments
result = (item * item for item in arguments)
ok expr(2, 4, 8).join(' ') is '4 16 64'
@ -82,8 +82,8 @@ class Cat
hair: 'cream'
whiskers = new Cat
own = value for key, value of whiskers
all = value for all key, value of whiskers
own = (value for key, value of whiskers)
all = (value for all key, value of whiskers)
ok own.join(' ') is 'Whiskers'
ok all.sort().join(' ') is 'Whiskers cream tabby'

View File

@ -111,7 +111,7 @@ persons = {
Christopher: { name: "Stan" }
}
join1 = "#{key}: #{name}" for key, { name } of persons
join1 = ("#{key}: #{name}" for key, { name } of persons)
eq join1.join(' / '), "George: Bob / Bob: Alice / Christopher: Stan"
@ -121,12 +121,12 @@ persons = [
{ name: "Stan", parent: { name: "Christopher" } }
]
join2 = "#{parent}: #{name}" for { name, parent: { name: parent } } in persons
join2 = ("#{parent}: #{name}" for { name, parent: { name: parent } } in persons)
eq join1.join(' '), join2.join(' ')
persons = [['Bob', ['George']], ['Alice', ['Bob']], ['Stan', ['Christopher']]]
join3 = "#{parent}: #{name}" for [name, [parent]] in persons
join3 = ("#{parent}: #{name}" for [name, [parent]] in persons)
eq join2.join(' '), join3.join(' ')

View File

@ -1,6 +1,6 @@
# Expression conversion under explicit returns.
first = ->
return 'do' for x in [1,2,3]
return ('do' for x in [1,2,3])
second = ->
return ['re' for x in [1,2,3]]