Skip to content

Commit

Permalink
Merge pull request #213 from amaanq/update-c
Browse files Browse the repository at this point in the history
Update c
  • Loading branch information
amaanq authored Jul 18, 2023
2 parents 0e7b7a0 + 0e36081 commit 8dc2b30
Show file tree
Hide file tree
Showing 12 changed files with 428,251 additions and 323,787 deletions.
103 changes: 103 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
name: Release

on:
workflow_run:
workflows: ["CI"]
branches:
- master
types:
- completed

jobs:
release:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3
with:
fetch-depth: 0

- name: Get previous commit SHA
id: get_previous_commit
run: |
LATEST_TAG=$(git describe --tags --abbrev=0)
if [[ -z "$LATEST_TAG" ]]; then
echo "No tag found. Failing..."
exit 1
fi
echo "latest_tag=${LATEST_TAG#v}" >> "$GITHUB_ENV" # Remove 'v' prefix from the tag
- name: Check if version changed and is greater than the previous
id: version_check
run: |
# Compare the current version with the version from the previous commit
PREVIOUS_NPM_VERSION=${{ env.latest_tag }}
CURRENT_NPM_VERSION=$(jq -r '.version' package.json)
CURRENT_CARGO_VERSION=$(awk -F '"' '/^version/ {print $2}' Cargo.toml)
if [[ "$CURRENT_NPM_VERSION" != "$CURRENT_CARGO_VERSION" ]]; then # Cargo.toml and package.json versions must match
echo "Mismatch: NPM version ($CURRENT_NPM_VERSION) and Cargo.toml version ($CURRENT_CARGO_VERSION)"
echo "version_changed=false" >> "$GITHUB_ENV"
else
if [[ "$PREVIOUS_NPM_VERSION" == "$CURRENT_NPM_VERSION" ]]; then
echo "version_changed=" >> "$GITHUB_ENV"
else
IFS='.' read -ra PREVIOUS_VERSION_PARTS <<< "$PREVIOUS_NPM_VERSION"
IFS='.' read -ra CURRENT_VERSION_PARTS <<< "$CURRENT_NPM_VERSION"
VERSION_CHANGED=false
for i in "${!PREVIOUS_VERSION_PARTS[@]}"; do
if [[ ${CURRENT_VERSION_PARTS[i]} -gt ${PREVIOUS_VERSION_PARTS[i]} ]]; then
VERSION_CHANGED=true
break
elif [[ ${CURRENT_VERSION_PARTS[i]} -lt ${PREVIOUS_VERSION_PARTS[i]} ]]; then
break
fi
done
echo "version_changed=$VERSION_CHANGED" >> "$GITHUB_ENV"
echo "current_version=${CURRENT_NPM_VERSION}" >> "$GITHUB_ENV"
fi
fi
- name: Display result
run: |
echo "Version bump detected: ${{ env.version_changed }}"
- name: Fail if version is lower
if: env.version_changed == 'false'
run: exit 1

- name: Setup Node
if: env.version_changed == 'true'
uses: actions/setup-node@v3
with:
node-version: 18
registry-url: "https://registry.npmjs.org"
- name: Publish to NPM
if: env.version_changed == 'true'
env:
NODE_AUTH_TOKEN: ${{secrets.NPM_TOKEN}}
run: npm publish

- name: Setup Rust
if: env.version_changed == 'true'
uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: stable
override: true
- name: Publish to Crates.io
if: env.version_changed == 'true'
uses: katyo/publish-crates@v2
with:
registry-token: ${{ secrets.CARGO_REGISTRY_TOKEN }}

- name: Tag versions
if: env.version_changed == 'true'
run: |
git checkout master
git config user.name github-actions[bot]
git config user.email github-actions[bot]@users.noreply.github.com
git tag -d "v${{ env.current_version }}" || true
git push origin --delete "v${{ env.current_version }}" || true
git tag -a "v${{ env.current_version }}" -m "Version ${{ env.current_version }}"
git push origin "v${{ env.current_version }}"
33 changes: 0 additions & 33 deletions .github/workflows/publish_crate.yml

This file was deleted.

53 changes: 49 additions & 4 deletions grammar.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,15 +44,19 @@ module.exports = grammar(C, {
conflicts: ($, original) => original.concat([
[$.template_function, $.template_type],
[$.template_function, $.template_type, $._expression],
[$.template_function, $.template_type, $._expression_not_binary],
[$.template_function, $.template_type, $.qualified_identifier],
[$.template_method, $.field_expression],
[$.template_type, $.qualified_type_identifier],
[$.qualified_type_identifier, $.qualified_identifier],
[$.dependent_type_identifier, $.dependent_identifier],
[$.comma_expression, $.initializer_list],
[$._expression, $._declarator],
[$._expression_not_binary, $._declarator],
[$._expression, $.structured_binding_declarator],
[$._expression_not_binary, $.structured_binding_declarator],
[$._expression, $._declarator, $._type_specifier],
[$._expression_not_binary, $._declarator, $._type_specifier],
[$.parameter_list, $.argument_list],
[$._type_specifier, $.call_expression],
[$._declaration_specifiers, $._constructor_specifiers],
Expand All @@ -62,6 +66,7 @@ module.exports = grammar(C, {
[$._binary_fold_operator, $._fold_operator],
[$.expression_statement, $.for_statement],
[$.init_statement, $.for_statement],
[$._typedef_type_specifier, $.sized_type_specifier],
]),

inline: ($, original) => original.concat([
Expand All @@ -84,6 +89,21 @@ module.exports = grammar(C, {
alias($.operator_cast_declaration, $.declaration),
),

_block_item: ($, original) => choice(
original,
$.namespace_definition,
$.concept_definition,
$.namespace_alias_definition,
$.using_declaration,
$.alias_declaration,
$.static_assert_declaration,
$.template_declaration,
$.template_instantiation,
alias($.constructor_or_destructor_definition, $.function_definition),
alias($.operator_cast_definition, $.function_definition),
alias($.operator_cast_declaration, $.declaration),
),

// Types

placeholder_type_specifier: $ => prec(1, seq(
Expand Down Expand Up @@ -125,7 +145,6 @@ module.exports = grammar(C, {
type_qualifier: (_, original) => choice(
original,
'mutable',
'constexpr',
'constinit',
'consteval',
),
Expand Down Expand Up @@ -249,6 +268,25 @@ module.exports = grammar(C, {

// Declarations

_typedef_type_specifier: $ => choice(
$.macro_type_specifier,
alias($._typedef_sized_type_specifier, $.sized_type_specifier),
$.struct_specifier,
$.union_specifier,
$.enum_specifier,
$.class_specifier,
$.sized_type_specifier,
$.primitive_type,
$.template_type,
$.dependent_type,
$.placeholder_type_specifier,
$.decltype,
prec.right(choice(
alias($.qualified_type_identifier, $.qualified_identifier),
$._type_identifier,
)),
),

template_declaration: $ => seq(
'template',
field('parameters', $.template_parameter_list),
Expand Down Expand Up @@ -694,6 +732,15 @@ module.exports = grammar(C, {

// Statements

_top_level_statement: ($, original) => choice(
original,
$.co_return_statement,
$.co_yield_statement,
$.for_range_loop,
$.try_statement,
$.throw_statement,
),

_non_case_statement: ($, original) => choice(
original,
$.co_return_statement,
Expand Down Expand Up @@ -810,7 +857,7 @@ module.exports = grammar(C, {

// Expressions

_expression: ($, original) => choice(
_expression_not_binary: ($, original) => choice(
original,
$.co_await_expression,
$.requires_expression,
Expand All @@ -821,7 +868,6 @@ module.exports = grammar(C, {
$.delete_expression,
$.lambda_expression,
$.parameter_pack_expansion,
$.nullptr,
$.this,
$.raw_string_literal,
$.user_defined_literal,
Expand Down Expand Up @@ -1191,7 +1237,6 @@ module.exports = grammar(C, {
)),

this: _ => 'this',
nullptr: _ => 'nullptr',

concatenated_string: $ => seq(
choice($.raw_string_literal, $.string_literal),
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
"devDependencies": {
"eslint": "^8.43.0",
"eslint-config-google": "^0.14.0",
"tree-sitter-c": "^0.20.2",
"tree-sitter-cli": "^0.20.0"
"tree-sitter-c": "^0.20.3",
"tree-sitter-cli": "^0.20.8"
},
"scripts": {
"build": "tree-sitter generate && node-gyp build",
Expand Down
2 changes: 1 addition & 1 deletion queries/highlights.scm
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
; Constants

(this) @variable.builtin
(nullptr) @constant
(null "nullptr" @constant)

; Keywords

Expand Down
Loading

0 comments on commit 8dc2b30

Please sign in to comment.