Giter Site home page Giter Site logo

odatafilterparser's Introduction

简介

本项目演示了如何使用Antlr4解析OData filter表达式,并转为成SQL的子句.由于仅演示将OData filter字符串解析后转换为SQL的过程,所以输出值不完全符合SQL标准.可以在此基础上修改输出ef查询、SqlSugar的查询条件.

如何使用

前置条件

  • 安装Java 1.6或更高运行时
  • 安装antrl-complete-4.7.2.jar
  • antrl-complete-4.7.2.jar文件路径(含文件名)添加到CLASSPATH环境变量中
  • Java安装路径添加到JAVA_HOME环境变量中

验证环境

java org.antlr.v4.Tool

输出以下内容表示成功

ANTLR Parser Generator  Version 4.7.2
 -o ___              specify output directory where all output is generated
 -lib ___            specify location of grammars, tokens files
 -atn                generate rule augmented transition network diagrams
 ...

安装Visual Studio 插件

安装好插件以后编辑保存*.g4文件就能自动生成规则解析代码了.

如果说编译还是有问题,检查以下*.g4文件的属性,如下图所示.

还有可能是Parser.csproj文件中的配置路径不对,检查这两立项.

<PropertyGroup Condition="'$(JAVA_HOME)'==''">
  <JAVA_HOME>C:\Program Files\Java\jre1.8.0_231</JAVA_HOME>
</PropertyGroup>
<PropertyGroup Condition="'$(Antlr4ToolPath)'==''">
  <Antlr4ToolPath>C:\java\antlr-4.7.2-complete.jar</Antlr4ToolPath>
</PropertyGroup>

支持的表达式

当前示例支持解析的OData filter表达式有

  • EQ
  • NE
  • GT
  • GE
  • LT
  • LE
  • StartsWith
  • EndsWith
  • Contains
  • In
  • ()

使用示例可以见Test项目.

odatafilterparser's People

Watchers

James Cloos avatar fuyun avatar

Forkers

huazailmh

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.