Skip to content

Commit 17d7fd4

Browse files
committed
v0.0.8
Fix parsing bugs and cleanup package
1 parent 8a66088 commit 17d7fd4

File tree

15 files changed

+1273
-900
lines changed

15 files changed

+1273
-900
lines changed

apex/grammar.js

Lines changed: 12 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ const PREC = {
2525
BIT_OR: 6, // |
2626
BIT_XOR: 7, // ^
2727
BIT_AND: 8, // &
28-
EQUALITY: 9, // == !=
28+
EQUALITY: 9, // == != <>
2929
GENERIC: 10,
3030
REL: 10, // < <= > >= instanceof
3131
SHIFT: 11, // << >> >>>
@@ -75,6 +75,7 @@ module.exports = grammar({
7575
[$.field_access, $.method_invocation, $.expression],
7676
[$.map_initializer, $.array_initializer],
7777
[$.function_name, $.count_expression],
78+
[$.switch_label, $.primary_expression],
7879
],
7980

8081
rules: {
@@ -104,17 +105,13 @@ module.exports = grammar({
104105
dml_expression: ($) =>
105106
prec.right(
106107
choice(
107-
seq($.dml_type, $.primary_expression),
108+
seq($.dml_type, $.expression),
108109
seq(
109110
alias(ci("upsert"), $.dml_type),
110-
$.primary_expression,
111+
$.expression,
111112
optional($._unannotated_type)
112113
),
113-
seq(
114-
alias(ci("merge"), $.dml_type),
115-
$.primary_expression,
116-
$.identifier // TODO: should be primary_expression
117-
)
114+
seq(alias(ci("merge"), $.dml_type), $.expression, " ", $.expression)
118115
)
119116
),
120117
dml_type: ($) =>
@@ -164,6 +161,7 @@ module.exports = grammar({
164161
["==", PREC.EQUALITY],
165162
["===", PREC.EQUALITY],
166163
["!=", PREC.EQUALITY],
164+
["<>", PREC.EQUALITY],
167165
["!==", PREC.EQUALITY],
168166
["&&", PREC.AND],
169167
["||", PREC.OR],
@@ -360,8 +358,11 @@ module.exports = grammar({
360358
seq(
361359
ci("when"),
362360
choice(
363-
commaJoined1(seq(optional($._unannotated_type), $.identifier)),
364-
commaJoined1($._literal),
361+
// SObject type var syntax
362+
prec.right(
363+
commaJoined1(seq(optional($._unannotated_type), $.identifier))
364+
),
365+
commaJoined1($.expression),
365366
ci("else")
366367
)
367368
),
@@ -774,8 +775,6 @@ module.exports = grammar({
774775
_simple_type: ($) =>
775776
choice(
776777
$.void_type,
777-
$.integral_type,
778-
$.floating_point_type,
779778
$.boolean_type,
780779
alias($.identifier, $.type_identifier),
781780
$.scoped_type_identifier,
@@ -814,10 +813,6 @@ module.exports = grammar({
814813
field("dimensions", $.dimensions)
815814
),
816815

817-
integral_type: ($) => choice("byte", "short", "int", "long", "char"),
818-
819-
floating_point_type: ($) => choice("float", "double"),
820-
821816
boolean_type: ($) => "boolean",
822817

823818
_method_header: ($) =>
@@ -929,6 +924,6 @@ module.exports = grammar({
929924
)
930925
),
931926

932-
string_literal: ($) => /'(\\[nNrRtTbBfF"'_%\\]|[^\\'])*'/,
927+
string_literal: ($) => /'(\\[nNrRtTbBfFuU"'_%\\]|[^\\'])*'/,
933928
},
934929
});

apex/queries/highlights.scm

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -209,9 +209,6 @@
209209

210210
[
211211
(boolean_type)
212-
(integral_type)
213-
(floating_point_type)
214-
(floating_point_type)
215212
(void_type)
216213
] @type.defaultLibrary
217214

apex/test/corpus/dml_keywords.txt

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,67 @@ public class Me {
170170
(identifier)
171171
(identifier)))))))
172172

173+
================================================================================
174+
DML KEYWORD merge from array
175+
================================================================================
176+
177+
public class Me {
178+
{
179+
merge accounts[0] accounts[1];
180+
}
181+
}
182+
183+
--------------------------------------------------------------------------------
184+
185+
(parser_output
186+
(class_declaration
187+
(modifiers
188+
(modifier))
189+
(identifier)
190+
(class_body
191+
(block
192+
(expression_statement
193+
(dml_expression
194+
(dml_type)
195+
(array_access
196+
(identifier)
197+
(int))
198+
(array_access
199+
(identifier)
200+
(int))))))))
201+
202+
================================================================================
203+
DML KEYWORD merge new list
204+
================================================================================
205+
206+
public class Me {
207+
{
208+
merge masterContact new List<Contact>{oldContact1, oldContact2};
209+
}
210+
}
211+
212+
--------------------------------------------------------------------------------
213+
214+
(parser_output
215+
(class_declaration
216+
(modifiers
217+
(modifier))
218+
(identifier)
219+
(class_body
220+
(block
221+
(expression_statement
222+
(dml_expression
223+
(dml_type)
224+
(identifier)
225+
(array_creation_expression
226+
(generic_type
227+
(type_identifier)
228+
(type_arguments
229+
(type_identifier)))
230+
(array_initializer
231+
(identifier)
232+
(identifier)))))))))
233+
173234
================================================================================
174235
DML KEYWORD upsert from method with field reference
175236
================================================================================
@@ -232,3 +293,36 @@ public class Me {
232293
(array_initializer
233294
(identifier)
234295
(identifier)))))))))
296+
297+
================================================================================
298+
DML KEYWORD insert assigned
299+
================================================================================
300+
301+
public class Me {
302+
{
303+
insert accMG = new Account(Name='matching gift company');
304+
}
305+
}
306+
307+
--------------------------------------------------------------------------------
308+
309+
(parser_output
310+
(class_declaration
311+
(modifiers
312+
(modifier))
313+
(identifier)
314+
(class_body
315+
(block
316+
(expression_statement
317+
(dml_expression
318+
(dml_type)
319+
(assignment_expression
320+
(identifier)
321+
(assignment_operator)
322+
(object_creation_expression
323+
(type_identifier)
324+
(argument_list
325+
(assignment_expression
326+
(identifier)
327+
(assignment_operator)
328+
(string_literal)))))))))))

apex/test/corpus/expressions.txt

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,29 @@ public class Me {
2525
(field_access
2626
(identifier)
2727
(identifier))))))))
28+
29+
================================================================================
30+
EXPRESSIONS Double Class
31+
================================================================================
32+
33+
public class Me {
34+
{
35+
double.valueOf(1);
36+
}
37+
}
38+
39+
--------------------------------------------------------------------------------
40+
41+
(parser_output
42+
(class_declaration
43+
(modifiers
44+
(modifier))
45+
(identifier)
46+
(class_body
47+
(block
48+
(expression_statement
49+
(method_invocation
50+
(identifier)
51+
(identifier)
52+
(argument_list
53+
(int))))))))

apex/test/corpus/operators.txt

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -577,6 +577,34 @@ public class Me {
577577

578578
--------------------------------------------------------------------------------
579579

580+
(parser_output
581+
(class_declaration
582+
(modifiers
583+
(modifier))
584+
(identifier)
585+
(class_body
586+
(block
587+
(local_variable_declaration
588+
(type_identifier)
589+
(variable_declarator
590+
(identifier)
591+
(assignment_operator)
592+
(binary_expression
593+
(int)
594+
(int))))))))
595+
596+
================================================================================
597+
OPERATOR Inequality ltgt
598+
================================================================================
599+
600+
public class Me {
601+
{
602+
Boolean test = 1 <> 2;
603+
}
604+
}
605+
606+
--------------------------------------------------------------------------------
607+
580608
(parser_output
581609
(class_declaration
582610
(modifiers

apex/test/corpus/properties.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ public class Me {
157157
(field_declaration
158158
(modifiers
159159
(modifier))
160-
(floating_point_type)
160+
(type_identifier)
161161
(variable_declarator
162162
(identifier))
163163
(accessor_list

apex/test/corpus/switch.txt

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -392,3 +392,98 @@ public class Me {
392392
(identifier)
393393
(argument_list
394394
(string_literal))))))))))))
395+
396+
================================================================================
397+
SWITCH With Parens
398+
================================================================================
399+
400+
public class Me {
401+
{
402+
switch on (x) {
403+
when 1 { return 1; }
404+
when ((2)) { return 2; }
405+
when (3), (4) { return 3; }
406+
}
407+
}
408+
}
409+
410+
--------------------------------------------------------------------------------
411+
412+
(parser_output
413+
(class_declaration
414+
(modifiers
415+
(modifier))
416+
(identifier)
417+
(class_body
418+
(block
419+
(switch_expression
420+
(parenthesized_expression
421+
(identifier))
422+
(switch_block
423+
(switch_rule
424+
(switch_label
425+
(int))
426+
(block
427+
(return_statement
428+
(int))))
429+
(switch_rule
430+
(switch_label
431+
(parenthesized_expression
432+
(parenthesized_expression
433+
(int))))
434+
(block
435+
(return_statement
436+
(int))))
437+
(switch_rule
438+
(switch_label
439+
(parenthesized_expression
440+
(int))
441+
(parenthesized_expression
442+
(int)))
443+
(block
444+
(return_statement
445+
(int))))))))))
446+
447+
================================================================================
448+
SWITCH on values
449+
================================================================================
450+
451+
public class Me {
452+
{
453+
switch on monthsSinceFiscalStart {
454+
when 1, 2, 3, -9, -10, -11 {
455+
fiscalQuarter = 1;
456+
}
457+
}
458+
}
459+
}
460+
461+
--------------------------------------------------------------------------------
462+
463+
(parser_output
464+
(class_declaration
465+
(modifiers
466+
(modifier))
467+
(identifier)
468+
(class_body
469+
(block
470+
(switch_expression
471+
(identifier)
472+
(switch_block
473+
(switch_rule
474+
(switch_label
475+
(int)
476+
(int)
477+
(int)
478+
(unary_expression
479+
(int))
480+
(unary_expression
481+
(int))
482+
(unary_expression
483+
(int)))
484+
(block
485+
(expression_statement
486+
(assignment_expression
487+
(identifier)
488+
(assignment_operator)
489+
(int)))))))))))

0 commit comments

Comments
 (0)