mirror of https://github.com/AMT-Cheif/drift.git
Sort token types and keywords
This commit is contained in:
parent
9a78604d98
commit
c007e1f9ac
|
@ -351,7 +351,7 @@ mixin ExpressionParser on ParserBase {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_peek is KeywordToken) {
|
if (_peek is KeywordToken) {
|
||||||
_error('Could not parse this expressions. Note: This is a reserved '
|
_error('Could not parse this expression. Note: This is a reserved '
|
||||||
'keyword, you can escape it in double ticks');
|
'keyword, you can escape it in double ticks');
|
||||||
} else {
|
} else {
|
||||||
_error('Could not parse this expression');
|
_error('Could not parse this expression');
|
||||||
|
|
|
@ -138,6 +138,7 @@ abstract class ParserBase {
|
||||||
|
|
||||||
Token _consume(TokenType type, String message) {
|
Token _consume(TokenType type, String message) {
|
||||||
if (_check(type)) return _advance();
|
if (_check(type)) return _advance();
|
||||||
|
|
||||||
_error(message);
|
_error(message);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -2,285 +2,272 @@ import 'package:source_span/source_span.dart';
|
||||||
import 'package:sqlparser/sqlparser.dart';
|
import 'package:sqlparser/sqlparser.dart';
|
||||||
|
|
||||||
enum TokenType {
|
enum TokenType {
|
||||||
leftParen,
|
$case,
|
||||||
rightParen,
|
$default,
|
||||||
comma,
|
|
||||||
dot,
|
|
||||||
$do,
|
$do,
|
||||||
doublePipe,
|
$else,
|
||||||
star,
|
$false,
|
||||||
|
$for,
|
||||||
/// A `**` token. This is only scanned when scanning for moor tokens.
|
$if,
|
||||||
doubleStar,
|
|
||||||
slash,
|
|
||||||
percent,
|
|
||||||
plus,
|
|
||||||
minus,
|
|
||||||
shiftLeft,
|
|
||||||
shiftRight,
|
|
||||||
ampersand,
|
|
||||||
pipe,
|
|
||||||
less,
|
|
||||||
lessEqual,
|
|
||||||
more,
|
|
||||||
moreEqual,
|
|
||||||
equal,
|
|
||||||
doubleEqual,
|
|
||||||
exclamationEqual,
|
|
||||||
lessMore,
|
|
||||||
$is,
|
|
||||||
$in,
|
$in,
|
||||||
not,
|
$index,
|
||||||
nothing,
|
$is,
|
||||||
like,
|
$null,
|
||||||
glob,
|
$true,
|
||||||
match,
|
$values,
|
||||||
regexp,
|
$with,
|
||||||
escape,
|
abort,
|
||||||
|
action,
|
||||||
|
after,
|
||||||
|
all,
|
||||||
|
ampersand,
|
||||||
and,
|
and,
|
||||||
or,
|
as,
|
||||||
tilde,
|
asc,
|
||||||
|
atSignVariable,
|
||||||
|
autoincrement,
|
||||||
|
before,
|
||||||
|
begin,
|
||||||
between,
|
between,
|
||||||
exists,
|
by,
|
||||||
|
cascade,
|
||||||
|
check,
|
||||||
collate,
|
collate,
|
||||||
|
|
||||||
questionMarkVariable,
|
|
||||||
colon,
|
colon,
|
||||||
colonVariable,
|
colonVariable,
|
||||||
atSignVariable,
|
comma,
|
||||||
dollarSignVariable,
|
comment,
|
||||||
|
conflict,
|
||||||
stringLiteral,
|
constraint,
|
||||||
numberLiteral,
|
create,
|
||||||
$true,
|
|
||||||
$false,
|
|
||||||
$null,
|
|
||||||
isNull,
|
|
||||||
notNull,
|
|
||||||
currentTime,
|
|
||||||
currentDate,
|
|
||||||
currentTimestamp,
|
|
||||||
identifier,
|
|
||||||
|
|
||||||
select,
|
|
||||||
delete,
|
|
||||||
update,
|
|
||||||
insert,
|
|
||||||
into,
|
|
||||||
distinct,
|
|
||||||
all,
|
|
||||||
from,
|
|
||||||
as,
|
|
||||||
where,
|
|
||||||
|
|
||||||
natural,
|
|
||||||
left,
|
|
||||||
outer,
|
|
||||||
inner,
|
|
||||||
cross,
|
cross,
|
||||||
join,
|
current,
|
||||||
on,
|
currentDate,
|
||||||
using,
|
currentTime,
|
||||||
|
currentTimestamp,
|
||||||
group,
|
delete,
|
||||||
order,
|
|
||||||
by,
|
|
||||||
asc,
|
|
||||||
desc,
|
desc,
|
||||||
having,
|
distinct,
|
||||||
|
dollarSignVariable,
|
||||||
limit,
|
dot,
|
||||||
offset,
|
doubleEqual,
|
||||||
|
doublePipe,
|
||||||
$case,
|
each,
|
||||||
when,
|
|
||||||
then,
|
|
||||||
$else,
|
|
||||||
end,
|
end,
|
||||||
|
eof,
|
||||||
window,
|
equal,
|
||||||
|
escape,
|
||||||
|
except,
|
||||||
|
exclamationEqual,
|
||||||
|
exclude,
|
||||||
|
exists,
|
||||||
|
fail,
|
||||||
filter,
|
filter,
|
||||||
|
following,
|
||||||
|
foreign,
|
||||||
|
from,
|
||||||
|
glob,
|
||||||
|
group,
|
||||||
|
groups,
|
||||||
|
having,
|
||||||
|
identifier,
|
||||||
|
ignore,
|
||||||
|
inner,
|
||||||
|
insert,
|
||||||
|
instead,
|
||||||
|
intersect,
|
||||||
|
into,
|
||||||
|
isNull,
|
||||||
|
join,
|
||||||
|
key,
|
||||||
|
left,
|
||||||
|
leftParen,
|
||||||
|
less,
|
||||||
|
lessEqual,
|
||||||
|
lessMore,
|
||||||
|
like,
|
||||||
|
limit,
|
||||||
|
match,
|
||||||
|
minus,
|
||||||
|
more,
|
||||||
|
moreEqual,
|
||||||
|
natural,
|
||||||
|
no,
|
||||||
|
not,
|
||||||
|
notNull,
|
||||||
|
nothing,
|
||||||
|
numberLiteral,
|
||||||
|
of,
|
||||||
|
offset,
|
||||||
|
on,
|
||||||
|
or,
|
||||||
|
order,
|
||||||
|
others,
|
||||||
|
outer,
|
||||||
over,
|
over,
|
||||||
partition,
|
partition,
|
||||||
range,
|
percent,
|
||||||
rows,
|
pipe,
|
||||||
groups,
|
plus,
|
||||||
unbounded,
|
|
||||||
preceding,
|
preceding,
|
||||||
following,
|
|
||||||
current,
|
|
||||||
row,
|
|
||||||
exclude,
|
|
||||||
others,
|
|
||||||
ties,
|
|
||||||
|
|
||||||
rollback,
|
|
||||||
abort,
|
|
||||||
replace,
|
|
||||||
fail,
|
|
||||||
ignore,
|
|
||||||
set,
|
|
||||||
|
|
||||||
union,
|
|
||||||
intersect,
|
|
||||||
except,
|
|
||||||
|
|
||||||
create,
|
|
||||||
virtual,
|
|
||||||
table,
|
|
||||||
trigger,
|
|
||||||
$index,
|
|
||||||
$if,
|
|
||||||
$with,
|
|
||||||
without,
|
|
||||||
rowid,
|
|
||||||
constraint,
|
|
||||||
autoincrement,
|
|
||||||
primary,
|
primary,
|
||||||
foreign,
|
questionMarkVariable,
|
||||||
key,
|
range,
|
||||||
unique,
|
|
||||||
check,
|
|
||||||
$default,
|
|
||||||
$values,
|
|
||||||
conflict,
|
|
||||||
references,
|
|
||||||
cascade,
|
|
||||||
restrict,
|
|
||||||
no,
|
|
||||||
action,
|
|
||||||
recursive,
|
recursive,
|
||||||
|
references,
|
||||||
before,
|
regexp,
|
||||||
after,
|
replace,
|
||||||
instead,
|
restrict,
|
||||||
of,
|
rightParen,
|
||||||
$for,
|
rollback,
|
||||||
each,
|
row,
|
||||||
begin,
|
rowid,
|
||||||
|
rows,
|
||||||
|
select,
|
||||||
semicolon,
|
semicolon,
|
||||||
comment,
|
set,
|
||||||
eof,
|
shiftLeft,
|
||||||
|
shiftRight,
|
||||||
|
slash,
|
||||||
|
star,
|
||||||
|
stringLiteral,
|
||||||
|
table,
|
||||||
|
then,
|
||||||
|
ties,
|
||||||
|
tilde,
|
||||||
|
trigger,
|
||||||
|
unbounded,
|
||||||
|
union,
|
||||||
|
unique,
|
||||||
|
update,
|
||||||
|
using,
|
||||||
|
virtual,
|
||||||
|
when,
|
||||||
|
where,
|
||||||
|
window,
|
||||||
|
without,
|
||||||
|
|
||||||
/// Moor specific token, used to declare a type converters
|
/// Moor specific token, used to declare type converter
|
||||||
mapped,
|
mapped,
|
||||||
inlineDart,
|
inlineDart,
|
||||||
import,
|
import,
|
||||||
json,
|
json,
|
||||||
|
|
||||||
|
/// A `**` token. This is only scanned when scanning for moor tokens.
|
||||||
|
doubleStar,
|
||||||
}
|
}
|
||||||
|
|
||||||
const Map<String, TokenType> keywords = {
|
const Map<String, TokenType> keywords = {
|
||||||
'SELECT': TokenType.select,
|
'ABORT': TokenType.abort,
|
||||||
'INSERT': TokenType.insert,
|
'ACTION': TokenType.action,
|
||||||
'INTO': TokenType.into,
|
'AFTER': TokenType.after,
|
||||||
'COLLATE': TokenType.collate,
|
|
||||||
'DISTINCT': TokenType.distinct,
|
|
||||||
'DO': TokenType.$do,
|
|
||||||
'UPDATE': TokenType.update,
|
|
||||||
'ALL': TokenType.all,
|
'ALL': TokenType.all,
|
||||||
'AND': TokenType.and,
|
'AND': TokenType.and,
|
||||||
'OR': TokenType.or,
|
|
||||||
'EXISTS': TokenType.exists,
|
|
||||||
'BETWEEN': TokenType.between,
|
|
||||||
'DELETE': TokenType.delete,
|
|
||||||
'FROM': TokenType.from,
|
|
||||||
'NATURAL': TokenType.natural,
|
|
||||||
'LEFT': TokenType.left,
|
|
||||||
'OUTER': TokenType.outer,
|
|
||||||
'INNER': TokenType.inner,
|
|
||||||
'CROSS': TokenType.cross,
|
|
||||||
'JOIN': TokenType.join,
|
|
||||||
'ON': TokenType.on,
|
|
||||||
'USING': TokenType.using,
|
|
||||||
'AS': TokenType.as,
|
'AS': TokenType.as,
|
||||||
'WHERE': TokenType.where,
|
|
||||||
'ORDER': TokenType.order,
|
|
||||||
'GROUP': TokenType.group,
|
|
||||||
'HAVING': TokenType.having,
|
|
||||||
'BY': TokenType.by,
|
|
||||||
'ASC': TokenType.asc,
|
'ASC': TokenType.asc,
|
||||||
'DESC': TokenType.desc,
|
'AUTOINCREMENT': TokenType.autoincrement,
|
||||||
'LIMIT': TokenType.limit,
|
'BEFORE': TokenType.before,
|
||||||
'OFFSET': TokenType.offset,
|
'BEGIN': TokenType.begin,
|
||||||
'SET': TokenType.set,
|
'BETWEEN': TokenType.between,
|
||||||
'IS': TokenType.$is,
|
'BY': TokenType.by,
|
||||||
'IN': TokenType.$in,
|
'CASCADE': TokenType.cascade,
|
||||||
'LIKE': TokenType.like,
|
|
||||||
'GLOB': TokenType.glob,
|
|
||||||
'MATCH': TokenType.match,
|
|
||||||
'REGEXP': TokenType.regexp,
|
|
||||||
'ESCAPE': TokenType.escape,
|
|
||||||
'NOT': TokenType.not,
|
|
||||||
'NOTHING': TokenType.nothing,
|
|
||||||
'TRUE': TokenType.$true,
|
|
||||||
'FALSE': TokenType.$false,
|
|
||||||
'NULL': TokenType.$null,
|
|
||||||
'ISNULL': TokenType.isNull,
|
|
||||||
'NOTNULL': TokenType.notNull,
|
|
||||||
'CURRENT_TIME': TokenType.currentTime,
|
|
||||||
'CURRENT_DATE': TokenType.currentDate,
|
|
||||||
'CURRENT_TIMESTAMP': TokenType.currentTimestamp,
|
|
||||||
'CASE': TokenType.$case,
|
'CASE': TokenType.$case,
|
||||||
'WHEN': TokenType.when,
|
'CHECK': TokenType.check,
|
||||||
'THEN': TokenType.then,
|
'COLLATE': TokenType.collate,
|
||||||
|
'CONFLICT': TokenType.conflict,
|
||||||
|
'CONSTRAINT': TokenType.constraint,
|
||||||
|
'CREATE': TokenType.create,
|
||||||
|
'CROSS': TokenType.cross,
|
||||||
|
'CURRENT': TokenType.current,
|
||||||
|
'CURRENT_DATE': TokenType.currentDate,
|
||||||
|
'CURRENT_TIME': TokenType.currentTime,
|
||||||
|
'CURRENT_TIMESTAMP': TokenType.currentTimestamp,
|
||||||
|
'DEFAULT': TokenType.$default,
|
||||||
|
'DELETE': TokenType.delete,
|
||||||
|
'DESC': TokenType.desc,
|
||||||
|
'DISTINCT': TokenType.distinct,
|
||||||
|
'DO': TokenType.$do,
|
||||||
|
'EACH': TokenType.each,
|
||||||
'ELSE': TokenType.$else,
|
'ELSE': TokenType.$else,
|
||||||
'END': TokenType.end,
|
'END': TokenType.end,
|
||||||
'ABORT': TokenType.abort,
|
'ESCAPE': TokenType.escape,
|
||||||
'ROLLBACK': TokenType.rollback,
|
'EXCEPT': TokenType.except,
|
||||||
'REPLACE': TokenType.replace,
|
'EXCLUDE': TokenType.exclude,
|
||||||
|
'EXISTS': TokenType.exists,
|
||||||
'FAIL': TokenType.fail,
|
'FAIL': TokenType.fail,
|
||||||
'IGNORE': TokenType.ignore,
|
'FALSE': TokenType.$false,
|
||||||
'CREATE': TokenType.create,
|
|
||||||
'TABLE': TokenType.table,
|
|
||||||
'TRIGGER': TokenType.trigger,
|
|
||||||
'INDEX': TokenType.$index,
|
|
||||||
'IF': TokenType.$if,
|
|
||||||
'WITH': TokenType.$with,
|
|
||||||
'WITHOUT': TokenType.without,
|
|
||||||
'ROWID': TokenType.rowid,
|
|
||||||
'CONSTRAINT': TokenType.constraint,
|
|
||||||
'AUTOINCREMENT': TokenType.autoincrement,
|
|
||||||
'PRIMARY': TokenType.primary,
|
|
||||||
'FOREIGN': TokenType.foreign,
|
|
||||||
'KEY': TokenType.key,
|
|
||||||
'UNIQUE': TokenType.unique,
|
|
||||||
'CHECK': TokenType.check,
|
|
||||||
'DEFAULT': TokenType.$default,
|
|
||||||
'CONFLICT': TokenType.conflict,
|
|
||||||
'REFERENCES': TokenType.references,
|
|
||||||
'CASCADE': TokenType.cascade,
|
|
||||||
'RESTRICT': TokenType.restrict,
|
|
||||||
'NO': TokenType.no,
|
|
||||||
'ACTION': TokenType.action,
|
|
||||||
'FILTER': TokenType.filter,
|
'FILTER': TokenType.filter,
|
||||||
|
'FOLLOWING': TokenType.following,
|
||||||
|
'FOR': TokenType.$for,
|
||||||
|
'FOREIGN': TokenType.foreign,
|
||||||
|
'FROM': TokenType.from,
|
||||||
|
'GLOB': TokenType.glob,
|
||||||
|
'GROUP': TokenType.group,
|
||||||
|
'GROUPS': TokenType.groups,
|
||||||
|
'HAVING': TokenType.having,
|
||||||
|
'IF': TokenType.$if,
|
||||||
|
'IGNORE': TokenType.ignore,
|
||||||
|
'IN': TokenType.$in,
|
||||||
|
'INDEX': TokenType.$index,
|
||||||
|
'INNER': TokenType.inner,
|
||||||
|
'INSERT': TokenType.insert,
|
||||||
|
'INSTEAD': TokenType.instead,
|
||||||
|
'INTERSECT': TokenType.intersect,
|
||||||
|
'INTO': TokenType.into,
|
||||||
|
'IS': TokenType.$is,
|
||||||
|
'ISNULL': TokenType.isNull,
|
||||||
|
'JOIN': TokenType.join,
|
||||||
|
'KEY': TokenType.key,
|
||||||
|
'LEFT': TokenType.left,
|
||||||
|
'LIKE': TokenType.like,
|
||||||
|
'LIMIT': TokenType.limit,
|
||||||
|
'MATCH': TokenType.match,
|
||||||
|
'NATURAL': TokenType.natural,
|
||||||
|
'NO': TokenType.no,
|
||||||
|
'NOT': TokenType.not,
|
||||||
|
'NOTHING': TokenType.nothing,
|
||||||
|
'NOTNULL': TokenType.notNull,
|
||||||
|
'NULL': TokenType.$null,
|
||||||
|
'OF': TokenType.of,
|
||||||
|
'OFFSET': TokenType.offset,
|
||||||
|
'ON': TokenType.on,
|
||||||
|
'OR': TokenType.or,
|
||||||
|
'ORDER': TokenType.order,
|
||||||
|
'OTHERS': TokenType.others,
|
||||||
|
'OUTER': TokenType.outer,
|
||||||
'OVER': TokenType.over,
|
'OVER': TokenType.over,
|
||||||
'PARTITION': TokenType.partition,
|
'PARTITION': TokenType.partition,
|
||||||
|
'PRECEDING': TokenType.preceding,
|
||||||
|
'PRIMARY': TokenType.primary,
|
||||||
'RANGE': TokenType.range,
|
'RANGE': TokenType.range,
|
||||||
'RECURSIVE': TokenType.recursive,
|
'RECURSIVE': TokenType.recursive,
|
||||||
'ROWS': TokenType.rows,
|
'REFERENCES': TokenType.references,
|
||||||
'GROUPS': TokenType.groups,
|
'REGEXP': TokenType.regexp,
|
||||||
'UNBOUNDED': TokenType.unbounded,
|
'REPLACE': TokenType.replace,
|
||||||
'PRECEDING': TokenType.preceding,
|
'RESTRICT': TokenType.restrict,
|
||||||
'FOLLOWING': TokenType.following,
|
'ROLLBACK': TokenType.rollback,
|
||||||
'CURRENT': TokenType.current,
|
|
||||||
'ROW': TokenType.row,
|
'ROW': TokenType.row,
|
||||||
'EXCLUDE': TokenType.exclude,
|
'ROWID': TokenType.rowid,
|
||||||
'OTHERS': TokenType.others,
|
'ROWS': TokenType.rows,
|
||||||
|
'SELECT': TokenType.select,
|
||||||
|
'SET': TokenType.set,
|
||||||
|
'TABLE': TokenType.table,
|
||||||
|
'THEN': TokenType.then,
|
||||||
'TIES': TokenType.ties,
|
'TIES': TokenType.ties,
|
||||||
'WINDOW': TokenType.window,
|
'TRIGGER': TokenType.trigger,
|
||||||
'VALUES': TokenType.$values,
|
'TRUE': TokenType.$true,
|
||||||
|
'UNBOUNDED': TokenType.unbounded,
|
||||||
'UNION': TokenType.union,
|
'UNION': TokenType.union,
|
||||||
'INTERSECT': TokenType.intersect,
|
'UNIQUE': TokenType.unique,
|
||||||
'EXCEPT': TokenType.except,
|
'UPDATE': TokenType.update,
|
||||||
'BEFORE': TokenType.before,
|
'USING': TokenType.using,
|
||||||
'AFTER': TokenType.after,
|
'VALUES': TokenType.$values,
|
||||||
'INSTEAD': TokenType.instead,
|
|
||||||
'OF': TokenType.of,
|
|
||||||
'FOR': TokenType.$for,
|
|
||||||
'EACH': TokenType.each,
|
|
||||||
'BEGIN': TokenType.begin,
|
|
||||||
'VIRTUAL': TokenType.virtual,
|
'VIRTUAL': TokenType.virtual,
|
||||||
|
'WHEN': TokenType.when,
|
||||||
|
'WHERE': TokenType.where,
|
||||||
|
'WINDOW': TokenType.window,
|
||||||
|
'WITH': TokenType.$with,
|
||||||
|
'WITHOUT': TokenType.without,
|
||||||
};
|
};
|
||||||
|
|
||||||
/// Maps [TokenType]s which are keywords to their lexeme.
|
/// Maps [TokenType]s which are keywords to their lexeme.
|
||||||
|
@ -290,9 +277,9 @@ final Map<TokenType, String> reverseKeywords = {
|
||||||
};
|
};
|
||||||
|
|
||||||
const Map<String, TokenType> moorKeywords = {
|
const Map<String, TokenType> moorKeywords = {
|
||||||
'MAPPED': TokenType.mapped,
|
|
||||||
'IMPORT': TokenType.import,
|
'IMPORT': TokenType.import,
|
||||||
'JSON': TokenType.json,
|
'JSON': TokenType.json,
|
||||||
|
'MAPPED': TokenType.mapped,
|
||||||
};
|
};
|
||||||
|
|
||||||
/// A set of [TokenType]s that can be parsed as an identifier.
|
/// A set of [TokenType]s that can be parsed as an identifier.
|
||||||
|
|
Loading…
Reference in New Issue