Skip to content

Commit 2758190

Browse files
committed
Add GitHub Actions
1 parent baeeda1 commit 2758190

File tree

3 files changed

+165
-3
lines changed

3 files changed

+165
-3
lines changed
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
name: Run tests
2+
3+
on: [push, pull_request]
4+
5+
jobs:
6+
test-code:
7+
8+
strategy:
9+
matrix:
10+
os: [ubuntu-latest, macos-latest, windows-latest]
11+
12+
runs-on: ${{ matrix.os }}
13+
14+
steps:
15+
- uses: actions/checkout@v2
16+
17+
- name: Checkout submodules
18+
shell: bash
19+
run: |
20+
GIT_PATH=https://github.com/.extraheader
21+
AUTH_HEADER="$(git config --local --get http.$GIT_PATH)"
22+
git submodule sync --recursive
23+
git -c "http.extraheader=$AUTH_HEADER" \
24+
-c protocol.version=2 \
25+
submodule update --init --force --recursive --depth=1
26+
27+
- name: Install Rust stable
28+
uses: actions-rs/toolchain@v1
29+
with:
30+
profile: minimal
31+
toolchain: stable
32+
override: true
33+
34+
- name: Build
35+
run: |
36+
cargo build --all-features --verbose
37+
38+
- name: Run tests
39+
run: |
40+
cargo test --all-features --verbose

build.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ fn collect_src_files(dir: &str) -> (Vec<String>, Vec<String>) {
9696
}
9797

9898
fn build_c(files: Vec<String>, language: &str) {
99+
let triple = env::var("TARGET").unwrap();
99100
let mut build = cc::Build::new();
100101
for file in files {
101102
build
@@ -104,8 +105,11 @@ fn build_c(files: Vec<String>, language: &str) {
104105
.pic(true)
105106
.opt_level(get_opt_level())
106107
.debug(get_debug())
107-
.warnings(false)
108-
.flag("-std=c99");
108+
.warnings(false);
109+
110+
if triple != "x86_64-pc-windows-msvc" {
111+
build.flag("-std=c99");
112+
}
109113
}
110114
build.compile(&format!("tree-sitter-{}-c", language));
111115
}

tree-sitter-mozcpp/src/scanner.cc

Lines changed: 0 additions & 1 deletion
This file was deleted.

tree-sitter-mozcpp/src/scanner.cc

Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
#include <tree_sitter/parser.h>
2+
#include <string>
3+
#include <cwctype>
4+
5+
namespace {
6+
7+
using std::wstring;
8+
using std::iswspace;
9+
10+
enum TokenType {
11+
RAW_STRING_LITERAL,
12+
};
13+
14+
struct Scanner {
15+
bool scan(TSLexer *lexer, const bool *valid_symbols) {
16+
while (iswspace(lexer->lookahead)) {
17+
lexer->advance(lexer, true);
18+
}
19+
20+
lexer->result_symbol = RAW_STRING_LITERAL;
21+
22+
// Raw string literals can start with: R, LR, uR, UR, u8R
23+
// Consume 'R'
24+
if (lexer->lookahead == 'L' || lexer->lookahead == 'U') {
25+
lexer->advance(lexer, false);
26+
if (lexer->lookahead != 'R') {
27+
return false;
28+
}
29+
} else if (lexer->lookahead == 'u') {
30+
lexer->advance(lexer, false);
31+
if (lexer->lookahead == '8') {
32+
lexer->advance(lexer, false);
33+
if (lexer->lookahead != 'R') {
34+
return false;
35+
}
36+
} else if (lexer->lookahead != 'R') {
37+
return false;
38+
}
39+
} else if (lexer->lookahead != 'R') {
40+
return false;
41+
}
42+
lexer->advance(lexer, false);
43+
44+
// Consume '"'
45+
if (lexer->lookahead != '"') return false;
46+
lexer->advance(lexer, false);
47+
48+
// Consume '(', delimiter
49+
wstring delimiter;
50+
for (;;) {
51+
if (lexer->lookahead == 0 || lexer->lookahead == '\\' || iswspace(lexer->lookahead)) {
52+
return false;
53+
}
54+
if (lexer->lookahead == '(') {
55+
lexer->advance(lexer, false);
56+
break;
57+
}
58+
delimiter += lexer->lookahead;
59+
lexer->advance(lexer, false);
60+
}
61+
62+
// Consume content, delimiter, ')', '"'
63+
int delimiter_index = -1;
64+
for (;;) {
65+
if (lexer->lookahead == 0) return false;
66+
67+
if (delimiter_index >= 0) {
68+
if (static_cast<unsigned>(delimiter_index) == delimiter.size()) {
69+
if (lexer->lookahead == '"') {
70+
lexer->advance(lexer, false);
71+
return true;
72+
} else {
73+
delimiter_index = -1;
74+
}
75+
} else {
76+
if (lexer->lookahead == delimiter[delimiter_index]) {
77+
delimiter_index++;
78+
} else {
79+
delimiter_index = -1;
80+
}
81+
}
82+
}
83+
84+
if (delimiter_index == -1 && lexer->lookahead == ')') {
85+
delimiter_index = 0;
86+
}
87+
88+
lexer->advance(lexer, false);
89+
}
90+
}
91+
};
92+
93+
}
94+
95+
extern "C" {
96+
97+
void *tree_sitter_cpp_external_scanner_create() {
98+
return new Scanner();
99+
}
100+
101+
bool tree_sitter_cpp_external_scanner_scan(void *payload, TSLexer *lexer,
102+
const bool *valid_symbols) {
103+
Scanner *scanner = static_cast<Scanner *>(payload);
104+
return scanner->scan(lexer, valid_symbols);
105+
}
106+
107+
unsigned tree_sitter_cpp_external_scanner_serialize(void *payload, char *buffer) {
108+
return 0;
109+
}
110+
111+
void tree_sitter_cpp_external_scanner_deserialize(void *payload, const char *buffer, unsigned length) {
112+
}
113+
114+
void tree_sitter_cpp_external_scanner_destroy(void *payload) {
115+
Scanner *scanner = static_cast<Scanner *>(payload);
116+
delete scanner;
117+
}
118+
119+
}

0 commit comments

Comments
 (0)