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
22 changes: 22 additions & 0 deletions appveyor.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
image: Visual Studio 2015

environment:
nodejs_version: "8"

platform:
- x64

install:
- ps: Install-Product node $env:nodejs_version
- node --version
- npm --version
- npm install

test_script:
- npm run test-windows

build: off

branches:
only:
- master
79 changes: 53 additions & 26 deletions grammar.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,48 @@ const PREC = {
SUBSCRIPT: 16
};

const SIZE_QUALIFIERS = [
'signed',
'unsigned',
'long',
'short'
]

const TYPE_QUALIFIERS = [
'const',
'restrict',
'volatile',
'restrict',
'_Atomic'
]

const STORAGE_CLASS_SPECIFIERS = [
'extern',
'static' ,
'auto',
'register',
'inline'
]

const KEYWORDS = [
'break',
'case',
'continue',
'do',
'enum',
'for',
'if',
'return',
'struct',
'switch',
'typedef',
'union',
'while',
...STORAGE_CLASS_SPECIFIERS,
...TYPE_QUALIFIERS,
...SIZE_QUALIFIERS
]

module.exports = grammar({
name: 'c',

Expand All @@ -32,6 +74,7 @@ module.exports = grammar({
inline: $ => [
$._statement,
$._top_level_item,
$._identifier,
$._type_identifier,
$._field_identifier,
$._statement_identifier,
Expand Down Expand Up @@ -162,7 +205,7 @@ module.exports = grammar({
$.function_declarator,
$.array_declarator,
prec.dynamic(PREC.PAREN_DECLARATOR, seq('(', $._declarator, ')')),
$.identifier
$._identifier
),

_field_declarator: $ => choice(
Expand Down Expand Up @@ -239,21 +282,9 @@ module.exports = grammar({
'}'
),

storage_class_specifier: $ => choice(
'extern',
'static' ,
'auto',
'register',
'inline'
),
storage_class_specifier: $ => choice(...STORAGE_CLASS_SPECIFIERS),

type_qualifier: $ => choice(
'const',
'restrict',
'volatile',
'restrict',
'_Atomic'
),
type_qualifier: $ => choice(...TYPE_QUALIFIERS),

_type_specifier: $ => choice(
$.struct_specifier,
Expand All @@ -266,12 +297,7 @@ module.exports = grammar({
),

sized_type_specifier: $ => seq(
repeat1(choice(
'signed',
'unsigned',
'long',
'short'
)),
repeat1(choice(...SIZE_QUALIFIERS)),
optional(choice(
prec.dynamic(-1, $._type_identifier),
$.primitive_type
Expand Down Expand Up @@ -357,7 +383,7 @@ module.exports = grammar({
bitfield_clause: $ => seq(':', $._expression),

enumerator: $ => seq(
$.identifier,
$._identifier,
optional(seq('=', $._expression))
),

Expand Down Expand Up @@ -502,7 +528,7 @@ module.exports = grammar({
$.call_expression,
$.field_expression,
$.compound_literal_expression,
$.identifier,
$._identifier,
$.number_literal,
$.string_literal,
$.true,
Expand Down Expand Up @@ -714,9 +740,10 @@ module.exports = grammar({

identifier: $ => /[a-zA-Z_]\w*/,

_type_identifier: $ => alias($.identifier, $.type_identifier),
_field_identifier: $ => alias($.identifier, $.field_identifier),
_statement_identifier: $ => alias($.identifier, $.statement_identifier),
_identifier: $ => $.identifier.exclude($.primitive_type, ...KEYWORDS),
_type_identifier: $ => alias($._identifier, $.type_identifier),
_field_identifier: $ => alias($._identifier, $.field_identifier),
_statement_identifier: $ => alias($._identifier, $.statement_identifier),

_empty_declaration: $ => seq(
$._declaration_specifiers,
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,6 @@
},
"scripts": {
"build": "tree-sitter generate && node-gyp build",
"test": "tree-sitter test && tree-sitter parse examples/* --quiet --time"
"test": "tree-sitter test && tree-sitter parse examples --quiet --time"
}
}
Loading