Skip to content

Commit

Permalink
Fix DateTime/Currency Literals and Date Fields In SOQL
Browse files Browse the repository at this point in the history
Fix lexer to make DateTime and Currency literals case-insensitive.

Add formatting of date field names.
  • Loading branch information
cwarden committed Dec 6, 2023
1 parent 218bb18 commit 7425ead
Show file tree
Hide file tree
Showing 4 changed files with 375 additions and 368 deletions.
7 changes: 7 additions & 0 deletions formatter/visitors.go
Original file line number Diff line number Diff line change
Expand Up @@ -866,6 +866,13 @@ func (v *Visitor) VisitSoqlFieldsParameter(ctx *parser.SoqlFieldsParameterContex
return ctx.GetText()
}

func (v *Visitor) VisitDateFieldName(ctx *parser.DateFieldNameContext) interface{} {
if ctx.CONVERT_TIMEZONE() != nil {
return fmt.Sprintf("CONVERT_TIMEZONE(%s)", v.visitRule(ctx.FieldName()))
}
return v.visitRule(ctx.FieldName())
}

func (v *Visitor) VisitNullValue(ctx *parser.NullValueContext) interface{} {
return "null"
}
Expand Down
4 changes: 2 additions & 2 deletions grammar/ApexLexer.g4
Original file line number Diff line number Diff line change
Expand Up @@ -223,11 +223,11 @@ N_FISCAL_YEARS_AGO : N '_' F I S C A L '_' Y E A R S '_' A G O;

// SOQL Date literal
DateLiteral: Digit Digit Digit Digit '-' Digit Digit '-' Digit Digit;
DateTimeLiteral: DateLiteral 't' Digit Digit ':' Digit Digit ':' Digit Digit ('z' | (('+' | '-') Digit+ ( ':' Digit+)? ));
DateTimeLiteral: DateLiteral T Digit Digit ':' Digit Digit ':' Digit Digit (Z | (('+' | '-') Digit+ ( ':' Digit+)? ));

// SOQL Currency literal
// (NOTE: this is also a valid Identifier)
IntegralCurrencyLiteral: [a-z] [a-z] [a-z] Digit+;
IntegralCurrencyLiteral: [a-zA-Z] [a-zA-Z] [a-zA-Z] Digit+;

// SOSL Keywords
FIND : F I N D;
Expand Down
2 changes: 1 addition & 1 deletion parser/ApexLexer.interp

Large diffs are not rendered by default.

Loading

0 comments on commit 7425ead

Please sign in to comment.