Skip to content
This repository has been archived by the owner on Jun 9, 2024. It is now read-only.

Commit

Permalink
made new types of literals (#10)
Browse files Browse the repository at this point in the history
* made new types of literals

* updated literals

* addressed gavins comments

* removed unused fragments
  • Loading branch information
brennanjl authored Mar 26, 2024
1 parent cec5754 commit a055a15
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 34 deletions.
33 changes: 21 additions & 12 deletions SQLLexer.g4
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,6 @@ END_: 'END';
ESCAPE_: 'ESCAPE';
EXCEPT_: 'EXCEPT';
EXISTS_: 'EXISTS';
FALSE_: 'FALSE';
FILTER_: 'FILTER';
FIRST_: 'FIRST';
FROM_: 'FROM';
Expand All @@ -96,7 +95,6 @@ NOTHING_: 'NOTHING';
NOTNULL_: 'NOTNULL';
NOT_: 'NOT';
NULLS_: 'NULLS';
NULL_: 'NULL';
OFFSET_: 'OFFSET';
OF_: 'OF';
ON_: 'ON';
Expand All @@ -110,7 +108,6 @@ RIGHT_: 'RIGHT';
SELECT_: 'SELECT';
SET_: 'SET';
THEN_: 'THEN';
TRUE_: 'TRUE';
UNION_: 'UNION';
UPDATE_: 'UPDATE';
USING_: 'USING';
Expand All @@ -119,26 +116,38 @@ WHEN_: 'WHEN';
WHERE_: 'WHERE';
WITH_: 'WITH';

// literals

BOOLEAN_LITERAL:
'true'
| 'false'
;

NUMERIC_LITERAL:
[0-9]+
;

BLOB_LITERAL:
'0x' [0-9a-f]+
;

TEXT_LITERAL:
'\'' ( ~'\'' | '\'\'')* '\''
;

NULL_LITERAL: 'null';

IDENTIFIER:
'"' (~'"' | '""')* '"' // Delimited identifiers
| '`' (~'`' | '``')* '`'
| '[' ~']'* ']'
| [A-Z_] [A-Z_0-9]* // Ordinary identifiers
; // TODO check: needs more chars in set

NUMERIC_LITERAL: ((DIGIT+ ('.' DIGIT*)?) | ('.' DIGIT+)) ('E' [-+]? DIGIT+)? | '0x' HEX_DIGIT+;

BIND_PARAMETER: [@$] IDENTIFIER;

STRING_LITERAL: '\'' ( ~'\'' | '\'\'')* '\'';

SINGLE_LINE_COMMENT: '--' ~[\r\n]* (('\r'? '\n') | EOF) -> channel(HIDDEN);

MULTILINE_COMMENT: '/*' .*? '*/' -> channel(HIDDEN);

SPACES: [ \u000B\t\r\n] -> channel(HIDDEN);

UNEXPECTED_CHAR: .;

fragment HEX_DIGIT: [0-9A-F];
fragment DIGIT: [0-9];
28 changes: 6 additions & 22 deletions SQLParser.g4
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,11 @@ Type cast can only be applied to:
function_call
*/
expr:
literal type_cast? #literal_expr
TEXT_LITERAL type_cast? #text_literal_expr
| BOOLEAN_LITERAL type_cast? #boolean_literal_expr
| NUMERIC_LITERAL type_cast? #numeric_literal_expr
| NULL_LITERAL type_cast? #null_literal_expr
| BLOB_LITERAL type_cast? #blob_literal_expr
| variable type_cast? #variable_expr
| column_ref type_cast? #column_expr
| <assoc=right> operator=(MINUS | PLUS) expr #unary_expr
Expand All @@ -168,7 +172,7 @@ expr:
// comparison
| left=expr comparisonOperator right=expr #comparison_expr
//| left=expr comparisonOperator right=subquery #scalar_subquery_expr
| expr IS_ NOT_? (DISTINCT_ FROM_ expr | boolean_value | NULL_) #is_expr
| expr IS_ NOT_? ((DISTINCT_ FROM_ expr)|BOOLEAN_LITERAL|NULL_LITERAL)#is_expr
| expr (ISNULL_ | NOTNULL_) #null_expr
// logical expressions
| <assoc=right> NOT_ expr #logical_not_expr
Expand Down Expand Up @@ -196,26 +200,6 @@ type_cast:
TYPE_CAST cast_type
;

boolean_value:
TRUE_
| FALSE_
;

string_value:
STRING_LITERAL
;

numeric_value:
NUMERIC_LITERAL
;

literal:
NULL_
| boolean_value
| string_value
| numeric_value
;

value_row:
OPEN_PAR expr (COMMA expr)* CLOSE_PAR
;
Expand Down

0 comments on commit a055a15

Please sign in to comment.