tree-sitter/cli/src/generate
Alyssa Verkade 0e689657b7 Add a language linkage declaration to parsers
Previously, in order to compile a `tree-sitter` grammar that contained
c++ source in the parser (ie the `scanner.cc` file), you would have to
compile the `parser.c` file separately from the c++ files. For example,
in rust this would result in a `build.rs` close to the following:
```
extern crate cc;

fn main() {
  let dir: PathBuf = ["tree-sitter-ruby", "src"].iter().collect();

  cc::Build::new()
    .include(&dir)
    .cpp(true)
    .file(dir.join("scanner.cc"))
    // NOTE: must have a name that differs from the c static lib
    .compile("tree-sitter-ruby-scanner");

  cc::Build::new()
    .include(&dir)
    .file(dir.join("parser.c"))
    // NOTE: must have a name that differs from the c++ static lib
    .compile("tree-sitter-ruby-parser");
}
```

This was necessary at the time for the following grammars: `ruby`,
`php`, `python`, `embedded-template`, `html`, `cpp`, `ocaml`,
`bash`, `agda`, and `haskell`.

To solve this, we specify an `extern "C"` language linkage declaration
to the functions that must be linked against to compile a parser with the
scanner, making parsers linkable against c++ source.
On all major compilers (gcc, clang, and msvc) this should be the only
change needed due to the combination of clang and gcc both supporting
designated initialization for years and msvc 2019 adopting designated
initializers as a part of the C++20 conformance push.

Subsequently, for rust projects, the necessary `build.rs` would become
(which also brings these parsers into sync with the current docs):
```
extern crate cc;

fn main() {
  let dir: PathBuf = ["tree-sitter-ruby", "src"].iter().collect();

  cc::Build::new()
    .include(&dir)
    .cpp(true)
    .file(dir.join("scanner.cc"))
    .file(dir.join("parser.c"))
    .compile("tree-sitter-ruby");
}
```
2020-02-18 19:46:59 -08:00
..
build_tables Don't attempt to extract keywords that don't entirely match word token (#505) 2019-12-11 17:18:15 -08:00
prepare_grammar Rename extra_tokens -> extra_symbols 2019-10-21 17:26:01 -07:00
templates Update generated binding.cc to use newer NAN APIs 2019-04-30 17:23:36 -07:00
dedup.rs Move state splitting algorithm into its own file 2019-07-19 12:39:52 -07:00
dsl.js Catch missing precedence values in JS 2019-04-05 13:04:12 -07:00
grammar-schema.json added field-rule to grammar-schema.json 2020-01-12 19:40:21 -05:00
grammars.rs Rename extra_tokens -> extra_symbols 2019-10-21 17:26:01 -07:00
mod.rs Store a mapping to ensure no two symbols map to the same metadata 2019-12-05 17:21:46 -08:00
nfa.rs Fix false negative in token conflict detection 2019-09-19 11:50:38 -07:00
node_types.rs node-types: Fix ambiguity warning on rustc 1.41 2020-02-10 10:26:12 -08:00
npm_files.rs Generate binding.gyp, binding.cc, and index.js 2019-01-16 13:53:01 -08:00
parse_grammar.rs Rename extra_tokens -> extra_symbols 2019-10-21 17:26:01 -07:00
render.rs Add a language linkage declaration to parsers 2020-02-18 19:46:59 -08:00
rules.rs Fix node-types bugs involving aliases and external tokens 2019-12-12 10:06:18 -08:00
tables.rs Add a TSLexer.eof() API, use it in generated parsers 2019-10-31 14:11:52 -07:00