Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for misc features #161

Merged
merged 9 commits into from
Aug 9, 2023
Merged
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
4 changes: 4 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
/src/** linguist-vendored
/examples/* linguist-vendored

src/grammar.json linguist-generated
src/node-types.json linguist-generated
src/parser.c linguist-generated

src/grammar.json -diff
src/node-types.json -diff
src/parser.c -diff
5 changes: 0 additions & 5 deletions .travis.yml

This file was deleted.

3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# tree-sitter-c

[![Build Status](https://travis-ci.org/tree-sitter/tree-sitter-c.svg?branch=master)](https://travis-ci.org/tree-sitter/tree-sitter-c)
[![Build status](https://ci.appveyor.com/api/projects/status/7u0sy6ajmxro4wfh/branch/master?svg=true)](https://ci.appveyor.com/project/maxbrunsfeld/tree-sitter-c/branch/master)
[![CI](https://github.com/tree-sitter/tree-sitter-c/actions/workflows/ci.yml/badge.svg)](https://github.com/tree-sitter/tree-sitter-c/actions/workflows/ci.yml)

C grammar for [tree-sitter](https://github.com/tree-sitter/tree-sitter).
Adapted from [this C99 grammar](http://slps.github.io/zoo/c/iso-9899-tc3.html).
20 changes: 17 additions & 3 deletions grammar.js
Original file line number Diff line number Diff line change
Expand Up @@ -237,11 +237,13 @@ module.exports = grammar({
),

type_definition: $ => seq(
optional('__extension__'),
'typedef',
repeat($.type_qualifier),
field('type', $._type_specifier),
repeat($.type_qualifier),
commaSep1(field('declarator', $._type_declarator)),
repeat($.attribute_specifier),
';',
),

Expand Down Expand Up @@ -427,10 +429,11 @@ module.exports = grammar({
field('declarator', optional($._abstract_declarator)),
))),

function_declarator: $ => prec(1,
function_declarator: $ => prec.right(1,
seq(
field('declarator', $._declarator),
field('parameters', $.parameter_list),
optional($.gnu_asm_expression),
repeat($.attribute_specifier),
)),
function_field_declarator: $ => prec(1, seq(
Expand Down Expand Up @@ -493,6 +496,9 @@ module.exports = grammar({
'auto',
'register',
'inline',
'__inline',
'__inline__',
'__forceinline',
'thread_local',
'__thread',
),
Expand All @@ -503,6 +509,7 @@ module.exports = grammar({
'volatile',
'restrict',
'__restrict__',
'__extension__',
'_Atomic',
'_Noreturn',
'noreturn',
Expand Down Expand Up @@ -803,6 +810,7 @@ module.exports = grammar({
$.cast_expression,
$.pointer_expression,
$.sizeof_expression,
$.alignof_expression,
$.offsetof_expression,
$.generic_expression,
$.subscript_expression,
Expand Down Expand Up @@ -935,6 +943,11 @@ module.exports = grammar({
),
)),

alignof_expression: $ => prec(PREC.SIZEOF, seq(
choice('__alignof__', '__alignof', '_alignof', 'alignof', '_Alignof'),
seq('(', field('type', $.type_descriptor), ')'),
)),

offsetof_expression: $ => prec(PREC.OFFSETOF, seq(
'offsetof',
seq('(', field('type', $.type_descriptor), ',', field('member', $._field_identifier), ')'),
Expand Down Expand Up @@ -1030,7 +1043,7 @@ module.exports = grammar({
),

// The compound_statement is added to parse macros taking statements as arguments, e.g. MYFORLOOP(1, 10, i, { foo(i); bar(i); })
argument_list: $ => seq('(', commaSep(choice($._expression, $.compound_statement)), ')'),
argument_list: $ => seq('(', commaSep(choice(seq(optional('__extension__'), $._expression), $.compound_statement)), ')'),

field_expression: $ => seq(
prec(PREC.FIELD, seq(
Expand Down Expand Up @@ -1115,8 +1128,9 @@ module.exports = grammar({
),

concatenated_string: $ => seq(
choice($.identifier, $.string_literal),
$.string_literal,
repeat1(choice($.string_literal, $.identifier)), // Identifier is added to parse macros that are strings, like PRIu64
repeat(choice($.string_literal, $.identifier)), // Identifier is added to parse macros that are strings, like PRIu64
),

string_literal: $ => seq(
Expand Down
165 changes: 159 additions & 6 deletions src/grammar.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading