Syntax Error - Possible Missing Grammar Entry?
the-wondersmith opened this issue · 10 comments
First, thank you for publishing the project. I haven't quite got it working for what I need just yet, but even so it's already saved me a headache and a half.
I'm getting a syntax error during conversion of this line: CALCULATE MAX(LEN(ALLTRIM(memofile))) TO ln
Looking at a couple of the closed issues, I'm assuming this is due to either not having an entry for CALCULATE in the grammar, (if I'm reading this correctly, it looks to be commented out) or not having an entry for the added TO clause.
I looked at adding it myself, but after a cursory look over the project I'm fairly sure that meddling with any of the source would be well beyond my pay grade. That said, I'm a Python programmer by trade so if you let me know the rough basics of adding the requisite information I'll happily make the updates and submit a PR when I have everything working.
The project is definitely incomplete so missing grammar can be a common issue. If you would like to try adding it yourself, it's not too hard. For calculate you could mostly copy whats there for SUM and COUNT.
You would need to create a token for the calculate keyword(the commented ones are place holders from a list of keywords I had but I hadn't used it yet). Then you would add an entry somewhere under the cmd label (preferably near SUM and COUNT).
After you have the grammar changed, you have to generate new VisualFoxpro9Parser.py and VisualFoxpro9Visitor.py files using Antlr4. The makefile does that if you have make otherwise the command is something like java -jar antlr-4.8-complete.jar -visitor -no-listener -Dlanguage=Python3 VisualFoxpro9.g4
The final step is to add a visitCalculate function in vfp2py_convert.py that generates the converted code or just leave it empty with a pass and it will leave the original code as comment for later fixing.
@mwisslead Thank you for the amazingly fast response! That seems straightforward enough. I'll give it a shot and submit a PR as soon as I've got something working.
@mwisslead Well, getting CALCULATE to work went exactly as you described, easy-peasy. I am now, however, getting another syntax error when it tries to parse this:
SELECT PADR(LEFT(memofile, AT(".", memofile) - 1), ln) FROM listallt WHERE ".sct"$memofile ORDER BY 1 INTO CURSOR ysct
Any idea which part(s) of that line it's complaining about? Is there an easier way to tell?
I think the grammar would need updating to handle random ordering of the clauses. If you changed it to SELECT PADR(LEFT(memofile, AT(".", memofile) - 1), ln) FROM listallt WHERE ".sct"$memofile INTO CURSOR ysct ORDER BY 1 it would parse but be incorrect. It looks like it thinks the cursor is ysctorderby1. The current grammar expects order by to be an identifier but could be updated to be an expression.
@mwisslead I'm assuming that those changes need to be made on the Antlr end of things i.e. directly in VisualFoxpro9.g4 ? If so, I suspect that my next step will be consulting the Antlr documentation.
Are my suspicions accurate?
Yes. That line would just need changed to | SELECT (tablename=specialExpr | (DISTINCT? (specialArgs | '*') ((FROM fromExpr=specialExpr)|(WHERE whereExpr=expr)|(INTO (TABLE | CURSOR) intoExpr=specialExpr)|(ORDER BY orderbyid=expr))*)) #select I think.
Edited to put the change in
@mwisslead I'm still plodding my way through the project vfp2py is helping me with and I've run into a fun new (read: unexpected) exception:
Exception: Syntax Error on line 364: IF .NOT. (RECCOUNT()=1 .AND. currentDbf.primarykey=currentPk)
Not sure why that's causing an error. Maybe the grammar entry for if statements doesn't handle negations the way I thought it did? Thoughts?
Nevermind that previous comment. The problem is I never added .NOT. as a token because I don't have any code with it.
Nevermind that previous comment. The problem is I never added .NOT. as a token because I don't have any code with it.
Ah. Makes sense. Not 100% sure how to add it myself. Would it be a pain in the rear or an imposition for you to do it?