Use tree-sitter-objc from crates.io

pull/795/head
Wilfred Hughes 2024-12-19 23:00:43 +07:00
parent 913aee1c07
commit 919f15344f
46 changed files with 20 additions and 1065672 deletions

@ -10,7 +10,8 @@ with YAML.
Improved language detection when one argument is a named pipe.
Updated to the latest tree-sitter parser for Haskell, Ruby and Scala.
Updated to the latest tree-sitter parser for Haskell, Objective-C,
Ruby and Scala.
### Syntax Highlighting

15
Cargo.lock generated

@ -91,9 +91,9 @@ checksum = "7f30e7476521f6f8af1a1c4c0b8cc94f0bee37d91763d0ca2665f299b6cd8aec"
[[package]]
name = "cc"
version = "1.1.30"
version = "1.2.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b16803a61b81d9eabb7eae2588776c4c1e584b738ede45fdbb4c972cec1e9945"
checksum = "c31a0499c1dc64f458ad13872de75c0eb7e3fdb0e67964610c914b034fc5956e"
dependencies = [
"shlex",
]
@ -251,6 +251,7 @@ dependencies = [
"tree-sitter",
"tree-sitter-haskell",
"tree-sitter-language",
"tree-sitter-objc",
"tree-sitter-ruby",
"tree-sitter-scala",
"tree_magic_mini",
@ -1020,6 +1021,16 @@ version = "0.1.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c199356c799a8945965bb5f2c55b2ad9d9aa7c4b4f6e587fe9dea0bc715e5f9c"
[[package]]
name = "tree-sitter-objc"
version = "3.0.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9ca8bb556423fc176f0535e79d525f783a6684d3c9da81bf9d905303c129e1d2"
dependencies = [
"cc",
"tree-sitter-language",
]
[[package]]
name = "tree-sitter-ruby"
version = "0.23.1"

@ -81,6 +81,7 @@ streaming-iterator = "0.1.9"
tree-sitter-haskell = "0.23.1"
tree-sitter-ruby = "0.23.1"
tree-sitter-scala = "0.23.3"
tree-sitter-objc = "3.0.2"
[dev-dependencies]
# assert_cmd 2.0.10 requires predicates 3.

@ -243,11 +243,6 @@ fn main() {
src_dir: "vendored_parsers/tree-sitter-nix-src",
extra_files: vec!["scanner.c"],
},
TreeSitterParser {
name: "tree-sitter-objc",
src_dir: "vendored_parsers/tree-sitter-objc-src",
extra_files: vec![],
},
TreeSitterParser {
name: "tree-sitter-ocaml",
src_dir: "vendored_parsers/tree-sitter-ocaml-src/ocaml/src",

@ -96,7 +96,6 @@ extern "C" {
fn tree_sitter_make() -> ts::Language;
fn tree_sitter_newick() -> ts::Language;
fn tree_sitter_nix() -> ts::Language;
fn tree_sitter_objc() -> ts::Language;
fn tree_sitter_ocaml() -> ts::Language;
fn tree_sitter_ocaml_interface() -> ts::Language;
fn tree_sitter_pascal() -> ts::Language;
@ -776,7 +775,8 @@ pub(crate) fn from_language(language: guess::Language) -> TreeSitterConfig {
}
}
ObjC => {
let language = unsafe { tree_sitter_objc() };
let language_fn = tree_sitter_objc::LANGUAGE;
let language = tree_sitter::Language::new(language_fn);
TreeSitterConfig {
language: language.clone(),
atom_nodes: vec!["string_literal"].into_iter().collect(),
@ -788,10 +788,7 @@ pub(crate) fn from_language(language: guess::Language) -> TreeSitterConfig {
("@{", "}"),
("@[", "]"),
],
highlight_query: ts::Query::new(
&language,
include_str!("../../vendored_parsers/highlights/objc.scm"),
)
highlight_query: ts::Query::new(&language, tree_sitter_objc::HIGHLIGHTS_QUERY)
.unwrap(),
sub_languages: vec![],
}

@ -1 +0,0 @@
tree-sitter-objc/src

@ -1,20 +0,0 @@
module.exports = {
'env': {
'commonjs': true,
'es2021': true,
},
'extends': 'google',
'overrides': [
],
'parserOptions': {
'ecmaVersion': 'latest',
'sourceType': 'module',
},
'rules': {
'indent': ['error', 2, {'SwitchCase': 1}],
'max-len': [
'error',
{'code': 120, 'ignoreComments': true, 'ignoreUrls': true, 'ignoreStrings': true},
],
},
};

@ -1,6 +0,0 @@
/src/** linguist-vendored
/examples/* linguist-vendored
src/grammar.json -diff
src/node-types.json -diff
src/parser.c -diff

@ -1,34 +0,0 @@
name: CI
on:
push:
branches:
- master
pull_request:
branches:
- "**"
jobs:
test:
runs-on: ${{ matrix.os }}
strategy:
fail-fast: true
matrix:
os: [macos-latest, ubuntu-latest]
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v2
with:
node-version: 16
- run: npm install
- run: npm test
test_windows:
runs-on: windows-2019
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v2
with:
node-version: 16
- run: npm install
- run: npm run-script test-windows

@ -1,19 +0,0 @@
name: Lint
on:
push:
branches:
- master
pull_request:
branches:
- "**"
jobs:
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Install modules
run: npm install
- name: Run ESLint
run: npm run lint

@ -1,82 +0,0 @@
name: Release
on:
workflow_run:
workflows: ["CI"]
types:
- completed
permissions:
contents: write
pull-requests: write
jobs:
release:
runs-on: ubuntu-latest
if: ${{ github.event.workflow_run.conclusion == 'success' && github.ref == 'refs/heads/master' }}
steps:
- uses: google-github-actions/release-please-action@v3
id: release
with:
release-type: node
package-name: tree-sitter-objc
- uses: actions/checkout@v3
with:
token: ${{ secrets.GITHUB_TOKEN }}
- name: Update Rust version
run: |
git fetch origin release-please--branches--master--components--tree-sitter-objc
git checkout release-please--branches--master--components--tree-sitter-objc
git config user.name github-actions[bot]
git config user.email github-actions[bot]@users.noreply.github.com
repo_name="${{ github.repository }}"
repo_name="${repo_name##*/}"
version=$(grep -o '"version": *"[^"]*"' package.json | sed 's/"version": "\(.*\)"/\1/')
sed -i "s/version = \"[^\"]*\"/version = \"$version\"/g" Cargo.toml
sed -i "s/$repo_name = \"[^\"]*\"/$repo_name = \"$version\"/g" bindings/rust/README.md
git add Cargo.toml bindings/rust/README.md
git commit --amend --no-edit
git push -f
- name: Setup Node
if: ${{ steps.release.outputs.release_created }}
uses: actions/setup-node@v3
with:
node-version: 18
registry-url: "https://registry.npmjs.org"
- name: Publish to NPM
if: ${{ steps.release.outputs.release_created }}
env:
NODE_AUTH_TOKEN: ${{secrets.NPM_TOKEN}}
run: npm publish
- name: Setup Rust
if: ${{ steps.release.outputs.release_created }}
uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: stable
override: true
- name: Publish to Crates.io
if: ${{ steps.release.outputs.release_created }}
uses: katyo/publish-crates@v2
with:
registry-token: ${{ secrets.CARGO_REGISTRY_TOKEN }}
- name: Tag stable versions
if: ${{ steps.release.outputs.release_created }}
run: |
git checkout master
git config user.name github-actions[bot]
git config user.email github-actions[bot]@users.noreply.github.com
git remote add gh-token "https://${{ secrets.GITHUB_TOKEN }}@github.com/google-github-actions/release-please-action.git"
git tag -d stable || true
git push origin :stable || true
git tag -a stable -m "Last Stable Release"
git push origin stable

@ -1,6 +0,0 @@
Cargo.lock
package-lock.json
/build
/node_modules
/examples/*/
/target

@ -1,5 +0,0 @@
/test
/examples
/build
/script
/target

@ -1,43 +0,0 @@
# Changelog
## [2.1.0](https://github.com/amaanq/tree-sitter-objc/compare/v2.0.0...v2.1.0) (2023-08-13)
### Features
* bump C to 0.20.6 ([7d5b173](https://github.com/amaanq/tree-sitter-objc/commit/7d5b1733b9006b7d4388f097745c8e10e0c30a2a))
## [2.0.0](https://github.com/amaanq/tree-sitter-objc/compare/v1.2.0...v2.0.0) (2023-08-10)
### ⚠ BREAKING CHANGES
* update tree-sitter-c to 0.20.5
### Features
* update tree-sitter-c to 0.20.5 ([e198f35](https://github.com/amaanq/tree-sitter-objc/commit/e198f3579a95e81a0c83d080572a32c787c08afc))
## [1.2.0](https://github.com/amaanq/tree-sitter-objc/compare/v1.1.0...v1.2.0) (2023-07-18)
### Features
* catch/finally statements -> clause for objc++ ([60b1290](https://github.com/amaanq/tree-sitter-objc/commit/60b129046cbae347a478515906c17ab095588ef8))
* Initial working parser ([a360943](https://github.com/amaanq/tree-sitter-objc/commit/a360943e0f108b7d0935924a4eb772ce1a6aaec7))
* support preproc calls in interface/implementation blocks, add `nullable` to type_qualifier ([7151895](https://github.com/amaanq/tree-sitter-objc/commit/7151895deea69a29a2f76964ddb2de04962412e9))
## [1.1.0](https://github.com/amaanq/tree-sitter-objc/compare/v1.0.0...v1.1.0) (2023-07-11)
### Features
* catch/finally statements -> clause for objc++ ([60b1290](https://github.com/amaanq/tree-sitter-objc/commit/60b129046cbae347a478515906c17ab095588ef8))
* support preproc calls in interface/implementation blocks, add `nullable` to type_qualifier ([7151895](https://github.com/amaanq/tree-sitter-objc/commit/7151895deea69a29a2f76964ddb2de04962412e9))
## 1.0.0 (2023-05-19)
### Features
* Initial working parser ([a360943](https://github.com/amaanq/tree-sitter-objc/commit/a360943e0f108b7d0935924a4eb772ce1a6aaec7))

@ -1,24 +0,0 @@
[package]
name = "tree-sitter-objc"
description = "Objective-C grammar for tree-sitter"
version = "2.1.0"
authors = ["Amaan Qureshi <amaanq12@gmail.com>"]
license = "MIT"
readme = "bindings/rust/README.md"
keywords = ["tree-sitter", "incremental", "parsing", "objc"]
categories = ["parsing", "text-editors"]
repository = "https://github.com/amaanq/tree-sitter-objc"
edition = "2021"
autoexamples = false
build = "bindings/rust/build.rs"
include = ["bindings/rust/*", "grammar.js", "queries/*", "src/*"]
[lib]
path = "bindings/rust/lib.rs"
[dependencies]
tree-sitter = "~0.20.10"
[build-dependencies]
cc = "1.0"

@ -1,21 +0,0 @@
The MIT License (MIT)
Copyright (c) 2023 Amaan Qureshi <amaanq12@gmail.com>
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

@ -1,37 +0,0 @@
// swift-tools-version:5.3
import PackageDescription
let package = Package(
name: "TreeSitterObjc",
platforms: [.macOS(.v10_13), .iOS(.v11)],
products: [
.library(name: "TreeSitterObjc", targets: ["TreeSitterObjc"]),
],
dependencies: [],
targets: [
.target(name: "TreeSitterObjc",
path: ".",
exclude: [
"binding.gyp",
"bindings",
"Cargo.toml",
"test",
"examples",
"grammar.js",
"LICENSE",
"package.json",
"README.md",
"script",
"src/grammar.json",
"src/node-types.json",
],
sources: [
"src/parser.c",
],
resources: [
.copy("queries")
],
publicHeadersPath: "bindings/swift",
cSettings: [.headerSearchPath("src")])
]
)

@ -1,7 +0,0 @@
# tree-sitter-objc
[![Build Status](https://github.com/amaanq/tree-sitter-objc/actions/workflows/ci.yml/badge.svg)](https://github.com/amaanq/tree-sitter-objc/actions/workflows/ci.yml)
[![Discord](https://img.shields.io/discord/1063097320771698699?logo=discord)](https://discord.gg/w7nTvsVJhm)
[Objective C](https://developer.apple.com/library/archive/documentation/Cocoa/Conceptual/ObjectiveC/Introduction/introObjectiveC.html)
grammar for [tree-sitter](https://tree-sitter.github.io)

@ -1,18 +0,0 @@
{
"targets": [
{
"target_name": "tree_sitter_objc_binding",
"include_dirs": [
"<!(node -e \"require('nan')\")",
"src"
],
"sources": [
"src/parser.c",
"bindings/node/binding.cc"
],
"cflags_c": [
"-std=c99",
]
}
]
}

@ -1,30 +0,0 @@
#include "nan.h"
#include "tree_sitter/parser.h"
#include <node.h>
using namespace v8;
extern "C" TSLanguage *tree_sitter_objc();
namespace {
NAN_METHOD(New) {}
void Init(Local<Object> exports, Local<Object> module) {
Local<FunctionTemplate> tpl = Nan::New<FunctionTemplate>(New);
tpl->SetClassName(Nan::New("Language").ToLocalChecked());
tpl->InstanceTemplate()->SetInternalFieldCount(1);
Local<Function> constructor = Nan::GetFunction(tpl).ToLocalChecked();
Local<Object> instance =
constructor->NewInstance(Nan::GetCurrentContext()).ToLocalChecked();
Nan::SetInternalFieldPointer(instance, 0, tree_sitter_objc());
Nan::Set(instance, Nan::New("name").ToLocalChecked(),
Nan::New("objc").ToLocalChecked());
Nan::Set(module, Nan::New("exports").ToLocalChecked(), instance);
}
NODE_MODULE(tree_sitter_objc_binding, Init)
} // namespace

@ -1,19 +0,0 @@
try {
module.exports = require("../../build/Release/tree_sitter_objc_binding");
} catch (error1) {
if (error1.code !== 'MODULE_NOT_FOUND') {
throw error1;
}
try {
module.exports = require("../../build/Debug/tree_sitter_objc_binding");
} catch (error2) {
if (error2.code !== 'MODULE_NOT_FOUND') {
throw error2;
}
throw error1
}
}
try {
module.exports.nodeTypeInfo = require("../../src/node-types.json");
} catch (_) { }

@ -1,81 +0,0 @@
# tree-sitter-objc
This crate provides an Objective-C grammar for the [tree-sitter][] parsing library. To
use this crate, add it to the `[dependencies]` section of your `Cargo.toml`
file. (Note that you will probably also need to depend on the
[`tree-sitter`][tree-sitter crate] crate to use the parsed result in any useful
way.)
```toml
[dependencies]
tree-sitter = "~0.20.10"
tree-sitter-objc = "2.1.0"
```
Typically, you will use the [language][language func] function to add this
grammar to a tree-sitter [Parser][], and then use the parser to parse some code:
```rust
let code = r#"
#import <Foundation/Foundation.h>
// Defining a class interface
@interface Person : NSObject
// Declaring properties
@property (nonatomic, strong) NSString *name;
@property (nonatomic, assign) NSInteger age;
// Declaring methods
- (instancetype)initWithName:(NSString *)name age:(NSInteger)age;
- (void)greet;
@end
@implementation Person
// Implementing the initializer
- (instancetype)initWithName:(NSString *)name age:(NSInteger)age {
self = [super init];
if (self) {
_name = name;
_age = age;
}
return self;
}
// Implementing the greet method
- (void)greet {
NSLog(@"Hello, my name is %@ and I'm %ld years old.", self.name, (long)self.age);
}
@end
int main(int argc, const char * argv[]) {
@autoreleasepool {
// Creating an instance of Person
Person *person = [[Person alloc] initWithName:@"John" age:25];
// Accessing properties
NSString *name = person.name;
NSInteger age = person.age;
// Calling a method
[person greet];
}
return 0;
}
"#;
let mut parser = Parser::new();
parser.set_language(tree_sitter_objc::language()).expect("Error loading Objective-C grammar");
let parsed = parser.parse(code, None);
```
If you have any questions, please reach out to us in the [tree-sitter
discussions] page.
[language func]: https://docs.rs/tree-sitter-objc/*/tree_sitter_objc/fn.language.html
[parser]: https://docs.rs/tree-sitter/*/tree_sitter/struct.Parser.html
[tree-sitter]: https://tree-sitter.github.io/
[tree-sitter crate]: https://crates.io/crates/tree-sitter
[tree-sitter discussions]: https://github.com/tree-sitter/tree-sitter/discussions

@ -1,15 +0,0 @@
fn main() {
let src_dir = std::path::Path::new("src");
let mut c_config = cc::Build::new();
c_config.include(src_dir);
c_config
.flag_if_supported("-Wno-unused-parameter")
.flag_if_supported("-Wno-unused-but-set-variable")
.flag_if_supported("-Wno-trigraphs");
let parser_path = src_dir.join("parser.c");
c_config.file(&parser_path);
c_config.compile("parser");
println!("cargo:rerun-if-changed={}", parser_path.to_str().unwrap());
}

@ -1,68 +0,0 @@
// ------------------------------------------------------------------------------------------------
// Copyright © 2023, Amaan Qureshi <amaanq12@gmail.com>
// See the LICENSE file in this repo for license details.
// ------------------------------------------------------------------------------------------------
//! This crate provides Objective-C language support for the [tree-sitter][] parsing library.
//!
//! Typically, you will use the [language][language func] function to add this language to a
//! tree-sitter [Parser][], and then use the parser to parse some code:
//!
//! ```
//! let code = "";
//! let mut parser = tree_sitter::Parser::new();
//! parser.set_language(tree_sitter_objc::language()).expect("Error loading Objective-C grammar");
//! let tree = parser.parse(code, None).unwrap();
//! ```
//!
//! [Language]: https://docs.rs/tree-sitter/*/tree_sitter/struct.Language.html
//! [language func]: fn.language.html
//! [Parser]: https://docs.rs/tree-sitter/*/tree_sitter/struct.Parser.html
//! [tree-sitter]: https://tree-sitter.github.io/
use tree_sitter::Language;
extern "C" {
fn tree_sitter_objc() -> Language;
}
/// Get the tree-sitter [Language][] for this grammar.
///
/// [Language]: https://docs.rs/tree-sitter/*/tree_sitter/struct.Language.html
pub fn language() -> Language {
unsafe { tree_sitter_objc() }
}
/// The source of the Rust tree-sitter grammar description.
pub const GRAMMAR: &str = include_str!("../../grammar.js");
/// The folds query for this language.
pub const FOLDS_QUERY: &str = include_str!("../../queries/folds.scm");
/// The syntax highlighting query for this language.
pub const HIGHLIGHTS_QUERY: &str = include_str!("../../queries/highlights.scm");
/// The indents query for this language.
pub const INDENTS_QUERY: &str = include_str!("../../queries/indents.scm");
/// The injection query for this language.
pub const INJECTIONS_QUERY: &str = include_str!("../../queries/injections.scm");
/// The symbol tagging query for this language.
pub const LOCALS_QUERY: &str = include_str!("../../queries/locals.scm");
/// The content of the [`node-types.json`][] file for this grammar.
///
/// [`node-types.json`]: https://tree-sitter.github.io/tree-sitter/using-parsers#static-node-types
pub const NODE_TYPES: &str = include_str!("../../src/node-types.json");
#[cfg(test)]
mod tests {
#[test]
fn test_can_load_grammar() {
let mut parser = tree_sitter::Parser::new();
parser
.set_language(super::language())
.expect("Error loading Objective-C grammar");
}
}

@ -1,16 +0,0 @@
#ifndef TREE_SITTER_OBJC_H_
#define TREE_SITTER_OBJC_H_
typedef struct TSLanguage TSLanguage;
#ifdef __cplusplus
extern "C" {
#endif
extern TSLanguage *tree_sitter_objc();
#ifdef __cplusplus
}
#endif
#endif // TREE_SITTER_OBJC_H_

File diff suppressed because it is too large Load Diff

@ -1,49 +0,0 @@
{
"name": "tree-sitter-objc",
"version": "2.1.0",
"description": "Objective-C grammar for tree-sitter",
"main": "bindings/node",
"keywords": [
"parser",
"lexer",
"objective-c",
"objc"
],
"author": "Amaan Qureshi <amaanq12@gmail.com>",
"license": "MIT",
"bugs": {
"url": "https://github.com/amaanq/tree-sitter-objc/issues"
},
"homepage": "https://github.com/amaanq/tree-sitter-objc#readme",
"dependencies": {
"nan": "^2.17.0"
},
"devDependencies": {
"eslint": "^8.47.0",
"eslint-config-google": "^0.14.0",
"tree-sitter-c": "^0.20.6",
"tree-sitter-cli": "0.20.8"
},
"repository": "https://github.com/amaanq/tree-sitter-objc",
"scripts": {
"build": "tree-sitter generate && node-gyp build",
"lint": "eslint grammar.js",
"parse": "tree-sitter parse",
"test": "tree-sitter test && script/parse-examples",
"test-windows": "tree-sitter test"
},
"tree-sitter": [
{
"scope": "source.objc",
"injection-regex": "^(objc|objectivec)$",
"file-types": [
"h",
"m",
"objc"
],
"highlights": [
"queries/highlights.scm"
]
}
]
}

@ -1,20 +0,0 @@
; inherits: c
[
(class_declaration)
(class_interface)
(class_implementation)
(protocol_declaration)
(property_declaration)
(method_declaration)
(struct_declaration)
(struct_declarator)
(try_statement)
(catch_clause)
(finally_clause)
(throw_statement)
(block_literal)
(ms_asm_block)
(dictionary_literal)
(array_literal)
] @fold

@ -1,216 +0,0 @@
; inherits: c
; Preprocs
(preproc_undef
name: (_) @constant) @preproc
; Includes
(module_import "@import" @include path: (identifier) @namespace)
((preproc_include
_ @include path: (_))
(#any-of? @include "#include" "#import"))
; Type Qualifiers
[
"@optional"
"@required"
"__covariant"
"__contravariant"
(visibility_specification)
] @type.qualifier
; Storageclasses
[
"@autoreleasepool"
"@synthesize"
"@dynamic"
"volatile"
(protocol_qualifier)
] @storageclass
; Keywords
[
"@protocol"
"@interface"
"@implementation"
"@compatibility_alias"
"@property"
"@selector"
"@defs"
"availability"
"@end"
] @keyword
(class_declaration "@" @keyword "class" @keyword) ; I hate Obj-C for allowing "@ class" :)
(method_definition ["+" "-"] @keyword.function)
(method_declaration ["+" "-"] @keyword.function)
[
"__typeof__"
"__typeof"
"typeof"
"in"
] @keyword.operator
[
"@synchronized"
"oneway"
] @keyword.coroutine
; Exceptions
[
"@try"
"__try"
"@catch"
"__catch"
"@finally"
"__finally"
"@throw"
] @exception
; Variables
((identifier) @variable.builtin
(#any-of? @variable.builtin "self" "super"))
; Functions & Methods
[
"objc_bridge_related"
"@available"
"__builtin_available"
"va_arg"
"asm"
] @function.builtin
(method_definition (identifier) @method)
(method_declaration (identifier) @method)
(method_identifier (identifier)? @method ":" @method (identifier)? @method)
(message_expression method: (identifier) @method.call)
; Constructors
((message_expression method: (identifier) @constructor)
(#eq? @constructor "init"))
; Attributes
(availability_attribute_specifier
[
"CF_FORMAT_FUNCTION" "NS_AVAILABLE" "__IOS_AVAILABLE" "NS_AVAILABLE_IOS"
"API_AVAILABLE" "API_UNAVAILABLE" "API_DEPRECATED" "NS_ENUM_AVAILABLE_IOS"
"NS_DEPRECATED_IOS" "NS_ENUM_DEPRECATED_IOS" "NS_FORMAT_FUNCTION" "DEPRECATED_MSG_ATTRIBUTE"
"__deprecated_msg" "__deprecated_enum_msg" "NS_SWIFT_NAME" "NS_SWIFT_UNAVAILABLE"
"NS_EXTENSION_UNAVAILABLE_IOS" "NS_CLASS_AVAILABLE_IOS" "NS_CLASS_DEPRECATED_IOS" "__OSX_AVAILABLE_STARTING"
"NS_ROOT_CLASS" "NS_UNAVAILABLE" "NS_REQUIRES_NIL_TERMINATION" "CF_RETURNS_RETAINED"
"CF_RETURNS_NOT_RETAINED" "DEPRECATED_ATTRIBUTE" "UI_APPEARANCE_SELECTOR" "UNAVAILABLE_ATTRIBUTE"
]) @attribute
; Macros
(type_qualifier
[
"_Complex"
"_Nonnull"
"_Nullable"
"_Nullable_result"
"_Null_unspecified"
"__autoreleasing"
"__block"
"__bridge"
"__bridge_retained"
"__bridge_transfer"
"__complex"
"__kindof"
"__nonnull"
"__nullable"
"__ptrauth_objc_class_ro"
"__ptrauth_objc_isa_pointer"
"__ptrauth_objc_super_pointer"
"__strong"
"__thread"
"__unsafe_unretained"
"__unused"
"__weak"
]) @function.macro.builtin
[ "__real" "__imag" ] @function.macro.builtin
((call_expression function: (identifier) @function.macro)
(#eq? @function.macro "testassert"))
; Types
(class_declaration (identifier) @type)
(class_interface "@interface" . (identifier) @type superclass: _? @type category: _? @namespace)
(class_implementation "@implementation" . (identifier) @type superclass: _? @type category: _? @namespace)
(protocol_forward_declaration (identifier) @type) ; @interface :(
(protocol_reference_list (identifier) @type) ; ^
[
"BOOL"
"IMP"
"SEL"
"Class"
"id"
] @type.builtin
; Constants
(property_attribute (identifier) @constant "="?)
[ "__asm" "__asm__" ] @constant.macro
; Properties
(property_implementation "@synthesize" (identifier) @property)
((identifier) @property
(#has-ancestor? @property struct_declaration))
; Parameters
(method_parameter ":" @method (identifier) @parameter)
(method_parameter declarator: (identifier) @parameter)
(parameter_declaration
declarator: (function_declarator
declarator: (parenthesized_declarator
(block_pointer_declarator
declarator: (identifier) @parameter))))
"..." @parameter.builtin
; Operators
[
"^"
] @operator
; Literals
(platform) @string.special
(version_number) @text.uri @number
; Punctuation
"@" @punctuation.special
[ "<" ">" ] @punctuation.bracket

@ -1,10 +0,0 @@
; inherits: c
; TODO(amaanq): uncomment/add when I add asm support
; (ms_asm_block "{" _ @asm "}")
;
; ((asm_specifier (string_literal) @asm)
; (#offset! @asm 0 1 0 -1))
;
; ((asm_statement (string_literal) @asm)
; (#offset! @asm 0 1 0 -1))

@ -1,194 +0,0 @@
examples/clang/test/ARCMT/GC-check.m
examples/clang/test/ARCMT/nonobjc-to-objc-cast.m
examples/clang/test/ARCMT/objcmt-arc-cf-annotations.m
examples/clang/test/ARCMT/objcmt-atomic-property.m
examples/clang/test/ARCMT/objcmt-migrate-all.m
examples/clang/test/ARCMT/objcmt-ns-enum-crash.m
examples/clang/test/ARCMT/objcmt-ns-macros.m
examples/clang/test/ARCMT/objcmt-ns-nonatomic-iosonly.m
examples/clang/test/ARCMT/objcmt-ns-returns-inner-pointer.m
examples/clang/test/ARCMT/objcmt-property.m
examples/clang/test/ARCMT/objcmt-subscripting-literals.m
examples/clang/test/AST/property-atomic-bool.m
examples/clang/test/Analysis/Checkers/RunLoopAutoreleaseLeakChecker.m
examples/clang/test/Analysis/NSString.m
examples/clang/test/Analysis/dispatch-once.m
examples/clang/test/Analysis/misc-ps-64.m
examples/clang/test/Analysis/misc-ps-region-store-i386.m
examples/clang/test/Analysis/misc-ps-region-store-x86_64.m
examples/clang/test/Analysis/misc-ps-region-store.m
examples/clang/test/Analysis/misc-ps.m
examples/clang/test/Analysis/number-object-conversion.m
examples/clang/test/Analysis/retain-release-arc.m
examples/clang/test/Analysis/retain-release-inline.m
examples/clang/test/Analysis/retain-release.m
examples/clang/test/Analysis/vector.m
examples/clang/test/CodeCompletion/objc-protocol-member-access.m
examples/clang/test/CodeCompletion/pch-and-module.m
examples/clang/test/CodeGen/sanitize-thread-no-checking-at-run-time.m
examples/clang/test/CodeGenObjC/arc-blocks.m
examples/clang/test/CodeGenObjC/arc-precise-lifetime.m
examples/clang/test/CodeGenObjC/block-ptr-type-crash.m
examples/clang/test/CodeGenObjC/externally-retained.m
examples/clang/test/CodeGenObjC/objc-container-subscripting.m
examples/clang/test/CodeGenObjC/objc-fixed-enum.m
examples/clang/test/CodeGenObjC/objc-gc-aggr-assign.m
examples/clang/test/FixIt/fixit-autoreleasepool.m
examples/clang/test/FixIt/fixit-objc-message.m
examples/clang/test/FixIt/fixit-objc.m
examples/clang/test/FixIt/fixit-static-object-decl.m
examples/clang/test/FixIt/format.m
examples/clang/test/FixIt/typo.m
examples/clang/test/Frontend/noderef_on_non_pointers.m
examples/clang/test/Index/Core/external-source-symbol-attr.m
examples/clang/test/Index/Core/index-source.m
examples/clang/test/Index/annotate-comments-objc.m
examples/clang/test/Index/cindex-on-invalid-usrs.m
examples/clang/test/Index/cindex-on-invalid.m
examples/clang/test/Index/complete-block-property-assignment.m
examples/clang/test/Index/complete-in-invalid-method.m
examples/clang/test/Index/complete-method-decls.m
examples/clang/test/Index/complete-objc-message-id.m
examples/clang/test/Index/complete-objc-message.m
examples/clang/test/Index/complete-parameterized-classes.m
examples/clang/test/Index/complete-preprocessor.m
examples/clang/test/Index/complete-protocols.m
examples/clang/test/Index/complete-super.m
examples/clang/test/Index/get-cursor.m
examples/clang/test/Index/index-attrs.m
examples/clang/test/Index/index-decls.m
examples/clang/test/Index/index-invalid-code.m
examples/clang/test/Index/invalid-code-rdar10451854.m
examples/clang/test/Index/pch-with-errors.m
examples/clang/test/Index/unmatched-braces.m
examples/clang/test/Lexer/minimize_source_to_dependency_directives_at_import_extra_tokens.m
examples/clang/test/Lexer/minimize_source_to_dependency_directives_at_import_missing_semi.m
examples/clang/test/Modules/objc-at-keyword.m
examples/clang/test/Modules/redefinition-c-tagtypes.m
examples/clang/test/Parser/attr-external-source-symbol.m
examples/clang/test/Parser/c2x-attributes.m
examples/clang/test/Parser/check-syntax-1.m
examples/clang/test/Parser/debugger-import-module.m
examples/clang/test/Parser/method-def-in-class.m
examples/clang/test/Parser/method-prototype-1.m
examples/clang/test/Parser/missing-closing-rbrace.m
examples/clang/test/Parser/missing-end-2.m
examples/clang/test/Parser/missing-end-3.m
examples/clang/test/Parser/missing-end-4.m
examples/clang/test/Parser/missing-end.m
examples/clang/test/Parser/objc-at-directive-fixit.m
examples/clang/test/Parser/objc-at-implementation-eof-crash.m
examples/clang/test/Parser/objc-at-interface-eof-crash.m
examples/clang/test/Parser/objc-available.m
examples/clang/test/Parser/objc-boxing.m
examples/clang/test/Parser/objc-error-qualified-implementation.m
examples/clang/test/Parser/objc-forcollection-neg-2.m
examples/clang/test/Parser/objc-foreach-syntax.m
examples/clang/test/Parser/objc-implementation-attrs.m
examples/clang/test/Parser/objc-init.m
examples/clang/test/Parser/objc-interfaces.m
examples/clang/test/Parser/objc-messaging-1.m
examples/clang/test/Parser/objc-messaging-neg-1.m
examples/clang/test/Parser/objc-missing-impl.m
examples/clang/test/Parser/objc-property-syntax.m
examples/clang/test/Parser/objc-quirks.m
examples/clang/test/Parser/objc-static-assert.m
examples/clang/test/Parser/objc-synthesized-recover.m
examples/clang/test/Parser/objc-try-catch-1.m
examples/clang/test/Parser/objcbridge-related-attribute.m
examples/clang/test/Parser/placeholder-recovery.m
examples/clang/test/Parser/recovery.m
examples/clang/test/Sema/attr-objc-bridge-related.m
examples/clang/test/SemaObjC/arc-bridged-cast.m
examples/clang/test/SemaObjC/arc-cf.m
examples/clang/test/SemaObjC/arc-non-pod-memaccess.m
examples/clang/test/SemaObjC/arc.m
examples/clang/test/SemaObjC/attr-deprecated-replacement-fixit.m
examples/clang/test/SemaObjC/attr-designated-init.m
examples/clang/test/SemaObjC/attr-objc-gc.m
examples/clang/test/SemaObjC/class-unavail-warning.m
examples/clang/test/SemaObjC/crash-label.m
examples/clang/test/SemaObjC/crash-on-objc-bool-literal.m
examples/clang/test/SemaObjC/crash-on-type-args-protocols.m
examples/clang/test/SemaObjC/delay-parsing-cfunctions.m
examples/clang/test/SemaObjC/diagnose_if.m
examples/clang/test/SemaObjC/enum-fixed-type.m
examples/clang/test/SemaObjC/externally-retained.m
examples/clang/test/SemaObjC/foreach.m
examples/clang/test/SemaObjC/incomplete-implementation.m
examples/clang/test/SemaObjC/interface-1.m
examples/clang/test/SemaObjC/invalid-code.m
examples/clang/test/SemaObjC/method-bad-param.m
examples/clang/test/SemaObjC/method-conflict-2.m
examples/clang/test/SemaObjC/method-def-1.m
examples/clang/test/SemaObjC/method-no-context.m
examples/clang/test/SemaObjC/method-sentinel-attr.m
examples/clang/test/SemaObjC/mismatched-undefined-method.m
examples/clang/test/SemaObjC/missing-atend-metadata.m
examples/clang/test/SemaObjC/nonnull.m
examples/clang/test/SemaObjC/objc-asm-attribute-neg-test.m
examples/clang/test/SemaObjC/objc-boxed-expressions-nsvalue.m
examples/clang/test/SemaObjC/objc-cf-audited-warning.m
examples/clang/test/SemaObjC/parameterized_classes.m
examples/clang/test/SemaObjC/property-9.m
examples/clang/test/SemaObjC/property.m
examples/clang/test/SemaObjC/protocol-archane.m
examples/clang/test/SemaObjC/protocols.m
examples/clang/test/SemaObjC/self-assign.m
examples/clang/test/SemaObjC/severe-syntax-error.m
examples/clang/test/SemaObjC/sizeof-interface.m
examples/clang/test/SemaObjC/string.m
examples/clang/test/SemaObjC/strong-in-c-struct.m
examples/clang/test/SemaObjC/transfer-boxed-string-nullability.m
examples/clang/test/SemaObjC/unguarded-availability-new.m
examples/clang/test/SemaObjC/unguarded-availability.m
examples/clang/test/SemaObjC/x86-method-vector-values.m
examples/objc4/test/MRCBase.m
examples/objc4/test/accessors.m
examples/objc4/test/arr-cast.m
examples/objc4/test/badCache.m
examples/objc4/test/badSuperclass.m
examples/objc4/test/blocksAsImps.m
examples/objc4/test/category.m
examples/objc4/test/concurrentcat.m
examples/objc4/test/customrr-nsobject.m
examples/objc4/test/evil-class-def.m
examples/objc4/test/exc.m
examples/objc4/test/fakeRealizedClass.m
examples/objc4/test/fakeRealizedClass2.m
examples/objc4/test/foreach.m
examples/objc4/test/fork.m
examples/objc4/test/forward.m
examples/objc4/test/initialize.m
examples/objc4/test/ivarSlide.m
examples/objc4/test/lazyClassName.m
examples/objc4/test/literals.m
examples/objc4/test/load-image-notification.m
examples/objc4/test/load-map-images.m
examples/objc4/test/load-parallel0.m
examples/objc4/test/msgSend-performance-macos.m
examples/objc4/test/msgSend-performance.m
examples/objc4/test/msgSend.m
examples/objc4/test/nsobject.m
examples/objc4/test/protocolSmall.m
examples/objc4/test/restartableRangesSynchronizeStress.m
examples/objc4/test/retain-release-helpers.m
examples/objc4/test/rr-autorelease-fast.m
examples/objc4/test/rr-autorelease-fastarc.m
examples/objc4/test/subscripting.m
examples/objc4/test/swift-class-def.m
examples/objc4/test/swiftMetadataInitializerRealloc-dylib1.m
examples/objc4/test/swiftMetadataInitializerRealloc.m
examples/objc4/test/swiftStubClassList.m
examples/objc4/test/taggedNSPointers.m
examples/objc4/test/taggedPointers.m
examples/objc4/test/unwind.m
examples/objc4/test/weakcopy.m
examples/HandBrake/macosx/HBCore.m
examples/HandBrake/macosx/HBFilters.m
examples/HandBrake/macosx/HBImageUtilities.m
examples/HandBrake/macosx/HBJob.m
examples/HandBrake/macosx/HBPresetsManager.m
examples/HandBrake/macosx/HBRedirect.m
examples/HandBrake/macosx/HBUtilities.m
examples/clang/test/SemaObjC/format-size-spec-nsinteger.m

@ -1,46 +0,0 @@
#!/usr/bin/env bash
set -eu
cd "$(dirname "$0")/.."
function clone_repo {
owner=$1
name=$2
sha=$3
path=examples/$name
if [ ! -d "$path" ]; then
echo "Cloning $owner/$name"
git clone "https://github.com/$owner/$name" "$path"
fi
pushd "$path" >/dev/null
actual_sha=$(git rev-parse HEAD)
if [ "$actual_sha" != "$sha" ]; then
echo "Updating $owner/$name to $sha"
git fetch
git reset --hard "$sha"
fi
popd >/dev/null
}
clone_repo apple-oss-distributions objc4 689525d556eb3dee1ffb700423bccf5ecc501dbf
clone_repo llvm-mirror clang aa231e4be75ac4759c236b755c57876f76e3cf05
clone_repo HandBrake HandBrake aa928b718263b7979c50f0c7cd4f87a88a5b4253
known_failures="$(cat script/known_failures.txt)"
# shellcheck disable=2046
tree-sitter parse -q \
"examples/**/*.m" \
$(for file in $known_failures; do echo "!${file}"; done)
example_count=$(find examples -name "*.m" | wc -l)
failure_count=$(wc -w <<<"$known_failures")
success_count=$((example_count - failure_count))
success_percent=$(bc -l <<<"100*${success_count}/${example_count}")
printf \
"Successfully parsed %d of %d example files (%.1f%%)\n" \
"$success_count" "$example_count" "$success_percent"

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

@ -1,224 +0,0 @@
#ifndef TREE_SITTER_PARSER_H_
#define TREE_SITTER_PARSER_H_
#ifdef __cplusplus
extern "C" {
#endif
#include <stdbool.h>
#include <stdint.h>
#include <stdlib.h>
#define ts_builtin_sym_error ((TSSymbol)-1)
#define ts_builtin_sym_end 0
#define TREE_SITTER_SERIALIZATION_BUFFER_SIZE 1024
#ifndef TREE_SITTER_API_H_
typedef uint16_t TSStateId;
typedef uint16_t TSSymbol;
typedef uint16_t TSFieldId;
typedef struct TSLanguage TSLanguage;
#endif
typedef struct {
TSFieldId field_id;
uint8_t child_index;
bool inherited;
} TSFieldMapEntry;
typedef struct {
uint16_t index;
uint16_t length;
} TSFieldMapSlice;
typedef struct {
bool visible;
bool named;
bool supertype;
} TSSymbolMetadata;
typedef struct TSLexer TSLexer;
struct TSLexer {
int32_t lookahead;
TSSymbol result_symbol;
void (*advance)(TSLexer *, bool);
void (*mark_end)(TSLexer *);
uint32_t (*get_column)(TSLexer *);
bool (*is_at_included_range_start)(const TSLexer *);
bool (*eof)(const TSLexer *);
};
typedef enum {
TSParseActionTypeShift,
TSParseActionTypeReduce,
TSParseActionTypeAccept,
TSParseActionTypeRecover,
} TSParseActionType;
typedef union {
struct {
uint8_t type;
TSStateId state;
bool extra;
bool repetition;
} shift;
struct {
uint8_t type;
uint8_t child_count;
TSSymbol symbol;
int16_t dynamic_precedence;
uint16_t production_id;
} reduce;
uint8_t type;
} TSParseAction;
typedef struct {
uint16_t lex_state;
uint16_t external_lex_state;
} TSLexMode;
typedef union {
TSParseAction action;
struct {
uint8_t count;
bool reusable;
} entry;
} TSParseActionEntry;
struct TSLanguage {
uint32_t version;
uint32_t symbol_count;
uint32_t alias_count;
uint32_t token_count;
uint32_t external_token_count;
uint32_t state_count;
uint32_t large_state_count;
uint32_t production_id_count;
uint32_t field_count;
uint16_t max_alias_sequence_length;
const uint16_t *parse_table;
const uint16_t *small_parse_table;
const uint32_t *small_parse_table_map;
const TSParseActionEntry *parse_actions;
const char * const *symbol_names;
const char * const *field_names;
const TSFieldMapSlice *field_map_slices;
const TSFieldMapEntry *field_map_entries;
const TSSymbolMetadata *symbol_metadata;
const TSSymbol *public_symbol_map;
const uint16_t *alias_map;
const TSSymbol *alias_sequences;
const TSLexMode *lex_modes;
bool (*lex_fn)(TSLexer *, TSStateId);
bool (*keyword_lex_fn)(TSLexer *, TSStateId);
TSSymbol keyword_capture_token;
struct {
const bool *states;
const TSSymbol *symbol_map;
void *(*create)(void);
void (*destroy)(void *);
bool (*scan)(void *, TSLexer *, const bool *symbol_whitelist);
unsigned (*serialize)(void *, char *);
void (*deserialize)(void *, const char *, unsigned);
} external_scanner;
const TSStateId *primary_state_ids;
};
/*
* Lexer Macros
*/
#define START_LEXER() \
bool result = false; \
bool skip = false; \
bool eof = false; \
int32_t lookahead; \
goto start; \
next_state: \
lexer->advance(lexer, skip); \
start: \
skip = false; \
lookahead = lexer->lookahead; \
eof = lexer->eof(lexer);
#define ADVANCE(state_value) \
{ \
state = state_value; \
goto next_state; \
}
#define SKIP(state_value) \
{ \
skip = true; \
state = state_value; \
goto next_state; \
}
#define ACCEPT_TOKEN(symbol_value) \
result = true; \
lexer->result_symbol = symbol_value; \
lexer->mark_end(lexer);
#define END_STATE() return result;
/*
* Parse Table Macros
*/
#define SMALL_STATE(id) ((id) - LARGE_STATE_COUNT)
#define STATE(id) id
#define ACTIONS(id) id
#define SHIFT(state_value) \
{{ \
.shift = { \
.type = TSParseActionTypeShift, \
.state = (state_value) \
} \
}}
#define SHIFT_REPEAT(state_value) \
{{ \
.shift = { \
.type = TSParseActionTypeShift, \
.state = (state_value), \
.repetition = true \
} \
}}
#define SHIFT_EXTRA() \
{{ \
.shift = { \
.type = TSParseActionTypeShift, \
.extra = true \
} \
}}
#define REDUCE(symbol_val, child_count_val, ...) \
{{ \
.reduce = { \
.type = TSParseActionTypeReduce, \
.symbol = symbol_val, \
.child_count = child_count_val, \
__VA_ARGS__ \
}, \
}}
#define RECOVER() \
{{ \
.type = TSParseActionTypeRecover \
}}
#define ACCEPT_INPUT() \
{{ \
.type = TSParseActionTypeAccept \
}}
#ifdef __cplusplus
}
#endif
#endif // TREE_SITTER_PARSER_H_

@ -1,274 +0,0 @@
================================================================================
pointer declarations vs expressions
================================================================================
TSLanguage *(*lang_parser)(void);
char (*ptr_to_array)[];
int main() {
// declare a function pointer
T1 * b(T2 a);
// evaluate expressions
c * d(5);
e(f * g);
}
--------------------------------------------------------------------------------
(translation_unit
(declaration
(type_identifier)
(pointer_declarator
(function_declarator
(parenthesized_declarator
(pointer_declarator
(identifier)))
(parameter_list
(parameter_declaration
(primitive_type))))))
(declaration
(primitive_type)
(array_declarator
(parenthesized_declarator
(pointer_declarator
(identifier)))))
(function_definition
(primitive_type)
(function_declarator
(identifier)
(parameter_list))
(compound_statement
(comment)
(declaration
(type_identifier)
(pointer_declarator
(function_declarator
(identifier)
(parameter_list
(parameter_declaration
(type_identifier)
(identifier))))))
(comment)
(expression_statement
(binary_expression
(identifier)
(call_expression
(identifier)
(argument_list
(number_literal)))))
(expression_statement
(call_expression
(identifier)
(argument_list
(binary_expression
(identifier)
(identifier))))))))
================================================================================
casts vs multiplications
================================================================================
/*
* ambiguities
*/
int main() {
// cast
a((B *)c);
// parenthesized product
d((e * f));
}
--------------------------------------------------------------------------------
(translation_unit
(comment)
(function_definition
(primitive_type)
(function_declarator
(identifier)
(parameter_list))
(compound_statement
(comment)
(expression_statement
(call_expression
(identifier)
(argument_list
(cast_expression
(type_descriptor
(type_identifier)
(abstract_pointer_declarator))
(identifier)))))
(comment)
(expression_statement
(call_expression
(identifier)
(argument_list
(parenthesized_expression
(binary_expression
(identifier)
(identifier)))))))))
================================================================================
function-like type macros vs function calls
================================================================================
// this is a macro
GIT_INLINE(int *) x = 5;
--------------------------------------------------------------------------------
(translation_unit
(comment)
(declaration
(macro_type_specifier
(identifier)
(type_descriptor
(primitive_type)
(abstract_pointer_declarator)))
(init_declarator
(identifier)
(number_literal))))
================================================================================
function calls vs parenthesized declarators vs macro types
================================================================================
int main() {
/*
* Could be either:
* - function call
* - declaration w/ parenthesized declarator
* - declaration w/ macro type, no declarator
*/
ABC(d);
/*
* Normal declaration
*/
efg hij;
}
--------------------------------------------------------------------------------
(translation_unit
(function_definition
(primitive_type)
(function_declarator
(identifier)
(parameter_list))
(compound_statement
(comment)
(expression_statement
(call_expression
(identifier)
(argument_list
(identifier))))
(comment)
(declaration
(type_identifier)
(identifier)))))
================================================================================
Call expressions vs empty declarations w/ macros as types
================================================================================
int main() {
int a = 1;
b(a);
A(A *);
}
--------------------------------------------------------------------------------
(translation_unit
(function_definition
(primitive_type)
(function_declarator
(identifier)
(parameter_list))
(compound_statement
(declaration
(primitive_type)
(init_declarator
(identifier)
(number_literal)))
(expression_statement
(call_expression
(identifier)
(argument_list
(identifier))))
(macro_type_specifier
(identifier)
(type_descriptor
(type_identifier)
(abstract_pointer_declarator))))))
================================================================================
Comments after for loops with ambiguities
================================================================================
int main() {
for (a *b = c; d; e) {
aff;
}
// a-comment
g;
}
--------------------------------------------------------------------------------
(translation_unit
(function_definition
(primitive_type)
(function_declarator
(identifier)
(parameter_list))
(compound_statement
(for_statement
(declaration
(type_identifier)
(init_declarator
(pointer_declarator
(identifier))
(identifier)))
(identifier)
(identifier)
(compound_statement
(expression_statement
(identifier))))
(comment)
(expression_statement
(identifier)))))
================================================================================
Top-level macro invocations
================================================================================
DEFINE_SOMETHING(THING_A, "this is a thing a");
DEFINE_SOMETHING(THING_B, "this is a thing b", "thanks");
--------------------------------------------------------------------------------
(translation_unit
(expression_statement
(call_expression
(identifier)
(argument_list
(identifier)
(string_literal
(string_content)))))
(expression_statement
(call_expression
(identifier)
(argument_list
(identifier)
(string_literal
(string_content))
(string_literal
(string_content))))))

@ -1,13 +0,0 @@
============================================
Line comments with escaped CRLF line endings
============================================
// hello \
this is still a comment
this_is_not a_comment;
---
(translation_unit
(comment)
(declaration (type_identifier) (identifier)))

@ -1,882 +0,0 @@
================================================================================
Struct declarations
================================================================================
struct s1;
struct s2 {
int x;
float y : 5;
};
struct s3 {
int x : 1, y : 2;
};
--------------------------------------------------------------------------------
(translation_unit
(struct_specifier
name: (type_identifier))
(struct_specifier
name: (type_identifier)
body: (field_declaration_list
(field_declaration
type: (primitive_type)
declarator: (field_identifier))
(field_declaration
type: (primitive_type)
declarator: (field_identifier)
(bitfield_clause
(number_literal)))))
(struct_specifier
name: (type_identifier)
body: (field_declaration_list
(field_declaration
type: (primitive_type)
declarator: (field_identifier)
(bitfield_clause
(number_literal))
declarator: (field_identifier)
(bitfield_clause
(number_literal))))))
================================================================================
Union declarations
================================================================================
union u1;
union s2 {
int x;
float y;
};
--------------------------------------------------------------------------------
(translation_unit
(union_specifier
name: (type_identifier))
(union_specifier
name: (type_identifier)
body: (field_declaration_list
(field_declaration
type: (primitive_type)
declarator: (field_identifier))
(field_declaration
type: (primitive_type)
declarator: (field_identifier)))))
================================================================================
Enum declarations
================================================================================
enum e1;
enum e2 {
val1,
val2 = 5,
val3
};
enum e3 {
val1,
};
enum e4: int {
val1,
};
--------------------------------------------------------------------------------
(translation_unit
(enum_specifier
name: (type_identifier))
(enum_specifier
name: (type_identifier)
body: (enumerator_list
(enumerator
name: (identifier))
(enumerator
name: (identifier)
value: (number_literal))
(enumerator
name: (identifier))))
(enum_specifier
name: (type_identifier)
body: (enumerator_list
(enumerator
name: (identifier))))
(enum_specifier
name: (type_identifier)
underlying_type: (primitive_type)
body: (enumerator_list
(enumerator
name: (identifier)))))
================================================================================
Struct declarations containing preprocessor directives
================================================================================
struct s {
#define A 5
int b[a];
#undef A
};
--------------------------------------------------------------------------------
(translation_unit
(struct_specifier
(type_identifier)
(field_declaration_list
(preproc_def
(identifier)
(preproc_arg))
(field_declaration
(primitive_type)
(array_declarator
(field_identifier)
(identifier)))
(preproc_call
(preproc_directive)
(preproc_arg)))))
================================================================================
Primitive-typed variable declarations
================================================================================
unsigned short int a;
long int b, c = 5, d;
float d, e;
unsigned f;
short g, h;
--------------------------------------------------------------------------------
(translation_unit
(declaration
type: (sized_type_specifier
type: (primitive_type))
declarator: (identifier))
(declaration
type: (sized_type_specifier
type: (primitive_type))
declarator: (identifier)
declarator: (init_declarator
declarator: (identifier)
value: (number_literal))
declarator: (identifier))
(declaration
type: (primitive_type)
declarator: (identifier)
declarator: (identifier))
(declaration
type: (sized_type_specifier)
declarator: (identifier))
(declaration
type: (sized_type_specifier)
declarator: (identifier)
declarator: (identifier)))
================================================================================
Variable storage classes
================================================================================
int a;
extern int b, c;
auto int d;
register int e;
static int f;
register uint64_t rd_ asm("x" "10");
--------------------------------------------------------------------------------
(translation_unit
(declaration
(primitive_type)
(identifier))
(declaration
(storage_class_specifier)
(primitive_type)
(identifier)
(identifier))
(declaration
(storage_class_specifier)
(primitive_type)
(identifier))
(declaration
(storage_class_specifier)
(primitive_type)
(identifier))
(declaration
(storage_class_specifier)
(primitive_type)
(identifier))
(declaration
(storage_class_specifier)
(primitive_type)
(identifier)
(gnu_asm_expression
(concatenated_string
(string_literal
(string_content))
(string_literal
(string_content))))))
================================================================================
Composite-typed variable declarations
================================================================================
struct b c;
union { int e; } f;
enum { g, h } i;
--------------------------------------------------------------------------------
(translation_unit
(declaration
type: (struct_specifier
name: (type_identifier))
declarator: (identifier))
(declaration
type: (union_specifier
body: (field_declaration_list
(field_declaration
type: (primitive_type)
declarator: (field_identifier))))
declarator: (identifier))
(declaration
type: (enum_specifier
body: (enumerator_list
(enumerator
name: (identifier))
(enumerator
name: (identifier))))
declarator: (identifier)))
================================================================================
Pointer variable declarations
================================================================================
char *the_string;
const char **the_strings;
int const * const restrict x;
--------------------------------------------------------------------------------
(translation_unit
(declaration
type: (primitive_type)
declarator: (pointer_declarator
declarator: (identifier)))
(declaration
(type_qualifier)
type: (primitive_type)
declarator: (pointer_declarator
declarator: (pointer_declarator
declarator: (identifier))))
(declaration
type: (primitive_type)
(type_qualifier)
declarator: (pointer_declarator
(type_qualifier)
(type_qualifier)
declarator: (identifier))))
================================================================================
Typedefs
================================================================================
typedef int my_int;
typedef struct {
int x;
} *a;
typedef void my_callback(void *, size_t);
typedef struct A {
int i;
} a, b;
typedef void const *voidpc;
typedef void volatile *voidpv;
typedef void const volatile *const voidpcv;
typedef unsigned long int;
typedef unsigned short ptrdiff_t;
typedef short charptr_t;
typedef unsigned nullptr_t;
typedef signed max_align_t;
typedef unsigned long ulong_t;
typedef long long_t;
typedef unsigned short ushort_t;
typedef short short_t;
typedef unsigned unsigned_t;
typedef signed signed_t;
typedef long long;
typedef short short;
typedef unsigned int uint;
typedef unsigned short ushort;
typedef unsigned unsigned short;
typedef signed signed short;
typedef signed signed unsigned;
typedef int register_t __attribute__((__mode__(__word__)));
__extension__ typedef long int greg_t;
__extension__ typedef struct {
long long int quot;
long long int rem;
} lldiv_t;
--------------------------------------------------------------------------------
(translation_unit
(type_definition
type: (primitive_type)
declarator: (type_identifier))
(type_definition
type: (struct_specifier
body: (field_declaration_list
(field_declaration
type: (primitive_type)
declarator: (field_identifier))))
declarator: (pointer_declarator
declarator: (type_identifier)))
(type_definition
type: (primitive_type)
declarator: (function_declarator
declarator: (type_identifier)
parameters: (parameter_list
(parameter_declaration
type: (primitive_type)
declarator: (abstract_pointer_declarator))
(parameter_declaration
type: (primitive_type)))))
(type_definition
type: (struct_specifier
name: (type_identifier)
body: (field_declaration_list
(field_declaration
type: (primitive_type)
declarator: (field_identifier))))
declarator: (type_identifier)
declarator: (type_identifier))
(type_definition
type: (primitive_type)
(type_qualifier)
declarator: (pointer_declarator
declarator: (type_identifier)))
(type_definition
type: (primitive_type)
(type_qualifier)
declarator: (pointer_declarator
declarator: (type_identifier)))
(type_definition
type: (primitive_type)
(type_qualifier)
(type_qualifier)
declarator: (pointer_declarator
(type_qualifier)
declarator: (type_identifier)))
(type_definition
type: (sized_type_specifier)
declarator: (primitive_type))
(type_definition
type: (sized_type_specifier)
declarator: (primitive_type))
(type_definition
type: (sized_type_specifier)
declarator: (primitive_type))
(type_definition
type: (sized_type_specifier)
declarator: (primitive_type))
(type_definition
type: (sized_type_specifier)
declarator: (primitive_type))
(type_definition
type: (sized_type_specifier)
declarator: (type_identifier))
(type_definition
type: (sized_type_specifier)
declarator: (type_identifier))
(type_definition
type: (sized_type_specifier)
declarator: (type_identifier))
(type_definition
type: (sized_type_specifier)
declarator: (type_identifier))
(type_definition
type: (sized_type_specifier)
declarator: (type_identifier))
(type_definition
type: (sized_type_specifier)
declarator: (type_identifier))
(type_definition
type: (sized_type_specifier)
declarator: (primitive_type))
(type_definition
type: (sized_type_specifier)
declarator: (primitive_type))
(type_definition
type: (sized_type_specifier
type: (primitive_type))
declarator: (type_identifier))
(type_definition
type: (sized_type_specifier)
declarator: (type_identifier))
(type_definition
type: (sized_type_specifier)
declarator: (primitive_type))
(type_definition
type: (sized_type_specifier)
declarator: (primitive_type))
(type_definition
type: (sized_type_specifier)
declarator: (primitive_type))
(type_definition
type: (primitive_type)
declarator: (type_identifier)
(attribute_specifier
(argument_list
(call_expression
function: (identifier)
arguments: (argument_list
(identifier))))))
(type_definition
type: (sized_type_specifier
type: (primitive_type))
declarator: (type_identifier))
(type_definition
type: (struct_specifier
body: (field_declaration_list
(field_declaration
type: (sized_type_specifier
type: (primitive_type))
declarator: (field_identifier))
(field_declaration
type: (sized_type_specifier
type: (primitive_type))
declarator: (field_identifier))))
declarator: (type_identifier)))
================================================================================
Function declarations
================================================================================
int main(int argc, const char **argv);
static foo bar();
static baz quux(...);
--------------------------------------------------------------------------------
(translation_unit
(declaration
(primitive_type)
(function_declarator
(identifier)
(parameter_list
(parameter_declaration
(primitive_type)
(identifier))
(parameter_declaration
(type_qualifier)
(primitive_type)
(pointer_declarator
(pointer_declarator
(identifier)))))))
(declaration
(storage_class_specifier)
(type_identifier)
(function_declarator
(identifier)
(parameter_list)))
(declaration
(storage_class_specifier)
(type_identifier)
(function_declarator
(identifier)
(parameter_list
(variadic_parameter)))))
================================================================================
Function definitions
================================================================================
void * do_stuff(int arg1) {
return 5;
}
--------------------------------------------------------------------------------
(translation_unit
(function_definition
type: (primitive_type)
declarator: (pointer_declarator
declarator: (function_declarator
declarator: (identifier)
parameters: (parameter_list
(parameter_declaration
type: (primitive_type)
declarator: (identifier)))))
body: (compound_statement
(return_statement
(number_literal)))))
================================================================================
Function specifiers after types
================================================================================
int static inline do_stuff(int arg1) {
return 5;
}
--------------------------------------------------------------------------------
(translation_unit
(function_definition
(primitive_type)
(storage_class_specifier)
(storage_class_specifier)
(function_declarator
(identifier)
(parameter_list
(parameter_declaration
(primitive_type)
(identifier))))
(compound_statement
(return_statement
(number_literal)))))
================================================================================
Linkage specifications
================================================================================
extern "C" int foo();
extern "C" int foo() { return 0; }
extern "C" {
int bar();
int baz();
}
--------------------------------------------------------------------------------
(translation_unit
(linkage_specification
(string_literal
(string_content))
(declaration
(primitive_type)
(function_declarator
(identifier)
(parameter_list))))
(linkage_specification
(string_literal
(string_content))
(function_definition
(primitive_type)
(function_declarator
(identifier)
(parameter_list))
(compound_statement
(return_statement
(number_literal)))))
(linkage_specification
(string_literal
(string_content))
(declaration_list
(declaration
(primitive_type)
(function_declarator
(identifier)
(parameter_list)))
(declaration
(primitive_type)
(function_declarator
(identifier)
(parameter_list))))))
================================================================================
Type qualifiers
================================================================================
const _Atomic unsigned long int x = 5;
restrict int y = 6;
volatile int z = 7;
constexpr int a = 8;
__thread int c = 9;
noreturn void b() {}
__extension__ extern int ffsll (long long int __ll)
__attribute__ ((__nothrow__ )) __attribute__ ((__const__));
--------------------------------------------------------------------------------
(translation_unit
(declaration
(type_qualifier)
(type_qualifier)
(sized_type_specifier
(primitive_type))
(init_declarator
(identifier)
(number_literal)))
(declaration
(type_qualifier)
(primitive_type)
(init_declarator
(identifier)
(number_literal)))
(declaration
(type_qualifier)
(primitive_type)
(init_declarator
(identifier)
(number_literal)))
(declaration
(type_qualifier)
(primitive_type)
(init_declarator
(identifier)
(number_literal)))
(declaration
(storage_class_specifier)
(primitive_type)
(init_declarator
(identifier)
(number_literal)))
(function_definition
(type_qualifier)
(primitive_type)
(function_declarator
(identifier)
(parameter_list))
(compound_statement))
(declaration
(type_qualifier)
(storage_class_specifier)
(primitive_type)
(function_declarator
(identifier)
(parameter_list
(parameter_declaration
(sized_type_specifier
(primitive_type))
(identifier)))
(attribute_specifier
(argument_list
(identifier))))
(attribute_specifier
(argument_list
(identifier)))))
================================================================================
Local array declarations
================================================================================
int main() {
char the_buffer[the_size];
char the_other_buffer[*];
}
--------------------------------------------------------------------------------
(translation_unit
(function_definition
(primitive_type)
(function_declarator
(identifier)
(parameter_list))
(compound_statement
(declaration
(primitive_type)
(array_declarator
(identifier)
(identifier)))
(declaration
(primitive_type)
(array_declarator
(identifier))))))
================================================================================
Attributes
================================================================================
extern __attribute__((visibility("hidden"))) int foo();
extern int bar() __attribute__((const));
void die(const char *format, ...) __attribute__((noreturn))
__attribute__((format(printf,1,2)));
extern __attribute__((visibility("default"), weak)) int print_status();
extern int strerror_r(int __errnum, char *__buf,
int __buflen) __asm__(""
"__xpg_strerror_r")
__attribute__((__nothrow__)) __attribute__((__nonnull__(2)));
struct X {
int a __attribute__((aligned(4)));
} __attribute__((aligned(16)));
union Y {
int a __attribute__((aligned(4)));
} __attribute__((aligned(16)));
enum Z {
A
} __attribute__((aligned(16)));
struct __attribute__((__packed__)) foo_t {
int x;
};
--------------------------------------------------------------------------------
(translation_unit
(declaration
(storage_class_specifier)
(attribute_specifier
(argument_list
(call_expression
(identifier)
(argument_list
(string_literal
(string_content))))))
(primitive_type)
(function_declarator
(identifier)
(parameter_list)))
(declaration
(storage_class_specifier)
(primitive_type)
(function_declarator
(identifier)
(parameter_list)
(attribute_specifier
(argument_list
(identifier)))))
(declaration
(primitive_type)
(function_declarator
(identifier)
(parameter_list
(parameter_declaration
(type_qualifier)
(primitive_type)
(pointer_declarator
(identifier)))
(variadic_parameter))
(attribute_specifier))
(attribute_specifier
(argument_list
(call_expression
(identifier)
(argument_list
(identifier)
(number_literal)
(number_literal))))))
(declaration
(storage_class_specifier)
(attribute_specifier
(argument_list
(call_expression
(identifier)
(argument_list
(string_literal
(string_content))))
(identifier)))
(primitive_type)
(function_declarator
(identifier)
(parameter_list)))
(declaration
(storage_class_specifier)
(primitive_type)
(function_declarator
(identifier)
(parameter_list
(parameter_declaration
(primitive_type)
(identifier))
(parameter_declaration
(primitive_type)
(pointer_declarator
(identifier)))
(parameter_declaration
(primitive_type)
(identifier)))
(gnu_asm_expression
(concatenated_string
(string_literal)
(string_literal
(string_content))))
(attribute_specifier
(argument_list
(identifier))))
(attribute_specifier
(argument_list
(call_expression
(identifier)
(argument_list
(number_literal))))))
(struct_specifier
(type_identifier)
(field_declaration_list
(field_declaration
(primitive_type)
(field_identifier)
(attribute_specifier
(argument_list
(call_expression
(identifier)
(argument_list
(number_literal)))))))
(attribute_specifier
(argument_list
(call_expression
(identifier)
(argument_list
(number_literal))))))
(union_specifier
(type_identifier)
(field_declaration_list
(field_declaration
(primitive_type)
(field_identifier)
(attribute_specifier
(argument_list
(call_expression
(identifier)
(argument_list
(number_literal)))))))
(attribute_specifier
(argument_list
(call_expression
(identifier)
(argument_list
(number_literal))))))
(enum_specifier
(type_identifier)
(enumerator_list
(enumerator
(identifier)))
(attribute_specifier
(argument_list
(call_expression
(identifier)
(argument_list
(number_literal))))))
(struct_specifier
(attribute_specifier
(argument_list
(identifier)))
(type_identifier)
(field_declaration_list
(field_declaration
(primitive_type)
(field_identifier)))))

File diff suppressed because it is too large Load Diff

@ -1,187 +0,0 @@
================================
declaration specs
================================
struct __declspec(dllexport) s2
{
};
union __declspec(noinline) u2 {
};
---
(translation_unit
(struct_specifier
(ms_declspec_modifier
(identifier))
name: (type_identifier)
body: (field_declaration_list))
(union_specifier
(ms_declspec_modifier
(identifier))
name: (type_identifier)
body: (field_declaration_list)))
================================
pointers
================================
struct s2
{
int * __restrict x;
int * __sptr psp;
int * __uptr pup;
int * __unaligned pup;
};
void sum2(int n, int * __restrict a, int * __restrict b,
int * c, int * d) {
int i;
for (i = 0; i < n; i++) {
a[i] = b[i] + c[i];
c[i] = b[i] + d[i];
}
}
void MyFunction(char * __uptr myValue);
---
(translation_unit
(struct_specifier
name: (type_identifier)
body: (field_declaration_list
(field_declaration
type: (primitive_type)
declarator: (pointer_declarator
(ms_pointer_modifier
(ms_restrict_modifier))
declarator: (field_identifier)))
(field_declaration
type: (primitive_type)
declarator: (pointer_declarator
(ms_pointer_modifier
(ms_signed_ptr_modifier))
declarator: (field_identifier)))
(field_declaration
type: (primitive_type)
declarator: (pointer_declarator
(ms_pointer_modifier
(ms_unsigned_ptr_modifier))
declarator: (field_identifier)))
(field_declaration
type: (primitive_type)
declarator: (pointer_declarator
(ms_pointer_modifier
(ms_unaligned_ptr_modifier))
declarator: (field_identifier)))))
(function_definition
type: (primitive_type)
declarator: (function_declarator
declarator: (identifier)
parameters: (parameter_list
(parameter_declaration
type: (primitive_type)
declarator: (identifier))
(parameter_declaration
type: (primitive_type)
declarator: (pointer_declarator
(ms_pointer_modifier
(ms_restrict_modifier))
declarator: (identifier)))
(parameter_declaration
type: (primitive_type)
declarator: (pointer_declarator
(ms_pointer_modifier
(ms_restrict_modifier))
declarator: (identifier)))
(parameter_declaration
type: (primitive_type)
declarator: (pointer_declarator
declarator: (identifier)))
(parameter_declaration
type: (primitive_type)
declarator: (pointer_declarator
declarator: (identifier)))))
body: (compound_statement
(declaration
type: (primitive_type)
declarator: (identifier))
(for_statement
initializer: (assignment_expression
left: (identifier)
right: (number_literal))
condition: (binary_expression
left: (identifier)
right: (identifier))
update: (update_expression
argument: (identifier))
body: (compound_statement
(expression_statement
(assignment_expression
left: (subscript_expression
argument: (identifier)
index: (identifier))
right: (binary_expression
left: (subscript_expression
argument: (identifier)
index: (identifier))
right: (subscript_expression
argument: (identifier)
index: (identifier)))))
(expression_statement
(assignment_expression
left: (subscript_expression
argument: (identifier)
index: (identifier))
right: (binary_expression
left: (subscript_expression
argument: (identifier)
index: (identifier))
right: (subscript_expression
argument: (identifier)
index: (identifier)))))))))
(declaration
type: (primitive_type)
declarator: (function_declarator
declarator: (identifier)
parameters: (parameter_list
(parameter_declaration
type: (primitive_type)
declarator: (pointer_declarator
(ms_pointer_modifier
(ms_unsigned_ptr_modifier))
declarator: (identifier)))))))
================================
call modifiers
================================
__cdecl void mymethod(){
return;
}
__fastcall void mymethod(){
return;
}
---
(translation_unit
(function_definition
(ms_call_modifier)
type: (primitive_type)
declarator: (function_declarator
declarator: (identifier)
parameters: (parameter_list))
body: (compound_statement
(return_statement)))
(function_definition
(ms_call_modifier)
type: (primitive_type)
declarator: (function_declarator
declarator: (identifier)
parameters: (parameter_list))
body: (compound_statement
(return_statement))))

@ -1,401 +0,0 @@
================================================================================
Include directives
================================================================================
#include "some/path.h"
#include <stdint.h>
#include MACRO
#include MACRO(arg1, arg2)
--------------------------------------------------------------------------------
(translation_unit
(preproc_include
path: (string_literal
(string_content)))
(preproc_include
path: (system_lib_string))
(preproc_include
path: (identifier))
(preproc_include
path: (call_expression
function: (identifier)
arguments: (argument_list
(identifier)
(identifier)))))
================================================================================
Object-like macro definitions
================================================================================
#define ONE
#define TWO int a = b;
#define THREE \
c == d ? \
e : \
f
#define FOUR (mno * pq)
#define FIVE(a,b) x \
+ y
#define SIX(a, \
b) x \
+ y
#define SEVEN 7/* seven has an
* annoying comment */
#define EIGHT(x) do { \
x = x + 1; \
x = x / 2; \
} while (x > 0);
--------------------------------------------------------------------------------
(translation_unit
(preproc_def
name: (identifier))
(preproc_def
name: (identifier)
value: (preproc_arg))
(preproc_def
name: (identifier)
value: (preproc_arg))
(preproc_def
name: (identifier)
value: (preproc_arg))
(preproc_function_def
name: (identifier)
parameters: (preproc_params
(identifier)
(identifier))
value: (preproc_arg))
(preproc_function_def
name: (identifier)
parameters: (preproc_params
(identifier)
(identifier))
value: (preproc_arg))
(preproc_def
name: (identifier)
value: (preproc_arg)
(comment))
(preproc_function_def
name: (identifier)
parameters: (preproc_params
(identifier))
value: (preproc_arg)))
================================================================================
Function-like macro definitions
================================================================================
#define ONE() a
#define TWO(b) c
#define THREE(d, e) f
#define FOUR(...) g
#define FIVE(h, i, ...) j
--------------------------------------------------------------------------------
(translation_unit
(preproc_function_def
name: (identifier)
parameters: (preproc_params)
value: (preproc_arg))
(preproc_function_def
name: (identifier)
parameters: (preproc_params
(identifier))
value: (preproc_arg))
(preproc_function_def
name: (identifier)
parameters: (preproc_params
(identifier)
(identifier))
value: (preproc_arg))
(preproc_function_def
name: (identifier)
parameters: (preproc_params)
value: (preproc_arg))
(preproc_function_def
name: (identifier)
parameters: (preproc_params
(identifier)
(identifier))
value: (preproc_arg)))
================================================================================
Ifdefs
================================================================================
#ifndef DEFINE1
int j;
#endif
#ifdef DEFINE2
ssize_t b;
#define c 32
#elif defined DEFINE3
#else
int b;
#define c 16
#endif
#ifdef DEFINE2
#else
# ifdef DEFINE3
# else
# endif
#endif
--------------------------------------------------------------------------------
(translation_unit
(preproc_ifdef
name: (identifier)
(declaration
type: (primitive_type)
declarator: (identifier)))
(preproc_ifdef
name: (identifier)
(declaration
type: (primitive_type)
declarator: (identifier))
(preproc_def
name: (identifier)
value: (preproc_arg))
alternative: (preproc_elif
condition: (preproc_defined
(identifier))
alternative: (preproc_else
(declaration
type: (primitive_type)
declarator: (identifier))
(preproc_def
name: (identifier)
value: (preproc_arg)))))
(preproc_ifdef
name: (identifier)
alternative: (preproc_else
(preproc_ifdef
name: (identifier)
alternative: (preproc_else)))))
================================================================================
Elifdefs
================================================================================
#ifndef DEFINE1
int j;
#elifndef DEFINE2
int k;
#endif
#ifdef DEFINE2
ssize_t b;
#elifdef DEFINE3
ssize_t c;
#else
int b;
#endif
--------------------------------------------------------------------------------
(translation_unit
(preproc_ifdef
(identifier)
(declaration
(primitive_type)
(identifier))
(preproc_elifdef
(identifier)
(declaration
(primitive_type)
(identifier))))
(preproc_ifdef
(identifier)
(declaration
(primitive_type)
(identifier))
(preproc_elifdef
(identifier)
(declaration
(primitive_type)
(identifier))
(preproc_else
(declaration
(primitive_type)
(identifier))))))
================================================================================
General if blocks
================================================================================
#if defined(__GNUC__) && defined(__PIC__)
#define inline inline __attribute__((always_inline))
#elif defined(_WIN32)
#define something
#elif !defined(SOMETHING_ELSE)
#define SOMETHING_ELSE
#else
#include <something>
#endif
--------------------------------------------------------------------------------
(translation_unit
(preproc_if
condition: (binary_expression
left: (preproc_defined
(identifier))
right: (preproc_defined
(identifier)))
(preproc_def
name: (identifier)
value: (preproc_arg))
alternative: (preproc_elif
condition: (preproc_defined
(identifier))
(preproc_def
name: (identifier))
alternative: (preproc_elif
condition: (unary_expression
argument: (preproc_defined
(identifier)))
(preproc_def
name: (identifier))
alternative: (preproc_else
(preproc_include
path: (system_lib_string)))))))
================================================================================
Preprocessor conditionals in functions
================================================================================
int main() {
#if d
puts("1");
#else
puts("2");
#endif
#if a
return 0;
#elif b
return 1;
#elif c
return 2;
#else
return 3;
#endif
}
--------------------------------------------------------------------------------
(translation_unit
(function_definition
(primitive_type)
(function_declarator
(identifier)
(parameter_list))
(compound_statement
(preproc_if
(identifier)
(expression_statement
(call_expression
(identifier)
(argument_list
(string_literal
(string_content)))))
(preproc_else
(expression_statement
(call_expression
(identifier)
(argument_list
(string_literal
(string_content)))))))
(preproc_if
(identifier)
(return_statement
(number_literal))
(preproc_elif
(identifier)
(return_statement
(number_literal))
(preproc_elif
(identifier)
(return_statement
(number_literal))
(preproc_else
(return_statement
(number_literal)))))))))
================================================================================
Preprocessor conditionals in struct/union bodies
================================================================================
struct S {
#ifdef _WIN32
LONG f2;
#else
uint32_t f2;
#endif
};
--------------------------------------------------------------------------------
(translation_unit
(struct_specifier
(type_identifier)
(field_declaration_list
(preproc_ifdef
(identifier)
(field_declaration
(type_identifier)
(field_identifier))
(preproc_else
(field_declaration
(primitive_type)
(field_identifier)))))))
================================================================================
Unknown preprocessor directives
================================================================================
#pragma mark - UIViewController
--------------------------------------------------------------------------------
(translation_unit
(preproc_call
directive: (preproc_directive)
argument: (preproc_arg)))
================================================================================
Preprocessor expressions
================================================================================
#if A(B || C) && \
!D(F)
uint32_t a;
#endif
--------------------------------------------------------------------------------
(translation_unit
(preproc_if
(binary_expression
(call_expression
(identifier)
(argument_list
(binary_expression
(identifier)
(identifier))))
(unary_expression
(call_expression
(identifier)
(argument_list
(identifier)))))
(declaration
(primitive_type)
(identifier))))

@ -1,535 +0,0 @@
================================================================================
If statements
================================================================================
int main() {
if (a)
1;
if (!a) {
2;
} else {
3;
}
}
--------------------------------------------------------------------------------
(translation_unit
(function_definition
(primitive_type)
(function_declarator
(identifier)
(parameter_list))
(compound_statement
(if_statement
(parenthesized_expression
(identifier))
(expression_statement
(number_literal)))
(if_statement
(parenthesized_expression
(unary_expression
(identifier)))
(compound_statement
(expression_statement
(number_literal)))
(else_clause
(compound_statement
(expression_statement
(number_literal))))))))
================================================================================
For loops
================================================================================
int main() {
for (;;)
1;
for (int i = 0; i < 5; next(), i++) {
2;
}
for (start(); check(); step())
3;
for (i = 0, j = 0, k = 0, l = 0; i < 1, j < 1; i++, j++, k++, l++)
1;
}
--------------------------------------------------------------------------------
(translation_unit
(function_definition
(primitive_type)
(function_declarator
(identifier)
(parameter_list))
(compound_statement
(for_statement
(expression_statement
(number_literal)))
(for_statement
(declaration
(primitive_type)
(init_declarator
(identifier)
(number_literal)))
(binary_expression
(identifier)
(number_literal))
(comma_expression
(call_expression
(identifier)
(argument_list))
(update_expression
(identifier)))
(compound_statement
(expression_statement
(number_literal))))
(for_statement
(call_expression
(identifier)
(argument_list))
(call_expression
(identifier)
(argument_list))
(call_expression
(identifier)
(argument_list))
(expression_statement
(number_literal)))
(for_statement
(comma_expression
(assignment_expression
(identifier)
(number_literal))
(comma_expression
(assignment_expression
(identifier)
(number_literal))
(comma_expression
(assignment_expression
(identifier)
(number_literal))
(assignment_expression
(identifier)
(number_literal)))))
(comma_expression
(binary_expression
(identifier)
(number_literal))
(binary_expression
(identifier)
(number_literal)))
(comma_expression
(update_expression
(identifier))
(comma_expression
(update_expression
(identifier))
(comma_expression
(update_expression
(identifier))
(update_expression
(identifier)))))
(expression_statement
(number_literal))))))
================================================================================
While loops
================================================================================
int main() {
while (x)
printf("hi");
}
--------------------------------------------------------------------------------
(translation_unit
(function_definition
(primitive_type)
(function_declarator
(identifier)
(parameter_list))
(compound_statement
(while_statement
(parenthesized_expression
(identifier))
(expression_statement
(call_expression
(identifier)
(argument_list
(string_literal
(string_content)))))))))
================================================================================
Labeled statements
================================================================================
void foo(T *t) {
recur:
t = t->next();
if (t) goto recur;
}
--------------------------------------------------------------------------------
(translation_unit
(function_definition
(primitive_type)
(function_declarator
(identifier)
(parameter_list
(parameter_declaration
(type_identifier)
(pointer_declarator
(identifier)))))
(compound_statement
(labeled_statement
(statement_identifier)
(expression_statement
(assignment_expression
(identifier)
(call_expression
(field_expression
(identifier)
(field_identifier))
(argument_list)))))
(if_statement
(parenthesized_expression
(identifier))
(goto_statement
(statement_identifier))))))
================================================================================
Switch statements
================================================================================
void foo(int a) {
switch (a) {
puts("entered switch!");
case 3:
case 5:
if (b) {
c();
}
break;
default:
c();
break;
}
}
--------------------------------------------------------------------------------
(translation_unit
(function_definition
(primitive_type)
(function_declarator
(identifier)
(parameter_list
(parameter_declaration
(primitive_type)
(identifier))))
(compound_statement
(switch_statement
(parenthesized_expression
(identifier))
(compound_statement
(expression_statement
(call_expression
(identifier)
(argument_list
(string_literal
(string_content)))))
(case_statement
(number_literal))
(case_statement
(number_literal)
(if_statement
(parenthesized_expression
(identifier))
(compound_statement
(expression_statement
(call_expression
(identifier)
(argument_list)))))
(break_statement))
(case_statement
(expression_statement
(call_expression
(identifier)
(argument_list)))
(break_statement)))))))
================================================================================
Case statements separate from switch statements
================================================================================
int main() {
switch (count % 8) {
case 0:
do {
*to = *from++;
case 2: *to = *from++;
case 1: *to = *from++;
} while (--n > 0);
}
}
--------------------------------------------------------------------------------
(translation_unit
(function_definition
(primitive_type)
(function_declarator
(identifier)
(parameter_list))
(compound_statement
(switch_statement
(parenthesized_expression
(binary_expression
(identifier)
(number_literal)))
(compound_statement
(case_statement
(number_literal)
(do_statement
(compound_statement
(expression_statement
(assignment_expression
(pointer_expression
(identifier))
(pointer_expression
(update_expression
(identifier)))))
(case_statement
(number_literal)
(expression_statement
(assignment_expression
(pointer_expression
(identifier))
(pointer_expression
(update_expression
(identifier))))))
(case_statement
(number_literal)
(expression_statement
(assignment_expression
(pointer_expression
(identifier))
(pointer_expression
(update_expression
(identifier)))))))
(parenthesized_expression
(binary_expression
(update_expression
(identifier))
(number_literal))))))))))
================================================================================
Return statements
================================================================================
void foo() {
return;
return a;
return a, b;
}
--------------------------------------------------------------------------------
(translation_unit
(function_definition
(primitive_type)
(function_declarator
(identifier)
(parameter_list))
(compound_statement
(return_statement)
(return_statement
(identifier))
(return_statement
(comma_expression
(identifier)
(identifier))))))
================================================================================
Comments with asterisks
================================================================================
/*************************
* odd number of asterisks
*************************/
int a;
/**************************
* even number of asterisks
**************************/
int b;
--------------------------------------------------------------------------------
(translation_unit
(comment)
(declaration
(primitive_type)
(identifier))
(comment)
(declaration
(primitive_type)
(identifier)))
================================================================================
Comment with multiple backslashes
================================================================================
int a = 3; // Hello \\
World
--------------------------------------------------------------------------------
(translation_unit
(declaration
(primitive_type)
(init_declarator
(identifier)
(number_literal)))
(comment))
================================================================================
Attributes
================================================================================
void f() {
[[a]] switch (b) {
[[c]] case 1: {}
case 2:
[[fallthrough]];
default:
}
[[a]] while (true) {}
[[a]] if (true) {}
[[a]] for (;;) {}
[[a]] return;
[[a]] a;
[[a]];
[[a]] label: {}
[[a]] goto label;
// these are c++ specific, but their bind locations should be c-compatible
if (true) [[likely]] {} else [[unlikely]] {}
do [[likely]] {} while (true);
}
--------------------------------------------------------------------------------
(translation_unit
(function_definition
(primitive_type)
(function_declarator
(identifier)
(parameter_list))
(compound_statement
(attributed_statement
(attribute_declaration
(attribute
(identifier)))
(switch_statement
(parenthesized_expression
(identifier))
(compound_statement
(attributed_statement
(attribute_declaration
(attribute
(identifier)))
(case_statement
(number_literal)
(compound_statement)))
(case_statement
(number_literal)
(attributed_statement
(attribute_declaration
(attribute
(identifier)))
(expression_statement)))
(case_statement))))
(attributed_statement
(attribute_declaration
(attribute
(identifier)))
(while_statement
(parenthesized_expression
(true))
(compound_statement)))
(attributed_statement
(attribute_declaration
(attribute
(identifier)))
(if_statement
(parenthesized_expression
(true))
(compound_statement)))
(attributed_statement
(attribute_declaration
(attribute
(identifier)))
(for_statement
(compound_statement)))
(attributed_statement
(attribute_declaration
(attribute
(identifier)))
(return_statement))
(attributed_statement
(attribute_declaration
(attribute
(identifier)))
(expression_statement
(identifier)))
(attributed_statement
(attribute_declaration
(attribute
(identifier)))
(expression_statement))
(attributed_statement
(attribute_declaration
(attribute
(identifier)))
(labeled_statement
(statement_identifier)
(compound_statement)))
(attributed_statement
(attribute_declaration
(attribute
(identifier)))
(goto_statement
(statement_identifier)))
(comment)
(if_statement
(parenthesized_expression
(true))
(attributed_statement
(attribute_declaration
(attribute
(identifier)))
(compound_statement))
(else_clause
(attributed_statement
(attribute_declaration
(attribute
(identifier)))
(compound_statement))))
(do_statement
(attributed_statement
(attribute_declaration
(attribute
(identifier)))
(compound_statement))
(parenthesized_expression
(true))))))

@ -1,80 +0,0 @@
========================================
Primitive types
========================================
int a;
uint8_t a;
uint16_t a;
uint32_t a;
uint64_t a;
uintptr_t a;
int8_t a;
int16_t a;
int32_t a;
int64_t a;
intptr_t a;
char16_t a;
char32_t a;
size_t a;
ssize_t a;
---
(translation_unit
(declaration (primitive_type) (identifier))
(declaration (primitive_type) (identifier))
(declaration (primitive_type) (identifier))
(declaration (primitive_type) (identifier))
(declaration (primitive_type) (identifier))
(declaration (primitive_type) (identifier))
(declaration (primitive_type) (identifier))
(declaration (primitive_type) (identifier))
(declaration (primitive_type) (identifier))
(declaration (primitive_type) (identifier))
(declaration (primitive_type) (identifier))
(declaration (primitive_type) (identifier))
(declaration (primitive_type) (identifier))
(declaration (primitive_type) (identifier))
(declaration (primitive_type) (identifier)))
========================================
Type modifiers
========================================
void f(unsigned);
void f(unsigned int);
void f(signed long int);
void f(unsigned v1);
void f(unsigned long v2);
---
(translation_unit
(declaration
(primitive_type)
(function_declarator
(identifier)
(parameter_list (parameter_declaration (sized_type_specifier)))))
(declaration
(primitive_type)
(function_declarator
(identifier)
(parameter_list (parameter_declaration (sized_type_specifier (primitive_type))))))
(declaration
(primitive_type)
(function_declarator
(identifier)
(parameter_list (parameter_declaration (sized_type_specifier (primitive_type))))))
(declaration
(primitive_type)
(function_declarator
(identifier)
(parameter_list (parameter_declaration (sized_type_specifier) (identifier)))))
(declaration
(primitive_type)
(function_declarator
(identifier)
(parameter_list (parameter_declaration (sized_type_specifier) (identifier))))))