Sort token types and keywords

This commit is contained in:
Simon Binder 2020-04-16 21:14:51 +02:00
parent 9a78604d98
commit c007e1f9ac
No known key found for this signature in database
GPG Key ID: 7891917E4147B8C0
3 changed files with 227 additions and 239 deletions

View File

@ -351,7 +351,7 @@ mixin ExpressionParser on ParserBase {
}
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');
} else {
_error('Could not parse this expression');

View File

@ -138,6 +138,7 @@ abstract class ParserBase {
Token _consume(TokenType type, String message) {
if (_check(type)) return _advance();
_error(message);
}

View File

@ -2,285 +2,272 @@ import 'package:source_span/source_span.dart';
import 'package:sqlparser/sqlparser.dart';
enum TokenType {
leftParen,
rightParen,
comma,
dot,
$case,
$default,
$do,
doublePipe,
star,
/// A `**` token. This is only scanned when scanning for moor tokens.
doubleStar,
slash,
percent,
plus,
minus,
shiftLeft,
shiftRight,
ampersand,
pipe,
less,
lessEqual,
more,
moreEqual,
equal,
doubleEqual,
exclamationEqual,
lessMore,
$is,
$else,
$false,
$for,
$if,
$in,
not,
nothing,
like,
glob,
match,
regexp,
escape,
$index,
$is,
$null,
$true,
$values,
$with,
abort,
action,
after,
all,
ampersand,
and,
or,
tilde,
as,
asc,
atSignVariable,
autoincrement,
before,
begin,
between,
exists,
by,
cascade,
check,
collate,
questionMarkVariable,
colon,
colonVariable,
atSignVariable,
dollarSignVariable,
stringLiteral,
numberLiteral,
$true,
$false,
$null,
isNull,
notNull,
currentTime,
currentDate,
currentTimestamp,
identifier,
select,
delete,
update,
insert,
into,
distinct,
all,
from,
as,
where,
natural,
left,
outer,
inner,
comma,
comment,
conflict,
constraint,
create,
cross,
join,
on,
using,
group,
order,
by,
asc,
current,
currentDate,
currentTime,
currentTimestamp,
delete,
desc,
having,
limit,
offset,
$case,
when,
then,
$else,
distinct,
dollarSignVariable,
dot,
doubleEqual,
doublePipe,
each,
end,
window,
eof,
equal,
escape,
except,
exclamationEqual,
exclude,
exists,
fail,
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,
partition,
range,
rows,
groups,
unbounded,
percent,
pipe,
plus,
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,
foreign,
key,
unique,
check,
$default,
$values,
conflict,
references,
cascade,
restrict,
no,
action,
questionMarkVariable,
range,
recursive,
before,
after,
instead,
of,
$for,
each,
begin,
references,
regexp,
replace,
restrict,
rightParen,
rollback,
row,
rowid,
rows,
select,
semicolon,
comment,
eof,
set,
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,
inlineDart,
import,
json,
/// A `**` token. This is only scanned when scanning for moor tokens.
doubleStar,
}
const Map<String, TokenType> keywords = {
'SELECT': TokenType.select,
'INSERT': TokenType.insert,
'INTO': TokenType.into,
'COLLATE': TokenType.collate,
'DISTINCT': TokenType.distinct,
'DO': TokenType.$do,
'UPDATE': TokenType.update,
'ABORT': TokenType.abort,
'ACTION': TokenType.action,
'AFTER': TokenType.after,
'ALL': TokenType.all,
'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,
'WHERE': TokenType.where,
'ORDER': TokenType.order,
'GROUP': TokenType.group,
'HAVING': TokenType.having,
'BY': TokenType.by,
'ASC': TokenType.asc,
'DESC': TokenType.desc,
'LIMIT': TokenType.limit,
'OFFSET': TokenType.offset,
'SET': TokenType.set,
'IS': TokenType.$is,
'IN': TokenType.$in,
'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,
'AUTOINCREMENT': TokenType.autoincrement,
'BEFORE': TokenType.before,
'BEGIN': TokenType.begin,
'BETWEEN': TokenType.between,
'BY': TokenType.by,
'CASCADE': TokenType.cascade,
'CASE': TokenType.$case,
'WHEN': TokenType.when,
'THEN': TokenType.then,
'CHECK': TokenType.check,
'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,
'END': TokenType.end,
'ABORT': TokenType.abort,
'ROLLBACK': TokenType.rollback,
'REPLACE': TokenType.replace,
'ESCAPE': TokenType.escape,
'EXCEPT': TokenType.except,
'EXCLUDE': TokenType.exclude,
'EXISTS': TokenType.exists,
'FAIL': TokenType.fail,
'IGNORE': TokenType.ignore,
'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,
'FALSE': TokenType.$false,
'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,
'PARTITION': TokenType.partition,
'PRECEDING': TokenType.preceding,
'PRIMARY': TokenType.primary,
'RANGE': TokenType.range,
'RECURSIVE': TokenType.recursive,
'ROWS': TokenType.rows,
'GROUPS': TokenType.groups,
'UNBOUNDED': TokenType.unbounded,
'PRECEDING': TokenType.preceding,
'FOLLOWING': TokenType.following,
'CURRENT': TokenType.current,
'REFERENCES': TokenType.references,
'REGEXP': TokenType.regexp,
'REPLACE': TokenType.replace,
'RESTRICT': TokenType.restrict,
'ROLLBACK': TokenType.rollback,
'ROW': TokenType.row,
'EXCLUDE': TokenType.exclude,
'OTHERS': TokenType.others,
'ROWID': TokenType.rowid,
'ROWS': TokenType.rows,
'SELECT': TokenType.select,
'SET': TokenType.set,
'TABLE': TokenType.table,
'THEN': TokenType.then,
'TIES': TokenType.ties,
'WINDOW': TokenType.window,
'VALUES': TokenType.$values,
'TRIGGER': TokenType.trigger,
'TRUE': TokenType.$true,
'UNBOUNDED': TokenType.unbounded,
'UNION': TokenType.union,
'INTERSECT': TokenType.intersect,
'EXCEPT': TokenType.except,
'BEFORE': TokenType.before,
'AFTER': TokenType.after,
'INSTEAD': TokenType.instead,
'OF': TokenType.of,
'FOR': TokenType.$for,
'EACH': TokenType.each,
'BEGIN': TokenType.begin,
'UNIQUE': TokenType.unique,
'UPDATE': TokenType.update,
'USING': TokenType.using,
'VALUES': TokenType.$values,
'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.
@ -290,9 +277,9 @@ final Map<TokenType, String> reverseKeywords = {
};
const Map<String, TokenType> moorKeywords = {
'MAPPED': TokenType.mapped,
'IMPORT': TokenType.import,
'JSON': TokenType.json,
'MAPPED': TokenType.mapped,
};
/// A set of [TokenType]s that can be parsed as an identifier.