use criterion::{black_box, criterion_group, criterion_main, Criterion}; use sana_core::{Rule, RuleSet, regex::Regex}; use std::convert::TryFrom; pub fn sql_dfa(c: &mut Criterion) { let rules: Vec<_> = keywords().iter() .map(|(regex, act)| { let hir = regex_syntax::Parser::new() .parse(regex).unwrap(); let regex = Regex::try_from(hir).unwrap(); Rule { regex, priority: 0, action: *act } }) .collect(); let ruleset = RuleSet { rules }; c.bench_function( "SQL DFA construction", |b| b.iter(|| black_box(&ruleset).construct_dfa().unwrap()) ); } criterion_group!(benches, sql_dfa); criterion_main!(benches); pub fn keywords() -> &'static [(&'static str, &'static str)] { &[ ( r"(?i)abort", "KwAbort" ), ( r"(?i)absolute", "KwAbsolute" ), ( r"(?i)access", "KwAccess" ), ( r"(?i)action", "KwAction" ), ( r"(?i)add", "KwAdd" ), ( r"(?i)admin", "KwAdmin" ), ( r"(?i)after", "KwAfter" ), ( r"(?i)aggregate", "KwAggregate" ), ( r"(?i)all", "KwAll" ), ( r"(?i)also", "KwAlso" ), ( r"(?i)alter", "KwAlter" ), ( r"(?i)always", "KwAlways" ), ( r"(?i)analyse", "KwAnalyse" ), ( r"(?i)analyze", "KwAnalyze" ), ( r"(?i)and", "KwAnd" ), ( r"(?i)any", "KwAny" ), ( r"(?i)array", "KwArray" ), ( r"(?i)as", "KwAs" ), ( r"(?i)asc", "KwAsc" ), ( r"(?i)assertion", "KwAssertion" ), ( r"(?i)assignment", "KwAssignment" ), ( r"(?i)asymmetric", "KwAsymmetric" ), ( r"(?i)at", "KwAt" ), ( r"(?i)attach", "KwAttach" ), ( r"(?i)attribute", "KwAttribute" ), ( r"(?i)authorization", "KwAuthorization" ), ( r"(?i)backward", "KwBackward" ), ( r"(?i)before", "KwBefore" ), ( r"(?i)begin", "KwBegin" ), ( r"(?i)between", "KwBetween" ), ( r"(?i)bigint", "KwBigint" ), ( r"(?i)binary", "KwBinary" ), ( r"(?i)bit", "KwBit" ), ( r"(?i)boolean", "KwBoolean" ), ( r"(?i)both", "KwBoth" ), ( r"(?i)by", "KwBy" ), ( r"(?i)cache", "KwCache" ), ( r"(?i)call", "KwCall" ), ( r"(?i)called", "KwCalled" ), ( r"(?i)cascade", "KwCascade" ), ( r"(?i)cascaded", "KwCascaded" ), ( r"(?i)case", "KwCase" ), ( r"(?i)cast", "KwCast" ), ( r"(?i)catalog", "KwCatalog" ), ( r"(?i)chain", "KwChain" ), ( r"(?i)char", "KwChar" ), ( r"(?i)character", "KwCharacter" ), ( r"(?i)characteristics", "KwCharacteristics" ), ( r"(?i)check", "KwCheck" ), ( r"(?i)checkpoint", "KwCheckpoint" ), ( r"(?i)class", "KwClass" ), ( r"(?i)close", "KwClose" ), ( r"(?i)cluster", "KwCluster" ), ( r"(?i)coalesce", "KwCoalesce" ), ( r"(?i)collate", "KwCollate" ), ( r"(?i)collation", "KwCollation" ), ( r"(?i)column", "KwColumn" ), ( r"(?i)columns", "KwColumns" ), ( r"(?i)comment", "KwComment" ), ( r"(?i)comments", "KwComments" ), ( r"(?i)commit", "KwCommit" ), ( r"(?i)committed", "KwCommitted" ), ( r"(?i)concurrently", "KwConcurrently" ), ( r"(?i)configuration", "KwConfiguration" ), ( r"(?i)conflict", "KwConflict" ), ( r"(?i)connection", "KwConnection" ), ( r"(?i)constraint", "KwConstraint" ), ( r"(?i)constraints", "KwConstraints" ), ( r"(?i)content", "KwContent" ), ( r"(?i)continue", "KwContinue" ), ( r"(?i)conversion", "KwConversion" ), ( r"(?i)copy", "KwCopy" ), ( r"(?i)cost", "KwCost" ), ( r"(?i)create", "KwCreate" ), ( r"(?i)cross", "KwCross" ), ( r"(?i)csv", "KwCsv" ), ( r"(?i)cube", "KwCube" ), ( r"(?i)current", "KwCurrent" ), ( r"(?i)current_catalog", "KwCurrentCatalog" ), ( r"(?i)current_date", "KwCurrentDate" ), ( r"(?i)current_role", "KwCurrentRole" ), ( r"(?i)current_schema", "KwCurrentSchema" ), ( r"(?i)current_time", "KwCurrentTime" ), ( r"(?i)current_timestamp", "KwCurrentTimestamp" ), ( r"(?i)current_user", "KwCurrentUser" ), ( r"(?i)cursor", "KwCursor" ), ( r"(?i)cycle", "KwCycle" ), ( r"(?i)data", "KwData" ), ( r"(?i)database", "KwDatabase" ), ( r"(?i)day", "KwDay" ), ( r"(?i)deallocate", "KwDeallocate" ), ( r"(?i)dec", "KwDec" ), ( r"(?i)decimal", "KwDecimal" ), ( r"(?i)declare", "KwDeclare" ), ( r"(?i)default", "KwDefault" ), ( r"(?i)defaults", "KwDefaults" ), ( r"(?i)deferrable", "KwDeferrable" ), ( r"(?i)deferred", "KwDeferred" ), ( r"(?i)definer", "KwDefiner" ), ( r"(?i)delete", "KwDelete" ), ( r"(?i)delimiter", "KwDelimiter" ), ( r"(?i)delimiters", "KwDelimiters" ), ( r"(?i)depends", "KwDepends" ), ( r"(?i)desc", "KwDesc" ), ( r"(?i)detach", "KwDetach" ), ( r"(?i)dictionary", "KwDictionary" ), ( r"(?i)disable", "KwDisable" ), ( r"(?i)discard", "KwDiscard" ), ( r"(?i)distinct", "KwDistinct" ), ( r"(?i)do", "KwDo" ), ( r"(?i)document", "KwDocument" ), ( r"(?i)domain", "KwDomain" ), ( r"(?i)double", "KwDouble" ), ( r"(?i)drop", "KwDrop" ), ( r"(?i)each", "KwEach" ), ( r"(?i)else", "KwElse" ), ( r"(?i)enable", "KwEnable" ), ( r"(?i)encoding", "KwEncoding" ), ( r"(?i)encrypted", "KwEncrypted" ), ( r"(?i)end", "KwEnd" ), ( r"(?i)enum", "KwEnum" ), ( r"(?i)escape", "KwEscape" ), ( r"(?i)event", "KwEvent" ), ( r"(?i)except", "KwExcept" ), ( r"(?i)exclude", "KwExclude" ), ( r"(?i)excluding", "KwExcluding" ), ( r"(?i)exclusive", "KwExclusive" ), ( r"(?i)execute", "KwExecute" ), ( r"(?i)exists", "KwExists" ), ( r"(?i)explain", "KwExplain" ), ( r"(?i)extension", "KwExtension" ), ( r"(?i)external", "KwExternal" ), ( r"(?i)extract", "KwExtract" ), ( r"(?i)false", "KwFalse" ), ( r"(?i)family", "KwFamily" ), ( r"(?i)fetch", "KwFetch" ), ( r"(?i)filter", "KwFilter" ), ( r"(?i)first", "KwFirst" ), ( r"(?i)float", "KwFloat" ), ( r"(?i)following", "KwFollowing" ), ( r"(?i)for", "KwFor" ), ( r"(?i)force", "KwForce" ), ( r"(?i)foreign", "KwForeign" ), ( r"(?i)forward", "KwForward" ), ( r"(?i)freeze", "KwFreeze" ), ( r"(?i)from", "KwFrom" ), ( r"(?i)full", "KwFull" ), ( r"(?i)function", "KwFunction" ), ( r"(?i)functions", "KwFunctions" ), ( r"(?i)generated", "KwGenerated" ), ( r"(?i)global", "KwGlobal" ), ( r"(?i)grant", "KwGrant" ), ( r"(?i)granted", "KwGranted" ), ( r"(?i)greatest", "KwGreatest" ), ( r"(?i)group", "KwGroup" ), ( r"(?i)grouping", "KwGrouping" ), ( r"(?i)groups", "KwGroups" ), ( r"(?i)handler", "KwHandler" ), ( r"(?i)having", "KwHaving" ), ( r"(?i)header", "KwHeader" ), ( r"(?i)hold", "KwHold" ), ( r"(?i)hour", "KwHour" ), ( r"(?i)identity", "KwIdentity" ), ( r"(?i)if", "KwIf" ), ( r"(?i)ilike", "KwIlike" ), ( r"(?i)immediate", "KwImmediate" ), ( r"(?i)immutable", "KwImmutable" ), ( r"(?i)implicit", "KwImplicit" ), ( r"(?i)import", "KwImport" ), ( r"(?i)in", "KwIn" ), ( r"(?i)include", "KwInclude" ), ( r"(?i)including", "KwIncluding" ), ( r"(?i)increment", "KwIncrement" ), ( r"(?i)index", "KwIndex" ), ( r"(?i)indexes", "KwIndexes" ), ( r"(?i)inherit", "KwInherit" ), ( r"(?i)inherits", "KwInherits" ), ( r"(?i)initially", "KwInitially" ), ( r"(?i)inline", "KwInline" ), ( r"(?i)inner", "KwInner" ), ( r"(?i)inout", "KwInout" ), ( r"(?i)input", "KwInput" ), ( r"(?i)insensitive", "KwInsensitive" ), ( r"(?i)insert", "KwInsert" ), ( r"(?i)instead", "KwInstead" ), ( r"(?i)int", "KwInt" ), ( r"(?i)integer", "KwInteger" ), ( r"(?i)intersect", "KwIntersect" ), ( r"(?i)interval", "KwInterval" ), ( r"(?i)into", "KwInto" ), ( r"(?i)invoker", "KwInvoker" ), ( r"(?i)is", "KwIs" ), ( r"(?i)isnull", "KwIsnull" ), ( r"(?i)isolation", "KwIsolation" ), ( r"(?i)join", "KwJoin" ), ( r"(?i)key", "KwKey" ), ( r"(?i)label", "KwLabel" ), ( r"(?i)language", "KwLanguage" ), ( r"(?i)large", "KwLarge" ), ( r"(?i)last", "KwLast" ), ( r"(?i)lateral", "KwLateral" ), ( r"(?i)leading", "KwLeading" ), ( r"(?i)leakproof", "KwLeakproof" ), ( r"(?i)least", "KwLeast" ), ( r"(?i)left", "KwLeft" ), ( r"(?i)level", "KwLevel" ), ( r"(?i)like", "KwLike" ), ( r"(?i)limit", "KwLimit" ), ( r"(?i)listen", "KwListen" ), ( r"(?i)load", "KwLoad" ), ( r"(?i)local", "KwLocal" ), ( r"(?i)localtime", "KwLocaltime" ), ( r"(?i)localtimestamp", "KwLocaltimestamp" ), ( r"(?i)location", "KwLocation" ), ( r"(?i)lock", "KwLock" ), ( r"(?i)locked", "KwLocked" ), ( r"(?i)logged", "KwLogged" ), ( r"(?i)mapping", "KwMapping" ), ( r"(?i)match", "KwMatch" ), ( r"(?i)materialized", "KwMaterialized" ), ( r"(?i)maxvalue", "KwMaxvalue" ), ( r"(?i)method", "KwMethod" ), ( r"(?i)minute", "KwMinute" ), ( r"(?i)minvalue", "KwMinvalue" ), ( r"(?i)mode", "KwMode" ), ( r"(?i)month", "KwMonth" ), ( r"(?i)move", "KwMove" ), ( r"(?i)name", "KwName" ), ( r"(?i)names", "KwNames" ), ( r"(?i)national", "KwNational" ), ( r"(?i)natural", "KwNatural" ), ( r"(?i)nchar", "KwNchar" ), ( r"(?i)new", "KwNew" ), ( r"(?i)next", "KwNext" ), ( r"(?i)no", "KwNo" ), ( r"(?i)none", "KwNone" ), ( r"(?i)not", "KwNot" ), ( r"(?i)nothing", "KwNothing" ), ( r"(?i)notify", "KwNotify" ), ( r"(?i)notnull", "KwNotnull" ), ( r"(?i)nowait", "KwNowait" ), ( r"(?i)null", "KwNull" ), ( r"(?i)nullif", "KwNullif" ), ( r"(?i)nulls", "KwNulls" ), ( r"(?i)numeric", "KwNumeric" ), ( r"(?i)object", "KwObject" ), ( r"(?i)of", "KwOf" ), ( r"(?i)off", "KwOff" ), ( r"(?i)offset", "KwOffset" ), ( r"(?i)oids", "KwOids" ), ( r"(?i)old", "KwOld" ), ( r"(?i)on", "KwOn" ), ( r"(?i)only", "KwOnly" ), ( r"(?i)operator", "KwOperator" ), ( r"(?i)option", "KwOption" ), ( r"(?i)options", "KwOptions" ), ( r"(?i)or", "KwOr" ), ( r"(?i)order", "KwOrder" ), ( r"(?i)ordinality", "KwOrdinality" ), ( r"(?i)others", "KwOthers" ), ( r"(?i)out", "KwOut" ), ( r"(?i)outer", "KwOuter" ), ( r"(?i)over", "KwOver" ), ( r"(?i)overlaps", "KwOverlaps" ), ( r"(?i)overlay", "KwOverlay" ), ( r"(?i)overriding", "KwOverriding" ), ( r"(?i)owned", "KwOwned" ), ( r"(?i)owner", "KwOwner" ), ( r"(?i)parallel", "KwParallel" ), ( r"(?i)parser", "KwParser" ), ( r"(?i)partial", "KwPartial" ), ( r"(?i)partition", "KwPartition" ), ( r"(?i)passing", "KwPassing" ), ( r"(?i)password", "KwPassword" ), ( r"(?i)placing", "KwPlacing" ), ( r"(?i)plans", "KwPlans" ), ( r"(?i)policy", "KwPolicy" ), ( r"(?i)position", "KwPosition" ), ( r"(?i)preceding", "KwPreceding" ), ( r"(?i)precision", "KwPrecision" ), ( r"(?i)prepare", "KwPrepare" ), ( r"(?i)prepared", "KwPrepared" ), ( r"(?i)preserve", "KwPreserve" ), ( r"(?i)primary", "KwPrimary" ), ( r"(?i)prior", "KwPrior" ), ( r"(?i)privileges", "KwPrivileges" ), ( r"(?i)procedural", "KwProcedural" ), ( r"(?i)procedure", "KwProcedure" ), ( r"(?i)procedures", "KwProcedures" ), ( r"(?i)program", "KwProgram" ), ( r"(?i)publication", "KwPublication" ), ( r"(?i)quote", "KwQuote" ), ( r"(?i)range", "KwRange" ), ( r"(?i)read", "KwRead" ), ( r"(?i)real", "KwReal" ), ( r"(?i)reassign", "KwReassign" ), ( r"(?i)recheck", "KwRecheck" ), ( r"(?i)recursive", "KwRecursive" ), ( r"(?i)ref", "KwRef" ), ( r"(?i)references", "KwReferences" ), ( r"(?i)referencing", "KwReferencing" ), ( r"(?i)refresh", "KwRefresh" ), ( r"(?i)reindex", "KwReindex" ), ( r"(?i)relative", "KwRelative" ), ( r"(?i)release", "KwRelease" ), ( r"(?i)rename", "KwRename" ), ( r"(?i)repeatable", "KwRepeatable" ), ( r"(?i)replace", "KwReplace" ), ( r"(?i)replica", "KwReplica" ), ( r"(?i)reset", "KwReset" ), ( r"(?i)restart", "KwRestart" ), ( r"(?i)restrict", "KwRestrict" ), ( r"(?i)returning", "KwReturning" ), ( r"(?i)returns", "KwReturns" ), ( r"(?i)revoke", "KwRevoke" ), ( r"(?i)right", "KwRight" ), ( r"(?i)role", "KwRole" ), ( r"(?i)rollback", "KwRollback" ), ( r"(?i)rollup", "KwRollup" ), ( r"(?i)routine", "KwRoutine" ), ( r"(?i)routines", "KwRoutines" ), ( r"(?i)row", "KwRow" ), ( r"(?i)rows", "KwRows" ), ( r"(?i)rule", "KwRule" ), ( r"(?i)savepoint", "KwSavepoint" ), ( r"(?i)schema", "KwSchema" ), ( r"(?i)schemas", "KwSchemas" ), ( r"(?i)scroll", "KwScroll" ), ( r"(?i)search", "KwSearch" ), ( r"(?i)second", "KwSecond" ), ( r"(?i)security", "KwSecurity" ), ( r"(?i)select", "KwSelect" ), ( r"(?i)sequence", "KwSequence" ), ( r"(?i)sequences", "KwSequences" ), ( r"(?i)serializable", "KwSerializable" ), ( r"(?i)server", "KwServer" ), ( r"(?i)session", "KwSession" ), ( r"(?i)session_user", "KwSessionUser" ), ( r"(?i)set", "KwSet" ), ( r"(?i)setof", "KwSetof" ), ( r"(?i)sets", "KwSets" ), ( r"(?i)share", "KwShare" ), ( r"(?i)show", "KwShow" ), ( r"(?i)similar", "KwSimilar" ), ( r"(?i)simple", "KwSimple" ), ( r"(?i)skip", "KwSkip" ), ( r"(?i)smallint", "KwSmallint" ), ( r"(?i)snapshot", "KwSnapshot" ), ( r"(?i)some", "KwSome" ), ( r"(?i)sql", "KwSql" ), ( r"(?i)stable", "KwStable" ), ( r"(?i)standalone", "KwStandalone" ), ( r"(?i)start", "KwStart" ), ( r"(?i)statement", "KwStatement" ), ( r"(?i)statistics", "KwStatistics" ), ( r"(?i)stdin", "KwStdin" ), ( r"(?i)stdout", "KwStdout" ), ( r"(?i)storage", "KwStorage" ), ( r"(?i)stored", "KwStored" ), ( r"(?i)strict", "KwStrict" ), ( r"(?i)strip", "KwStrip" ), ( r"(?i)subscription", "KwSubscription" ), ( r"(?i)substring", "KwSubstring" ), ( r"(?i)support", "KwSupport" ), ( r"(?i)symmetric", "KwSymmetric" ), ( r"(?i)sysid", "KwSysid" ), ( r"(?i)system", "KwSystem" ), ( r"(?i)table", "KwTable" ), ( r"(?i)tables", "KwTables" ), ( r"(?i)tablesample", "KwTablesample" ), ( r"(?i)tablespace", "KwTablespace" ), ( r"(?i)temp", "KwTemp" ), ( r"(?i)template", "KwTemplate" ), ( r"(?i)temporary", "KwTemporary" ), ( r"(?i)text", "KwText" ), ( r"(?i)then", "KwThen" ), ( r"(?i)ties", "KwTies" ), ( r"(?i)time", "KwTime" ), ( r"(?i)timestamp", "KwTimestamp" ), ( r"(?i)to", "KwTo" ), ( r"(?i)trailing", "KwTrailing" ), ( r"(?i)transaction", "KwTransaction" ), ( r"(?i)transform", "KwTransform" ), ( r"(?i)treat", "KwTreat" ), ( r"(?i)trigger", "KwTrigger" ), ( r"(?i)trim", "KwTrim" ), ( r"(?i)true", "KwTrue" ), ( r"(?i)truncate", "KwTruncate" ), ( r"(?i)trusted", "KwTrusted" ), ( r"(?i)type", "KwType" ), ( r"(?i)types", "KwTypes" ), ( r"(?i)unbounded", "KwUnbounded" ), ( r"(?i)uncommitted", "KwUncommitted" ), ( r"(?i)unencrypted", "KwUnencrypted" ), ( r"(?i)union", "KwUnion" ), ( r"(?i)unique", "KwUnique" ), ( r"(?i)unknown", "KwUnknown" ), ( r"(?i)unlisten", "KwUnlisten" ), ( r"(?i)unlogged", "KwUnlogged" ), ( r"(?i)until", "KwUntil" ), ( r"(?i)update", "KwUpdate" ), ( r"(?i)user", "KwUser" ), ( r"(?i)using", "KwUsing" ), ( r"(?i)vacuum", "KwVacuum" ), ( r"(?i)valid", "KwValid" ), ( r"(?i)validate", "KwValidate" ), ( r"(?i)validator", "KwValidator" ), ( r"(?i)value", "KwValue" ), ( r"(?i)values", "KwValues" ), ( r"(?i)varchar", "KwVarchar" ), ( r"(?i)variadic", "KwVariadic" ), ( r"(?i)varying", "KwVarying" ), ( r"(?i)verbose", "KwVerbose" ), ( r"(?i)version", "KwVersion" ), ( r"(?i)view", "KwView" ), ( r"(?i)views", "KwViews" ), ( r"(?i)volatile", "KwVolatile" ), ( r"(?i)when", "KwWhen" ), ( r"(?i)where", "KwWhere" ), ( r"(?i)whitespace", "KwWhitespace" ), ( r"(?i)window", "KwWindow" ), ( r"(?i)with", "KwWith" ), ( r"(?i)within", "KwWithin" ), ( r"(?i)without", "KwWithout" ), ( r"(?i)work", "KwWork" ), ( r"(?i)wrapper", "KwWrapper" ), ( r"(?i)write", "KwWrite" ), ( r"(?i)xml", "KwXml" ), ( r"(?i)xmlattributes", "KwXmlattributes" ), ( r"(?i)xmlconcat", "KwXmlconcat" ), ( r"(?i)xmlelement", "KwXmlelement" ), ( r"(?i)xmlexists", "KwXmlexists" ), ( r"(?i)xmlforest", "KwXmlforest" ), ( r"(?i)xmlnamespaces", "KwXmlnamespaces" ), ( r"(?i)xmlparse", "KwXmlparse" ), ( r"(?i)xmlpi", "KwXmlpi" ), ( r"(?i)xmlroot", "KwXmlroot" ), ( r"(?i)xmlserialize", "KwXmlserialize" ), ( r"(?i)xmltable", "KwXmltable" ), ( r"(?i)year", "KwYear" ), ( r"(?i)yes", "KwYes" ), ( r"(?i)zone", "KwZone" ), ] }