Skip to content

Commit

Permalink
Distinguish line continuation that can occur anywhere (in 'extras') from
Browse files Browse the repository at this point in the history
line continuation in shell command rule so as to know which is which
when recovering a typed tree with ocaml-tree-sitter.
See semgrep/ocaml-tree-sitter-core#20
  • Loading branch information
mjambon committed Dec 16, 2021
1 parent f0b8e67 commit e0fa91d
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 20 deletions.
6 changes: 5 additions & 1 deletion grammar.js
Original file line number Diff line number Diff line change
Expand Up @@ -248,13 +248,17 @@ module.exports = grammar({
seq(
$.shell_fragment,
repeat(
seq($.line_continuation, repeat($._comment_line), $.shell_fragment)
seq(
alias($.required_line_continuation, $.line_continuation),
repeat($._comment_line), $.shell_fragment
)
)
),

shell_fragment: ($) => repeat1(choice(/[^\\\[\n#\s][^\\\n]*/, /\\[^\n]/)),

line_continuation: ($) => "\\\n",
required_line_continuation: ($) => "\\\n",

_comment_line: ($) => seq(alias($._anon_comment, $.comment), "\n"),

Expand Down
34 changes: 17 additions & 17 deletions src/parser.c
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ enum {
aux_sym_unquoted_string_repeat1 = 123,
};

static const char *ts_symbol_names[] = {
static const char * const ts_symbol_names[] = {
[ts_builtin_sym_end] = "end",
[anon_sym_LF] = "\n",
[aux_sym_from_instruction_token1] = "FROM",
Expand Down Expand Up @@ -269,7 +269,7 @@ static const char *ts_symbol_names[] = {
[aux_sym_unquoted_string_repeat1] = "unquoted_string_repeat1",
};

static TSSymbol ts_symbol_map[] = {
static const TSSymbol ts_symbol_map[] = {
[ts_builtin_sym_end] = ts_builtin_sym_end,
[anon_sym_LF] = anon_sym_LF,
[aux_sym_from_instruction_token1] = aux_sym_from_instruction_token1,
Expand Down Expand Up @@ -907,7 +907,7 @@ enum {
field_value = 9,
};

static const char *ts_field_names[] = {
static const char * const ts_field_names[] = {
[0] = NULL,
[field_as] = "as",
[field_default] = "default",
Expand Down Expand Up @@ -978,7 +978,7 @@ static const TSFieldMapEntry ts_field_map_entries[] = {
{field_as, 4},
};

static TSSymbol ts_alias_sequences[PRODUCTION_ID_COUNT][MAX_ALIAS_SEQUENCE_LENGTH] = {
static const TSSymbol ts_alias_sequences[PRODUCTION_ID_COUNT][MAX_ALIAS_SEQUENCE_LENGTH] = {
[0] = {0},
[3] = {
[1] = sym_unquoted_string,
Expand All @@ -989,7 +989,7 @@ static TSSymbol ts_alias_sequences[PRODUCTION_ID_COUNT][MAX_ALIAS_SEQUENCE_LENGT
},
};

static uint16_t ts_non_terminal_alias_map[] = {
static const uint16_t ts_non_terminal_alias_map[] = {
aux_sym__user_name_or_group, 2,
aux_sym__user_name_or_group,
sym_unquoted_string,
Expand Down Expand Up @@ -2563,7 +2563,7 @@ static bool ts_lex(TSLexer *lexer, TSStateId state) {
}
}

static TSLexMode ts_lex_modes[STATE_COUNT] = {
static const TSLexMode ts_lex_modes[STATE_COUNT] = {
[0] = {.lex_state = 0},
[1] = {.lex_state = 158},
[2] = {.lex_state = 158},
Expand Down Expand Up @@ -2794,7 +2794,7 @@ static TSLexMode ts_lex_modes[STATE_COUNT] = {
[227] = {.lex_state = 50},
};

static uint16_t ts_parse_table[LARGE_STATE_COUNT][SYMBOL_COUNT] = {
static const uint16_t ts_parse_table[LARGE_STATE_COUNT][SYMBOL_COUNT] = {
[0] = {
[ts_builtin_sym_end] = ACTIONS(1),
[anon_sym_COLON] = ACTIONS(1),
Expand Down Expand Up @@ -2861,7 +2861,7 @@ static uint16_t ts_parse_table[LARGE_STATE_COUNT][SYMBOL_COUNT] = {
},
};

static uint16_t ts_small_parse_table[] = {
static const uint16_t ts_small_parse_table[] = {
[0] = 24,
ACTIONS(3), 1,
sym_line_continuation,
Expand Down Expand Up @@ -5039,7 +5039,7 @@ static uint16_t ts_small_parse_table[] = {
aux_sym_param_token1,
};

static uint32_t ts_small_parse_table_map[] = {
static const uint32_t ts_small_parse_table_map[] = {
[SMALL_STATE(2)] = 0,
[SMALL_STATE(3)] = 92,
[SMALL_STATE(4)] = 184,
Expand Down Expand Up @@ -5268,7 +5268,7 @@ static uint32_t ts_small_parse_table_map[] = {
[SMALL_STATE(227)] = 3025,
};

static TSParseActionEntry ts_parse_actions[] = {
static const TSParseActionEntry ts_parse_actions[] = {
[0] = {.entry = {.count = 0, .reusable = false}},
[1] = {.entry = {.count = 1, .reusable = false}}, RECOVER(),
[3] = {.entry = {.count = 1, .reusable = true}}, SHIFT_EXTRA(),
Expand Down Expand Up @@ -5632,7 +5632,7 @@ extern "C" {
#endif

extern const TSLanguage *tree_sitter_dockerfile(void) {
static TSLanguage language = {
static const TSLanguage language = {
.version = LANGUAGE_VERSION,
.symbol_count = SYMBOL_COUNT,
.alias_count = ALIAS_COUNT,
Expand All @@ -5643,18 +5643,18 @@ extern const TSLanguage *tree_sitter_dockerfile(void) {
.production_id_count = PRODUCTION_ID_COUNT,
.field_count = FIELD_COUNT,
.max_alias_sequence_length = MAX_ALIAS_SEQUENCE_LENGTH,
.parse_table = (const uint16_t *)ts_parse_table,
.small_parse_table = (const uint16_t *)ts_small_parse_table,
.small_parse_table_map = (const uint32_t *)ts_small_parse_table_map,
.parse_table = &ts_parse_table[0][0],
.small_parse_table = ts_small_parse_table,
.small_parse_table_map = ts_small_parse_table_map,
.parse_actions = ts_parse_actions,
.symbol_names = ts_symbol_names,
.field_names = ts_field_names,
.field_map_slices = (const TSFieldMapSlice *)ts_field_map_slices,
.field_map_entries = (const TSFieldMapEntry *)ts_field_map_entries,
.field_map_slices = ts_field_map_slices,
.field_map_entries = ts_field_map_entries,
.symbol_metadata = ts_symbol_metadata,
.public_symbol_map = ts_symbol_map,
.alias_map = ts_non_terminal_alias_map,
.alias_sequences = (const TSSymbol *)ts_alias_sequences,
.alias_sequences = &ts_alias_sequences[0][0],
.lex_modes = ts_lex_modes,
.lex_fn = ts_lex,
};
Expand Down
4 changes: 2 additions & 2 deletions src/tree_sitter/parser.h
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,8 @@ struct TSLanguage {
const uint16_t *small_parse_table;
const uint32_t *small_parse_table_map;
const TSParseActionEntry *parse_actions;
const char **symbol_names;
const char **field_names;
const char * const *symbol_names;
const char * const *field_names;
const TSFieldMapSlice *field_map_slices;
const TSFieldMapEntry *field_map_entries;
const TSSymbolMetadata *symbol_metadata;
Expand Down

0 comments on commit e0fa91d

Please sign in to comment.