I've been learning F# for some time, and I wanted to try creating a small SQL parser. I have found a tutorial that explains how to do this through FsLex and FsYacc, however, the site does not give any download links. Under Visual Studio, via nuget, I come across this, which I then download. It seems very similar to the explanations provided by the site, so I don't think it's related to the problem.
I'm not far from it yet, here are my two little files :
Sql.fs:
module Sql
type value =
| Int of int
| Float of float
| String of string
type dir = Asc | Desc
type op = Eq | Gt | Ge | Lt | Le
type order = string * dir
type where =
| Cond of (value * op * value)
| And of where * where
| Or of where * where
type joinType = Inner | Left | Right
type join = string * joinType * where option
type sqlStatement =
{
Table : string;
Columns : string list;
Joins : join list;
Where : where option;
OrderBy : order list
}
SqlParser.fsp:
module SqlParser
%{
open Sql
%}
%token <string> ID
%token <int> INT
%token <float> FLOAT
%token AND OR
%token COMMA
%token EQ LT LE GT GE
%token JOIN INNER LEFT RIGHT ON
%token SELECT FROM WHERE ORDER BY
%token ASC DESC
%token EOF
// start
%start start
%type <string> start
%%
start:
| { "Nothing to see here" }
%%
Here is the list of files / references of my project :
References:
- FSharp.Core
- FsLexYacc.Runtime
- mscorlib
- System
- System.Core
- System.Numerics
- System.ValueTuple
AssemblyInfo.fs
Sql.fs
SqlParser.fsp
App.config
packages.config
And here is the prebuild command, which is supposed to interact with the "SqlParser.fsp" file:
fsyacc "$(ProjectDir)SqlParser.fsp"
When I compile, with this command, Visual Studio tells me "Generation failure", yet there are no errors, the list of these is empty. When I remove this command, the project compiles "normally", indeed the file "SqlParser.fsp" should have generated other files (hence the prebuild command).
- Did I miss anything?
- Is the FsLexYacc library obsolete?
- Isn't the tutorial correct?
- ...
Thank you in advance.