Skip to content

Commit 6c8329e

Browse files
authored
Merge pull request #148 from tree-sitter/fixes
fix: rework decimal logic to properly parse octal numbers fix: make cast expression values with ampersands stricter
2 parents 7c9964a + 72adb42 commit 6c8329e

File tree

8 files changed

+35542
-34080
lines changed

8 files changed

+35542
-34080
lines changed

.github/workflows/ci.yml

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
1-
name: Build/test
1+
name: CI
2+
23
on:
3-
pull_request:
44
push:
5+
branches:
6+
- master
7+
pull_request:
8+
branches:
9+
- "**"
510

611
jobs:
712
test:

bindings/rust/build.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ fn main() {
55
let src_dir = Path::new("src");
66

77
let mut c_config = cc::Build::new();
8-
c_config.include(&src_dir);
8+
c_config.include(src_dir);
99
c_config
1010
.flag_if_supported("-Wno-unused-parameter")
1111
.flag_if_supported("-Wno-unused-but-set-variable")

bindings/rust/lib.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,18 +46,18 @@ pub fn language() -> Language {
4646
}
4747

4848
/// The source of the Java tree-sitter grammar description.
49-
pub const GRAMMAR: &'static str = include_str!("../../grammar.js");
49+
pub const GRAMMAR: &str = include_str!("../../grammar.js");
5050

5151
/// The syntax highlighting query for this language.
52-
pub const HIGHLIGHT_QUERY: &'static str = include_str!("../../queries/highlights.scm");
52+
pub const HIGHLIGHT_QUERY: &str = include_str!("../../queries/highlights.scm");
5353

5454
/// The content of the [`node-types.json`][] file for this grammar.
5555
///
5656
/// [`node-types.json`]: https://tree-sitter.github.io/tree-sitter/using-parsers#static-node-types
57-
pub const NODE_TYPES: &'static str = include_str!("../../src/node-types.json");
57+
pub const NODE_TYPES: &str = include_str!("../../src/node-types.json");
5858

5959
/// The symbol tagging query for this language.
60-
pub const TAGGING_QUERY: &'static str = include_str!("../../queries/tags.scm");
60+
pub const TAGGING_QUERY: &str = include_str!("../../queries/tags.scm");
6161

6262
#[cfg(test)]
6363
mod tests {

grammar.js

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
const DIGITS = token(sep1(/[0-9]+/, /_+/))
1+
const DIGITS = token(choice('0', seq(/[1-9]/, optional(seq(optional('_'), sep1(/[0-9]+/, /_+/))))))
2+
const DECIMAL_DIGITS = token(sep1(/[0-9]+/, '_'))
23
const HEX_DIGITS = token(sep1(/[A-Fa-f0-9]+/, '_'))
34
const PREC = {
45
// https://introcs.cs.princeton.edu/java/11precedence/
@@ -106,7 +107,7 @@ module.exports = grammar({
106107
)),
107108

108109
octal_integer_literal: $ => token(seq(
109-
choice('0o', '0O'),
110+
choice('0o', '0O', '0'),
110111
sep1(/[0-7]+/, '_'),
111112
optional(choice('l', 'L'))
112113
)),
@@ -118,10 +119,10 @@ module.exports = grammar({
118119
)),
119120

120121
decimal_floating_point_literal: $ => token(choice(
121-
seq(DIGITS, '.', optional(DIGITS), optional(seq((/[eE]/), optional(choice('-', '+')), DIGITS)), optional(/[fFdD]/)),
122-
seq('.', DIGITS, optional(seq((/[eE]/), optional(choice('-', '+')), DIGITS)), optional(/[fFdD]/)),
123-
seq(DIGITS, /[eEpP]/, optional(choice('-', '+')), DIGITS, optional(/[fFdD]/)),
124-
seq(DIGITS, optional(seq((/[eE]/), optional(choice('-', '+')), DIGITS)), (/[fFdD]/))
122+
seq(DECIMAL_DIGITS, '.', optional(DECIMAL_DIGITS), optional(seq((/[eE]/), optional(choice('-', '+')), DECIMAL_DIGITS)), optional(/[fFdD]/)),
123+
seq('.', DECIMAL_DIGITS, optional(seq((/[eE]/), optional(choice('-', '+')), DECIMAL_DIGITS)), optional(/[fFdD]/)),
124+
seq(DIGITS, /[eEpP]/, optional(choice('-', '+')), DECIMAL_DIGITS, optional(/[fFdD]/)),
125+
seq(DIGITS, optional(seq((/[eE]/), optional(choice('-', '+')), DECIMAL_DIGITS)), (/[fFdD]/))
125126
)),
126127

127128
hex_floating_point_literal: $ => token(seq(
@@ -213,11 +214,19 @@ module.exports = grammar({
213214
$.switch_expression,
214215
),
215216

216-
cast_expression: $ => prec(PREC.CAST, seq(
217-
'(',
218-
sep1(field('type', $._type), '&'),
219-
')',
220-
field('value', $.expression)
217+
cast_expression: $ => prec(PREC.CAST, choice(
218+
seq(
219+
'(',
220+
field('type', $._type),
221+
')',
222+
field('value', $.expression),
223+
),
224+
seq(
225+
'(',
226+
sep1(field('type', $._type), '&'),
227+
')',
228+
field('value', choice($.primary_expression, $.lambda_expression)),
229+
),
221230
)),
222231

223232
assignment_expression: $ => prec.right(PREC.ASSIGN, seq(

0 commit comments

Comments
 (0)