forked from tgrosinger/aenea-grammars
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsql_grammar.py
50 lines (41 loc) · 1013 Bytes
/
sql_grammar.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# Created for aenea using libraries from the Dictation Toolbox
# https://github.com/dictation-toolbox/dragonfly-scripts
#
# Commands for writing SQL queries
#
# Author: Tony Grosinger
#
# Licensed under LGPL
import aenea
import aenea.configuration
from aenea import Choice
from aenea.lax import Text
import dragonfly
sql_map = {
"update": "UPDATE ",
"select": "SELECT ",
"from": "FROM ",
"count": "COUNT ",
"values": "VALUES ",
"as": "AS ",
"when": "WHEN ",
"in": "IN ",
"into": "INTO ",
"and": "AND ",
"all": "ALL ",
"similar to": "SIMILAR TO ",
"like": "LIKE ",
"set": "SET ",
}
sql_mapping = aenea.configuration.make_grammar_commands('sql', {
'<sqlKeyword>': Text("%(text)s"),
})
class SQL(dragonfly.MappingRule):
mapping = sql_mapping
extras = [
Choice('sqlKeyword', sql_map,)
]
def get_grammar(context):
sql_grammar = dragonfly.Grammar('sql', context=context)
sql_grammar.add_rule(SQL())
return sql_grammar