Categorygithub.com/pingcap/parser
modulepackage
5.2.0-alpha+incompatible
Repository: https://github.com/pingcap/parser.git
Documentation: pkg.go.dev

# README

Parser - A MySQL Compatible SQL Parser

Go Report Card CircleCI Status GoDoc codecov

The goal of this project is to build a Golang parser that is fully compatible with MySQL syntax, easy to extend, and high performance. Currently, features supported by parser are as follows:

  • Highly compatible with MySQL: it supports almost all features of MySQL. For the complete details, see parser.y and hintparser.y.
  • Extensible: adding a new syntax requires only a few lines of Yacc and Golang code changes. As an example, see PR-680.
  • Good performance: the parser is generated by goyacc in a bottom-up approach. It is efficient to build an AST tree with a state machine.

How to use it

Please read the quickstart.

Future

  • Support more MySQL syntax
  • Optimize the code structure, make it easier to extend
  • Improve performance and benchmark
  • Improve the quality of code and comments

Getting Help

If you have any questions, feel free to discuss in sig-ddl. Here are the steps to join:

  1. Join TiDB Slack community, and then
  2. Join sig-ddl Slack channel.

If you want to join as a special interest group member, see DDL Special Interest Group.

Users

These projects use this parser. Please feel free to extend this list if you found you are one of the users but not listed here:

Contributing

Contributions are welcomed and greatly appreciated. See Contribution Guide for details on submitting patches and the contribution workflow.

Here is how to update parser for TiDB.

Acknowledgments

Thanks cznic for providing some great open-source tools.

License

Parser is under the Apache 2.0 license. See the LICENSE file for details.

More resources

# Packages

Package ast is the abstract syntax tree parsed from a SQL statement by parser.
Goyacc is a version of yacc generating Go parsers.

# Functions

DigestHash generates the digest of statements.
DigestNormalized generates the digest of a normalized sql.
New returns a Parser object with default SQL mode.
NewDigest returns a new digest.
NewScanner returns a new scanner object.
Normalize generates the normalized statements.
NormalizeDigest combines Normalize and DigestNormalized into one method.
ParseErrorWith returns "You have a syntax error near..." error message compatible with mysql.
ParseHint parses an optimizer hint (the interior of `/*+ ..
TrimComment trim comment for special comment code of MySQL.

# Variables

ErrInvalidYearColumnLength returns for illegal column length for year type.
ErrParse returns for sql parse error.
ErrSyntax returns for sql syntax error.
ErrTooBigDisplayWidth returns for data display width exceed limit .
ErrTooBigPrecision returns for data precision exceed limit.
ErrUnknownAlterAlgorithm returns for no alter algorithm found error.
ErrUnknownAlterLock returns for no alter lock type found error.
ErrUnknownCharacterSet returns for no character set found error.
ErrWarnDeprecatedIntegerDisplayWidth share the same code 1681, and it will be returned when length is specified in integer.
ErrWarnDeprecatedSyntaxNoReplacement return when the syntax was deprecated and there is no replacement.
ErrWrongArguments returns for illegal argument.
ErrWrongFieldTerminators returns for illegal field terminators.
ErrWrongUsage returns for incorrect usages.
ErrWrongValue returns for wrong value.
SpecFieldPattern special result field pattern.
SpecialCommentsController controls whether special comments like `/*T![xxx] yyy */` can be parsed as `yyy`.

# Structs

Parser represents a parser instance.
Pos represents the position of a token.
Scanner implements the yyLexer interface.