Used to be that RAW, the sniper wasn't getting the sneak attack. Why? No good reason other than that "a legalistic reading of the rules said so." There are no end of huge threads on paizo.com going over in tortuous detail how vision and stealth and all that work in PF core, especially here and here, and the summary was "slavishly following the rules means things that make no sense." You never get sneak attack from stealth because "you can't stealth while attacking" and "it doesn't say you get sneak attack just because someone can't see you, as hidden isn't an official condition (tm)."
I would previously invoke GM privilege to implement RAI - as in Pathfinder they say clearly "the GM is the law over and above the written rules" - and make it so they get their sneak attack. Because it makes sense from a game world logic/sim point of view and you can rule that's more important than the RAW point of view. IMO the clear intent was to sneak-attack someone from Stealth. You know, "sneak," "attack," things that happen in the real world and every previous edition of D&D.
Can I Attack From Stealth?
Now, however, the Stealth rules have been errata'ed to specifically say "you can attack from stealth" which means that yes, you get the sneak attack. See the updated version on the PRD which says:
Breaking Stealth: When you start your turn using Stealth, you can leave cover or concealment and remain unobserved as long as you succeed at a Stealth check and end your turn in cover or concealment. Your Stealth immediately ends after you make an attack roll, whether or not the attack is successful (except when sniping as noted below).
Sniping: If you've already successfully used Stealth at least 10 feet from your target, you can make one ranged attack and then immediately use Stealth again. You take a –20 penalty on your Stealth check to maintain your obscured location.
So the RAW has been updated to match the RAI for whatever that's worth (apparently it's really meaningful to some, though all my rogues have been happily sneak attacking from Stealth since the year 2000...).
Does A Stealthed Attack Enable Sneak Attack?
Yes, if you're stealthed, your attacks are sneak attacks.
Jason Buhlman states the intent clearly on the Paizo forums:
For simplicities sake, it should be assumed that those making Perception checks get to do so at the most favorable point during the movement of a character using Stealth, to avoid making checks every time the condition changes. Technically, I think you would get a check whenever the conditions change, but that might make things overly complicated during play.
Creatures are denied their Dexterity bonus to AC "if they cannot react to a blow" (CR pg 179 under AC). It was our intent that if you are unaware of a threat, you cannot react to a blow. I think we probably should have spelled this out a wee bit clearer, but space in the Stealth description was extraordinarily tight and ever word was at a premium. That said, I think these changes clear up the situation immensely (compared to where they were.. which was nebulous at best).
They didn't bother changing the RAW because most people use common sense and play it that way. Stealthed = sneak, etc.
RAW + Pathfinder = Sad Panda
This is why, whether you like this or not, a pure RAW approach to Pathfinder is always going to be frustrating; the devs explicitly don't bother to clean up RAW when RAI and/or common sense is clear. It's not a priority of theirs and I for one am pretty happy about that - they spend their intellectual capital making new interesting fun content instead of crafting rules and just retreading the same content year after year like WotC did with 3.5 (Return to the Return to the 1e Module, anyone?).
The rules do allow such a readied Sneak Attack
The wording of that passage in grease is, in my mind, very unclear, but readied-action attacks and attacks of opportunity are at least two cases that clearly do work. They take place during the movement, so they definitely work. Readied actions basically take place whenever the person who readied the action wants it to, so you can definitely ready an action for “as he moves past me” rather than “right before he starts to move” if you like, and clearly the Rogue would like to.
As you note, this is a really difficult maneuver to use effectively. Worse, as the Rogue levels, there’s very little he can do to improve it; stuff like Two-Weapon Fighting et al., iteratives from extra BAB, and the like, aren’t going to work with it. So as he levels up, instead of getting to improve this tactic with his feats and other choices, all he can hope for is extra Sneak Attack dice – which aren’t going to keep up on their own.
Note, though: “he moves and remain at 5ft of the enemy in the grease area, and ready a 5ft step + attack with the same trigger,” doesn’t quite work: he could only ready that action if he had not moved already in the round. If he was already in position and did not need to move into it, then it would work.
I’d strongly consider reverting to the 3.5 rule
While grease was and still is one of the best possible standard actions you can take, this particular facet of the spell was a good thing, in my opinion. It encourages teamwork and is an excellent example of a Wizard helping his teammates shine, rather than stealing all the spotlight himself. If I was to nerf it, rather than removing this aspect, I’d most likely tone down the spell’s double-jeopardy nature, or its effectiveness even when the enemy saves and makes his check.
This particular rule is thus more of a nerf to Rogues (who, after all, could have easily gotten a wand of grease since as a 1st-level spell it’s fairly cheap, and they have UMD in-class) than it is to Wizards (who still have plenty of options). Rogues don’t need a nerf. In general, Pathfinder makes it decidedly more difficult for Rogues to get multiple Sneak Attacks per turn, and I don’t think that improves the game at all. It was, in fact, already too hard for them to do this in 3.5, in my opinion. So I’d strongly consider reverting to the 3.5 rule.
Best Answer
Hiding behind a wall
If you have partial cover, you may use Stealth. If you have total cover (wall is taller than you, or floor-to-ceiling, or whatever), you don’t even need Stealth. So you may hide behind a wall.
Readying an attack
You may then ready an attack for when he enters a square next to you, since an Attack Action may be done as a Standard and you are allowed to ready those. Your DM may require that you specify which square; the rules leave it up to the DM how specific you have to be. In any event, if this readied action is triggered, however specific your DM requires it to be, you then attack the target.
Sneak Attack?
The most recent errata gives you Total Concealment until after you make an attack. So what does that give you? Well, it means he doesn’t know what square you’re in and takes a 50% miss chance even if he guesses the right square. Does that let you Sneak Attack?
No. It does not. Sneaking does not actually let you Sneak Attack.
Commentary on this errata seems to indicate that the point of the errata was to allow rogues to Sneak Attack while, ya know, sneaking, but that doesn’t actually seem borne out by the rules.
So the rules don’t actually give you a Sneak Attack, even though you are considered “hidden” for that first attack (the one you readied). If your DM is sane, he’ll allow sneaking to trigger Sneak Attacks, because it’s ridiculous that the rules don’t allow it. Paizo’s lead dev has even stated (if you go digging through the forums) that it’s supposed to work; why he doesn’t just fix the rules is anyone’s guess, but there it is. Ultimately, this is something you’ll have to ask your DM about.
Considering that it doesn’t work, quite flawed, but even if we assume it’s allowed to work, it’s still pretty poor damage most of the time. Rogues tend to have very little combat presence at mid-to-high levels if they can’t get full attacks with Two-Weapon Fighting to multiply their Sneak Attack damage. At low levels, it could be a useful trick.
Of course, with the various ways that Pathfinder has shafted rogues’ ability to Sneak Attack multiple times in a round, it may be the best you can hope for. Unfortunately, it’s not very good.