Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions src/scanner.c
Original file line number Diff line number Diff line change
Expand Up @@ -170,19 +170,21 @@ unsigned tree_sitter_sql_external_scanner_serialize(void *payload, char *buffer)
}

memcpy(buffer, state->start_tag, tag_length);
if (state->start_tag != NULL) {
free(state->start_tag);
state->start_tag = NULL;
}
return tag_length;
}

void tree_sitter_sql_external_scanner_deserialize(void *payload, const char *buffer, unsigned length) {
LexerState *state = (LexerState *)payload;
state->start_tag = NULL;
if (state->start_tag != NULL) {
free(state->start_tag);
state->start_tag = NULL;
}
// A length of 1 can't exists.
if (length > 1) {
state->start_tag = malloc(length);
if (state->start_tag == NULL) {
return;
}
memcpy(state->start_tag, buffer, length);
}
}
61 changes: 61 additions & 0 deletions test/corpus/procedures.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,67 @@ $$;

--------------------------------------------------------------------------------

(program
(statement
(create_procedure
(keyword_create)
(keyword_procedure)
(object_reference
name: (identifier))
(function_arguments
(function_argument
(identifier)
(int
(keyword_int)))
(function_argument
(identifier)
(int
(keyword_int))))
(function_language
(keyword_language)
(identifier))
(procedure_body
(keyword_as)
(dollar_quote)
(keyword_begin)
(statement
(insert
(keyword_insert)
(keyword_into)
(object_reference
name: (identifier))
(keyword_values)
(list
(field
name: (identifier)))))
(statement
(insert
(keyword_insert)
(keyword_into)
(object_reference
name: (identifier))
(keyword_values)
(list
(field
name: (identifier)))))
(keyword_end)
(dollar_quote)))))

================================================================================
Procedure with named tag dollar-quote (PostgreSQL)
================================================================================

CREATE PROCEDURE insert_data(a integer, b integer)
LANGUAGE SQL
AS $body$
BEGIN
INSERT INTO tbl VALUES (a);
INSERT INTO tbl VALUES (b);
END;
$body$;

--------------------------------------------------------------------------------

(program
(statement
(create_procedure
Expand Down
Loading