summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xpygments/lexers/gsql.py9
-rwxr-xr-xtests/examplefiles/gsql/test.gsql13
-rw-r--r--tests/examplefiles/gsql/test.gsql.output274
3 files changed, 262 insertions, 34 deletions
diff --git a/pygments/lexers/gsql.py b/pygments/lexers/gsql.py
index da32f780..3dd3ea1a 100755
--- a/pygments/lexers/gsql.py
+++ b/pygments/lexers/gsql.py
@@ -71,12 +71,11 @@ class GSQLLexer(RegexLexer):
'relations': [
(r'(-\s?)(\(.*\:\w?\))(\s?-)', bygroups(Operator, using(this), Operator)),
(r'->|<-', Operator),
- (r'[.*{}]', Punctuation),
+ (r'[.*{}\[\]\<\>\_]', Punctuation),
],
'strings': [
- (r'"(?:\\[tbnrf\'"\\]|[^\\"])*"', String),
+ (r'"([^"\\]|\\.)*"', String),
(r'@{1,2}\w+', Name.Variable),
- (r'(\<\w+)?\<(\w+\>?\,?\s?)+\>+', Name.Constant),
],
'whitespace': [
(r'\s+', Whitespace),
@@ -86,7 +85,7 @@ class GSQLLexer(RegexLexer):
(r'(\d+\.\d+|\d+)', Number),
],
'operators': [
- (r'[^0-9|\/|\-](\-\=|\+\=|\*\=|\\\=|\=|\=\=|\=\=\=|\+|\-|\*|\\|\+\=|\>|\<)[^\>|\/]', Operator),
- (r'(\(|\)|\,|\;|\=|\-|\+|\*|\/|\>|\<|\:)', Operator),
+ (r'\$|[^0-9|\/|\-](\-\=|\+\=|\*\=|\\\=|\=|\=\=|\=\=\=|\+|\-|\*|\\|\+\=|\>|\<)[^\>|\/]', Operator),
+ (r'(\||\(|\)|\,|\;|\=|\-|\+|\*|\/|\>|\<|\:)', Operator),
],
}
diff --git a/tests/examplefiles/gsql/test.gsql b/tests/examplefiles/gsql/test.gsql
index 805fce7a..9b8477bf 100755
--- a/tests/examplefiles/gsql/test.gsql
+++ b/tests/examplefiles/gsql/test.gsql
@@ -237,3 +237,16 @@ CREATE SCHEMA_CHANGE JOB do_schema_change FOR GRAPH Patents { # add vertex and e
}
RUN SCHEMA_CHANGE JOB do_schema_change
DROP JOB do_schema_change
+
+# Tests for PR#2006
+# Test lexer hang with params following SET<STRING> param
+CREATE QUERY tg_astar (VERTEX source_vertex, VERTEX target_vertex, SET<STRING> e_type, STRING wt_type, STRING latitude, STRING longitude,
+STRING wt_attr, BOOL display = False) {
+ # empty body for testing
+}
+
+# Test $(0), $"field", and empty positional parameter _
+CREATE LOADING JOB load_job_supplychain FOR GRAPH SupplyChain {
+ DEFINE FILENAME Inventory="m1:/home/tigergraph/mydata/supplychain/Inventory.csv";
+ LOAD Inventory TO EDGE in_warehouse_inventory VALUES($"warehouse", $1, $2) USING SEPARATOR=",", HEADER="true", EOL="\n";
+}
diff --git a/tests/examplefiles/gsql/test.gsql.output b/tests/examplefiles/gsql/test.gsql.output
index b207a9ca..109da84f 100644
--- a/tests/examplefiles/gsql/test.gsql.output
+++ b/tests/examplefiles/gsql/test.gsql.output
@@ -6,7 +6,9 @@
'(' Operator
'VERTEX' Keyword
' ' Text.Whitespace
-'<motionMember>' Name.Constant
+'<' Punctuation
+'motionMember' Name
+'>' Punctuation
' ' Text.Whitespace
'm1' Name
',' Operator
@@ -27,67 +29,139 @@
'# TYPEDEF TUPLE <x FLOAT, y FLOAT> XYPair;' Comment.Single
'\n\t' Text.Whitespace
'MapAccum' Name.Builtin
-'<VERTEX<motionMember>' Name.Constant
+'<' Punctuation
+'VERTEX' Keyword
+'<' Punctuation
+'motionMember' Name
+'>' Punctuation
',' Operator
' ' Text.Whitespace
'MapAccum' Name.Builtin
-'<STRING, FLOAT>>' Name.Constant
+'<' Punctuation
+'STRING' Keyword
+',' Operator
+' ' Text.Whitespace
+'FLOAT' Keyword
+'>' Punctuation
+'>' Punctuation
' ' Text.Whitespace
'@@likenessAccum' Name.Variable
';' Operator
'\n\t' Text.Whitespace
'MapAccum' Name.Builtin
-'<VERTEX<motionMember>, FLOAT>' Name.Constant
+'<' Punctuation
+'VERTEX' Keyword
+'<' Punctuation
+'motionMember' Name
+'>' Punctuation
+',' Operator
+' ' Text.Whitespace
+'FLOAT' Keyword
+'>' Punctuation
' ' Text.Whitespace
'@@BirthYearAccum' Name.Variable
';' Operator
'\n\t' Text.Whitespace
'MapAccum' Name.Builtin
-'<VERTEX<motionMember>, FLOAT>' Name.Constant
+'<' Punctuation
+'VERTEX' Keyword
+'<' Punctuation
+'motionMember' Name
+'>' Punctuation
+',' Operator
+' ' Text.Whitespace
+'FLOAT' Keyword
+'>' Punctuation
' ' Text.Whitespace
'@@HeightAccum' Name.Variable
';' Operator
'\n\t' Text.Whitespace
'MapAccum' Name.Builtin
-'<VERTEX<motionMember>, FLOAT>' Name.Constant
+'<' Punctuation
+'VERTEX' Keyword
+'<' Punctuation
+'motionMember' Name
+'>' Punctuation
+',' Operator
+' ' Text.Whitespace
+'FLOAT' Keyword
+'>' Punctuation
' ' Text.Whitespace
'@@WeightAccum' Name.Variable
';' Operator
'\n\t' Text.Whitespace
'ListAccum' Name.Builtin
-'<VERTEX<location>>' Name.Constant
+'<' Punctuation
+'VERTEX' Keyword
+'<' Punctuation
+'location' Name
+'>' Punctuation
+'>' Punctuation
' ' Text.Whitespace
'@@MemLocAccum' Name.Variable
';' Operator
'\n\t' Text.Whitespace
'MapAccum' Name.Builtin
-'<VERTEX<motionMember>, FLOAT>' Name.Constant
+'<' Punctuation
+'VERTEX' Keyword
+'<' Punctuation
+'motionMember' Name
+'>' Punctuation
+',' Operator
+' ' Text.Whitespace
+'FLOAT' Keyword
+'>' Punctuation
' ' Text.Whitespace
'@@LocAccum' Name.Variable
';' Operator
'\n\t' Text.Whitespace
'MapAccum' Name.Builtin
-'<VERTEX<motionMember>' Name.Constant
+'<' Punctuation
+'VERTEX' Keyword
+'<' Punctuation
+'motionMember' Name
+'>' Punctuation
',' Operator
' ' Text.Whitespace
'BagAccum' Name.Builtin
-'<VERTEX<incentive>>>' Name.Constant
+'<' Punctuation
+'VERTEX' Keyword
+'<' Punctuation
+'incentive' Name
+'>' Punctuation
+'>' Punctuation
+'>' Punctuation
' ' Text.Whitespace
'@@DayIncentives' Name.Variable
';' Operator
'\n\t' Text.Whitespace
'MapAccum' Name.Builtin
-'<VERTEX<motionMember>' Name.Constant
+'<' Punctuation
+'VERTEX' Keyword
+'<' Punctuation
+'motionMember' Name
+'>' Punctuation
',' Operator
' ' Text.Whitespace
'MapAccum' Name.Builtin
-'<STRING, FLOAT>>' Name.Constant
+'<' Punctuation
+'STRING' Keyword
+',' Operator
+' ' Text.Whitespace
+'FLOAT' Keyword
+'>' Punctuation
+'>' Punctuation
' ' Text.Whitespace
'@@MemberStats' Name.Variable
';' Operator
'\n\t' Text.Whitespace
'BagAccum' Name.Builtin
-'<VERTEX<incentive>>' Name.Constant
+'<' Punctuation
+'VERTEX' Keyword
+'<' Punctuation
+'incentive' Name
+'>' Punctuation
+'>' Punctuation
' ' Text.Whitespace
'@MemberIncentives' Name.Variable
';' Operator
@@ -377,7 +451,7 @@
' ' Text.Whitespace
'bys' Name
' ' Text.Whitespace
-'>' Operator
+'>' Punctuation
' ' Text.Whitespace
'lastMax' Name
' ' Text.Whitespace
@@ -397,7 +471,7 @@
' ' Text.Whitespace
'bys' Name
' ' Text.Whitespace
-'<' Operator
+'<' Punctuation
' ' Text.Whitespace
'lastMin' Name
' ' Text.Whitespace
@@ -567,7 +641,7 @@
' ' Text.Whitespace
'heights' Name
' ' Text.Whitespace
-'<' Operator
+'<' Punctuation
' ' Text.Whitespace
'height' Name
' ' Text.Whitespace
@@ -577,7 +651,7 @@
' ' Text.Whitespace
'heights' Name
' ' Text.Whitespace
-'>' Operator
+'>' Punctuation
' ' Text.Whitespace
'lastMax' Name
' ' Text.Whitespace
@@ -597,7 +671,7 @@
' ' Text.Whitespace
'heights' Name
' ' Text.Whitespace
-'<' Operator
+'<' Punctuation
' ' Text.Whitespace
'lastMin' Name
' ' Text.Whitespace
@@ -662,7 +736,7 @@
' ' Text.Whitespace
'heights' Name
' ' Text.Whitespace
-'<' Operator
+'<' Punctuation
' ' Text.Whitespace
'height' Name
' ' Text.Whitespace
@@ -792,7 +866,7 @@
' ' Text.Whitespace
'weights' Name
' ' Text.Whitespace
-'<' Operator
+'<' Punctuation
' ' Text.Whitespace
'weight' Name
' ' Text.Whitespace
@@ -802,7 +876,7 @@
' ' Text.Whitespace
'weights' Name
' ' Text.Whitespace
-'>' Operator
+'>' Punctuation
' ' Text.Whitespace
'lastMax' Name
' ' Text.Whitespace
@@ -822,7 +896,7 @@
' ' Text.Whitespace
'weights' Name
' ' Text.Whitespace
-'<' Operator
+'<' Punctuation
' ' Text.Whitespace
'lastMin' Name
' ' Text.Whitespace
@@ -887,7 +961,7 @@
' ' Text.Whitespace
'weights' Name
' ' Text.Whitespace
-'<' Operator
+'<' Punctuation
' ' Text.Whitespace
'weight' Name
' ' Text.Whitespace
@@ -1025,7 +1099,7 @@
' ' Text.Whitespace
'loc' Name
' ' Text.Whitespace
-'<' Operator
+'<' Punctuation
' ' Text.Whitespace
'5800' Literal.Number
' ' Text.Whitespace
@@ -1035,7 +1109,7 @@
' ' Text.Whitespace
'loc' Name
' ' Text.Whitespace
-'>' Operator
+'>' Punctuation
' ' Text.Whitespace
'lastMax' Name
' ' Text.Whitespace
@@ -1058,7 +1132,7 @@
' ' Text.Whitespace
'loc' Name
' ' Text.Whitespace
-'<' Operator
+'<' Punctuation
' ' Text.Whitespace
'lastMin' Name
' ' Text.Whitespace
@@ -1136,7 +1210,7 @@
' ' Text.Whitespace
'loc' Name
' ' Text.Whitespace
-'>' Operator
+'>' Punctuation
' ' Text.Whitespace
'5800' Literal.Number
' ' Text.Whitespace
@@ -1263,7 +1337,7 @@
'.' Punctuation
'IncentiveDate' Name
' ' Text.Whitespace
-'>' Operator
+'>' Punctuation
' ' Text.Whitespace
'datetime_sub' Keyword
'(' Operator
@@ -1283,7 +1357,7 @@
'.' Punctuation
'IncentiveDate' Name
' ' Text.Whitespace
-'<' Operator
+'<' Punctuation
' ' Text.Whitespace
'lastRecording' Name
';' Operator
@@ -1594,4 +1668,146 @@
'JOB' Name
' ' Text.Whitespace
'do_schema_change' Name
+'\n\n' Text.Whitespace
+
+'# Tests for PR#2006' Comment.Single
+'\n' Text.Whitespace
+
+'# Test lexer hang with params following SET<STRING> param' Comment.Single
+'\n' Text.Whitespace
+
+'CREATE' Keyword
+' ' Text.Whitespace
+'QUERY' Keyword
+' ' Text.Whitespace
+'tg_astar' Name
+' ' Text.Whitespace
+'(' Operator
+'VERTEX' Keyword
+' ' Text.Whitespace
+'source_vertex' Name
+',' Operator
+' ' Text.Whitespace
+'VERTEX' Keyword
+' ' Text.Whitespace
+'target_vertex' Name
+',' Operator
+' ' Text.Whitespace
+'SET' Keyword
+'<' Punctuation
+'STRING' Keyword
+'>' Punctuation
+' ' Text.Whitespace
+'e_type' Name
+',' Operator
+' ' Text.Whitespace
+'STRING' Keyword
+' ' Text.Whitespace
+'wt_type' Name
+',' Operator
+' ' Text.Whitespace
+'STRING' Keyword
+' ' Text.Whitespace
+'latitude' Name
+',' Operator
+' ' Text.Whitespace
+'STRING' Keyword
+' ' Text.Whitespace
+'longitude' Name
+',' Operator
+'\n' Text.Whitespace
+
+'STRING' Keyword
+' ' Text.Whitespace
+'wt_attr' Name
+',' Operator
+' ' Text.Whitespace
+'BOOL' Keyword
+' ' Text.Whitespace
+'display' Name
+' ' Text.Whitespace
+'=' Operator
+' ' Text.Whitespace
+'False' Keyword
+')' Operator
+' ' Text.Whitespace
+'{' Punctuation
+'\n ' Text.Whitespace
+'# empty body for testing' Comment.Single
+'\n' Text.Whitespace
+
+'}' Punctuation
+'\n\n' Text.Whitespace
+
+'# Test $(0), $"field", and empty positional parameter _' Comment.Single
+'\n' Text.Whitespace
+
+'CREATE' Keyword
+' ' Text.Whitespace
+'LOADING' Name
+' ' Text.Whitespace
+'JOB' Name
+' ' Text.Whitespace
+'load_job_supplychain' Name
+' ' Text.Whitespace
+'FOR' Keyword
+' ' Text.Whitespace
+'GRAPH' Keyword
+' ' Text.Whitespace
+'SupplyChain' Name
+' ' Text.Whitespace
+'{' Punctuation
+'\n ' Text.Whitespace
+'DEFINE' Name
+' ' Text.Whitespace
+'FILENAME' Name
+' ' Text.Whitespace
+'Inventory' Name
+'=' Operator
+'"m1:/home/tigergraph/mydata/supplychain/Inventory.csv"' Literal.String
+';' Operator
+'\n ' Text.Whitespace
+'LOAD' Name
+' ' Text.Whitespace
+'Inventory' Name
+' ' Text.Whitespace
+'TO' Keyword
+' ' Text.Whitespace
+'EDGE' Keyword
+' ' Text.Whitespace
+'in_warehouse_inventory' Name
+' ' Text.Whitespace
+'VALUES' Keyword
+'(' Operator
+'$' Operator
+'"warehouse"' Literal.String
+',' Operator
+' ' Text.Whitespace
+'$' Operator
+'1' Literal.Number
+',' Operator
+' ' Text.Whitespace
+'$' Operator
+'2' Literal.Number
+')' Operator
+' ' Text.Whitespace
+'USING' Name
+' ' Text.Whitespace
+'SEPARATOR' Name
+'=' Operator
+'","' Literal.String
+',' Operator
+' ' Text.Whitespace
+'HEADER' Name
+'=' Operator
+'"true"' Literal.String
+',' Operator
+' ' Text.Whitespace
+'EOL' Name
+'=' Operator
+'"\\n"' Literal.String
+';' Operator
+'\n' Text.Whitespace
+
+'}' Punctuation
'\n' Text.Whitespace