New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added GSQL lexer #1809
Added GSQL lexer #1809
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
import re | ||
|
||
from pygments.lexer import RegexLexer, include, bygroups, using, this | ||
from pygments.token import Keyword, Punctuation, Comment, Operator, Name,\ | ||
String, Number, Whitespace | ||
|
||
|
||
__all__ = ["GSQLLexer"] | ||
|
||
class GSQLLexer(RegexLexer): | ||
name = 'GSQL' | ||
aliases = ['gsql'] | ||
filenames = ['*.gsql'] | ||
|
||
flags = re.MULTILINE | re.IGNORECASE | ||
|
||
tokens = { | ||
'root': [ | ||
include('comment'), | ||
include('keywords'), | ||
include('clauses'), | ||
include('accums'), | ||
include('relations'), | ||
include('strings'), | ||
include('whitespace'), | ||
include('barewords'), | ||
include('operators'), | ||
], | ||
'comment': [ | ||
(r'.*\#.*\n', Comment.Single), | ||
(r'.*\/\*\s*.*\s*\*\/', Comment.Multiline), | ||
], | ||
'keywords': [ | ||
(r'(ACCUM|AND|ANY|API|AS|ASC|AVG|BAG|BATCH|BETWEEN|BOOL|BOTH|' | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please use the |
||
r'BREAK|BY|CASE|CATCH|COALESCE|COMPRESS|CONTINUE|COUNT|' | ||
r'CREATE|DATETIME|DATETIME_ADD|DATETIME_SUB|DELETE|DESC|DISTRIBUTED|DO|' | ||
r'DOUBLE|EDGE|ELSE|END|ESCAPE|EXCEPTION|FALSE|FILE|FILTER|FLOAT|FOREACH|FOR|' | ||
r'FROM|GRAPH|GROUP|GSQL_INT_MAX|GSQL_INT_MIN|GSQL_UINT_MAX|HAVING|IF|' | ||
r'IN|INSERT|INT|INTERPRET|INTERSECT|INTERVAL|INTO|IS|ISEMPTY|JSONARRAY|JSONOBJECT|LASTHOP|' | ||
r'LEADING|LIKE|LIMIT|LIST|LOAD_ACCUM|LOG|MAP|MATCH|MAX|MIN|MINUS|NOT|' | ||
r'NOW|NULL|OFFSET|OR|ORDER|PATH|PER|PINNED|POST_ACCUM|POST-ACCUM|PRIMARY_ID|PRINT|' | ||
r'QUERY|RAISE|RANGE|REPLACE|RESET_COLLECTION_ACCUM|RETURN|RETURNS|RUN|SAMPLE|SELECT|SELECT_VERTEX|' | ||
r'SET|SRC|STATIC|STRING|SUM|SYNTAX|TARGET|TAGSTGT|THEN|TO|TO_CSV|TO_DATETIME|TRAILING|TRIM|TRUE|' | ||
r'TRY|TUPLE|TYPEDEF|UINT|UNION|UPDATE|VALUES|VERTEX|WHEN|WHERE|WHILE|WITH)\b', Keyword), | ||
], | ||
'clauses': [ | ||
(r'(accum|having|limit|order|postAccum|sample|where)\b', Keyword), | ||
], | ||
'accums': [ | ||
(r'(andaccum|arrayaccum|avgaccum|bagaccum|bitwiseandaccum|' | ||
r'bitwiseoraccum|groupbyaccum|heapaccum|listaccum|MapAccum|' | ||
r'maxaccum|minaccum|oraccum|setaccum|sumaccum)\b', Keyword), | ||
], | ||
# 'name': [ | ||
# (r'(\@\@w+)\b', Name), | ||
# ], | ||
Comment on lines
+61
to
+63
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you please remove this? |
||
'relations': [ | ||
(r'(-\s?)(\(.*\:\w?\))(\s?-)', bygroups(Operator, using(this), Operator)), | ||
(r'->|<-', Operator), | ||
(r'[.*{}]', Punctuation), | ||
], | ||
'strings': [ | ||
(r'"(?:\\[tbnrf\'"\\]|[^\\"])*"', String), | ||
(r'@{1,2}\w+', Name.Variable), | ||
(r'(\<\w+)?\<(\w+\>?\,?\s?)+\>+', Name.Constant), | ||
], | ||
'whitespace': [ | ||
(r'\s+', Whitespace), | ||
], | ||
'barewords': [ | ||
(r'[a-z]\w*', Name), | ||
(r'(\d+\.\d+|\d+)', Number), | ||
], | ||
'operators': [ | ||
(r'[^0-9|\/|\-](\-\=|\+\=|\*\=|\\\=|\=|\=\=|\=\=\=|\+|\-|\*|\\|\+\=|\>|\<)[^\>|\/]', Operator), | ||
(r'(\(|\)|\,|\;|\=|\-|\+|\*|\/|\>|\<|\:)', Operator), | ||
], | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,223 @@ | ||
CREATE QUERY Member_Likeness(VERTEX <motionMember> m1, STRING inDate) FOR GRAPH motionData { | ||
# TYPEDEF TUPLE <x FLOAT, y FLOAT> XYPair; | ||
MapAccum<VERTEX<motionMember>, MapAccum<STRING, FLOAT>> @@likenessAccum; | ||
MapAccum<VERTEX<motionMember>, FLOAT> @@BirthYearAccum; | ||
MapAccum<VERTEX<motionMember>, FLOAT> @@HeightAccum; | ||
MapAccum<VERTEX<motionMember>, FLOAT> @@WeightAccum; | ||
ListAccum<VERTEX<location>> @@MemLocAccum; | ||
MapAccum<VERTEX<motionMember>, FLOAT> @@LocAccum; | ||
MapAccum<VERTEX<motionMember>, BagAccum<VERTEX<incentive>>> @@DayIncentives; | ||
MapAccum<VERTEX<motionMember>, MapAccum<STRING, FLOAT>> @@MemberStats; | ||
BagAccum<VERTEX<incentive>> @MemberIncentives; | ||
AvgAccum @@StepsAccum; | ||
AvgAccum @@BoutsAccum; | ||
AvgAccum @@MilesAccum; | ||
|
||
# Universal Vars | ||
INT lastMax = 0; | ||
INT lastMin = 1000; | ||
FLOAT mult; | ||
|
||
# Age Vars | ||
INT ageRange; | ||
INT birthYear; | ||
|
||
# Height Vars | ||
INT heightRange; | ||
INT height; | ||
|
||
# Height Vars | ||
INT weightRange; | ||
INT weight; | ||
|
||
# Location Vars | ||
FLOAT locRange; | ||
VERTEX memLoc; | ||
|
||
# Activity Vars | ||
DATETIME lastRecording; | ||
|
||
# lastRecording = to_datetime("2018-05-19"); | ||
lastRecording = to_datetime(inDate); | ||
|
||
/* | ||
|
||
test comment block | ||
|
||
*/ | ||
|
||
|
||
members = {motionMember.*}; | ||
|
||
birthYear = Get_Birth_Year(m1); | ||
height = m1.Height; | ||
weight = m1.Weight; | ||
temp = SELECT loc FROM members:member -(:e) - location: loc | ||
WHERE member == m1 | ||
ACCUM | ||
@@MemLocAccum += loc; | ||
FOREACH loc in @@MemLocAccum DO | ||
memLoc = loc; | ||
END; | ||
|
||
PRINT memLoc; | ||
PRINT birthYear; | ||
PRINT height; | ||
PRINT weight; | ||
|
||
results = SELECT member FROM members:member | ||
ACCUM | ||
@@BirthYearAccum += (member -> abs(Get_Birth_Year(member) - birthYear)); | ||
|
||
FOREACH (member,bys) in @@BirthYearAccum DO | ||
IF bys > lastMax THEN | ||
lastMax = bys; | ||
END; | ||
IF bys < lastMin THEN | ||
lastMin = bys; | ||
END; | ||
END; | ||
|
||
ageRange = lastMax - lastMin; | ||
print ageRange; | ||
mult = 1.0/ageRange; | ||
|
||
|
||
FOREACH (member,bys) in @@BirthYearAccum DO | ||
bys = 1 - bys * mult; | ||
@@likenessAccum += (member -> ("age" -> bys)); | ||
END; | ||
|
||
lastMax = 0; | ||
lastMin = 1000; | ||
mult = 0; | ||
|
||
results = SELECT member FROM members:member | ||
ACCUM | ||
@@HeightAccum += (member -> abs(member.Height - height)); | ||
|
||
FOREACH (member,heights) in @@HeightAccum DO | ||
IF heights < height THEN | ||
IF heights > lastMax THEN | ||
lastMax = heights; | ||
END; | ||
IF heights < lastMin THEN | ||
lastMin = heights; | ||
END; | ||
END; | ||
END; | ||
|
||
heightRange = lastMax - lastMin; | ||
print heightRange; | ||
mult = 1.0/heightRange; | ||
|
||
|
||
FOREACH (member,heights) in @@HeightAccum DO | ||
IF heights < height THEN | ||
heights = 1 - heights * mult; | ||
ELSE | ||
heights = 0; | ||
END; | ||
@@likenessAccum += (member -> ("height" -> heights)); | ||
END; | ||
|
||
lastMax = 0; | ||
lastMin = 1000; | ||
mult = 0; | ||
|
||
results = SELECT member FROM members:member | ||
ACCUM | ||
@@WeightAccum += (member -> abs(member.Weight - weight)); | ||
|
||
FOREACH (member,weights) in @@WeightAccum DO | ||
IF weights < weight THEN | ||
IF weights > lastMax THEN | ||
lastMax = weights; | ||
END; | ||
IF weights < lastMin THEN | ||
lastMin = weights; | ||
END; | ||
END; | ||
END; | ||
|
||
weightRange = lastMax - lastMin; | ||
print weightRange; | ||
mult = 1.0/weightRange; | ||
|
||
|
||
FOREACH (member,weights) in @@WeightAccum DO | ||
IF weights < weight THEN | ||
weights = 1 - weights * mult; | ||
ELSE | ||
weights = 0; | ||
END; | ||
@@likenessAccum += (member -> ("weight" -> weights)); | ||
END; | ||
|
||
lastMax = 0; | ||
lastMin = 1000; | ||
mult = 0; | ||
|
||
resultsLoc = SELECT loc FROM members:member -(:e) - location: loc | ||
ACCUM | ||
@@LocAccum += (member -> Check_Distance(loc,memLoc)); | ||
FOREACH (member,loc) in @@LocAccum DO | ||
IF loc < 5800 THEN | ||
IF loc > lastMax THEN | ||
lastMax = ceil(loc); | ||
END; | ||
IF loc < lastMin THEN | ||
lastMin = floor(loc); | ||
END; | ||
END; | ||
END; | ||
|
||
PRINT lastMax; | ||
PRINT lastMin; | ||
|
||
locRange = lastMax - lastMin; | ||
print locRange; | ||
mult = 1.0/locRange; | ||
|
||
FOREACH (member,loc) in @@LocAccum DO | ||
IF loc > 5800 THEN | ||
loc = -1; | ||
ELSE | ||
loc = 1 - loc * mult; | ||
END; | ||
@@likenessAccum += (member -> ("distance" -> loc)); | ||
END; | ||
|
||
lastMax = 0; | ||
lastMin = 1000; | ||
mult = 0; | ||
|
||
incentives = {incentive.*}; | ||
|
||
incentives = SELECT incent FROM incentives:incent - (:e) - lookupRule:rule WHERE | ||
rule.RuleName == "Tenacity" AND incent.IncentiveDate > datetime_sub(lastRecording, INTERVAL 1 MONTH) AND incent.IncentiveDate < lastRecording; | ||
|
||
members = SELECT member FROM incentives:incent - (:e) - motionMember:member | ||
ACCUM | ||
@@DayIncentives += (member -> (incent)); | ||
|
||
FOREACH (member, incent) IN @@DayIncentives DO | ||
@@StepsAccum = 0; | ||
FOREACH Incentive IN incent DO | ||
@@StepsAccum += Incentive.TotalSteps; | ||
@@BoutsAccum += Incentive.TotalBouts; | ||
@@MilesAccum += Incentive.Miles; | ||
END; | ||
@@MemberStats += (member -> ("stepsAvg" -> @@StepsAccum)); | ||
@@MemberStats += (member -> ("stepsSlope" -> Linear_Regression(incent, 1))); | ||
# @@MemberStats += (member -> ("boutsAvg" -> @@BoutsAccum)); | ||
# @@MemberStats += (member -> ("boutsSlope" -> Linear_Regression(incent, 2))); | ||
@@MemberStats += (member -> ("milesAvg" -> @@MilesAccum)); | ||
@@MemberStats += (member -> ("milesSlope" -> Linear_Regression(incent, 3))); | ||
END; | ||
|
||
|
||
PRINT @@MemberStats; | ||
PRINT @@likenessAccum; | ||
|
||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add a comment describing this lexer -- ideally with a link to the language definition. This comment should end with
.. versionadded:: 2.10
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@DanBarkus thanks for the great work 😄
@Anteru I can't wait to see this PR Merged 😄
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@DanBarkus Very cool! Can't wait to use it!
@Anteru Looking forward to the merge!