aboutsummaryrefslogtreecommitdiff
path: root/crates/libsyntax2
diff options
context:
space:
mode:
Diffstat (limited to 'crates/libsyntax2')
-rw-r--r--crates/libsyntax2/src/grammar.ron5
-rw-r--r--crates/libsyntax2/src/grammar/expressions/mod.rs54
-rw-r--r--crates/libsyntax2/src/parser_api.rs8
-rw-r--r--crates/libsyntax2/src/parser_impl/mod.rs25
-rw-r--r--crates/libsyntax2/src/syntax_kinds/generated.rs10
5 files changed, 63 insertions, 39 deletions
diff --git a/crates/libsyntax2/src/grammar.ron b/crates/libsyntax2/src/grammar.ron
index daf80dde3..2cec5b3e3 100644
--- a/crates/libsyntax2/src/grammar.ron
+++ b/crates/libsyntax2/src/grammar.ron
@@ -41,6 +41,11 @@ Grammar(
41 [">=", "GTEQ"], 41 [">=", "GTEQ"],
42 ["+=", "PLUSEQ"], 42 ["+=", "PLUSEQ"],
43 ["-=", "MINUSEQ"], 43 ["-=", "MINUSEQ"],
44 ["|=", "PIPEEQ"],
45 ["&=", "AMPEQ"],
46 ["^=", "CARETEQ"],
47 ["/=", "SLASHEQ"],
48 ["*=", "STAREQ"],
44 ["&&", "AMPAMP"], 49 ["&&", "AMPAMP"],
45 ["||", "PIPEPIPE"], 50 ["||", "PIPEPIPE"],
46 ["<<", "SHL"], 51 ["<<", "SHL"],
diff --git a/crates/libsyntax2/src/grammar/expressions/mod.rs b/crates/libsyntax2/src/grammar/expressions/mod.rs
index feef5f1d6..3da539699 100644
--- a/crates/libsyntax2/src/grammar/expressions/mod.rs
+++ b/crates/libsyntax2/src/grammar/expressions/mod.rs
@@ -45,35 +45,33 @@ enum Op {
45} 45}
46 46
47fn current_op(p: &Parser) -> (u8, Op) { 47fn current_op(p: &Parser) -> (u8, Op) {
48 if p.at_compound2(PLUS, EQ) { 48 if let Some(t) = p.next3() {
49 return (1, Op::Composite(PLUSEQ, 2)); 49 match t {
50 } 50 (L_ANGLE, L_ANGLE, EQ) =>
51 if p.at_compound2(MINUS, EQ) { 51 return (1, Op::Composite(SHLEQ, 3)),
52 return (1, Op::Composite(MINUSEQ, 2)); 52 (R_ANGLE, R_ANGLE, EQ) =>
53 } 53 return (1, Op::Composite(SHREQ, 3)),
54 if p.at_compound3(L_ANGLE, L_ANGLE, EQ) { 54 _ => (),
55 return (1, Op::Composite(SHLEQ, 3)); 55 }
56 }
57 if p.at_compound3(R_ANGLE, R_ANGLE, EQ) {
58 return (1, Op::Composite(SHREQ, 3));
59 }
60 if p.at_compound2(PIPE, PIPE) {
61 return (3, Op::Composite(PIPEPIPE, 2));
62 }
63 if p.at_compound2(AMP, AMP) {
64 return (4, Op::Composite(AMPAMP, 2));
65 }
66 if p.at_compound2(L_ANGLE, EQ) {
67 return (5, Op::Composite(LTEQ, 2));
68 }
69 if p.at_compound2(R_ANGLE, EQ) {
70 return (5, Op::Composite(GTEQ, 2));
71 }
72 if p.at_compound2(L_ANGLE, L_ANGLE) {
73 return (9, Op::Composite(SHL, 2));
74 } 56 }
75 if p.at_compound2(R_ANGLE, R_ANGLE) { 57
76 return (9, Op::Composite(SHR, 2)); 58 if let Some(t) = p.next2() {
59 match t {
60 (PLUS, EQ) => return (1, Op::Composite(PLUSEQ, 2)),
61 (MINUS, EQ) => return (1, Op::Composite(MINUSEQ, 2)),
62 (STAR, EQ) => return (1, Op::Composite(STAREQ, 2)),
63 (SLASH, EQ) => return (1, Op::Composite(SLASHEQ, 2)),
64 (PIPE, EQ) => return (1, Op::Composite(PIPEEQ, 2)),
65 (AMP, EQ) => return (1, Op::Composite(AMPEQ, 2)),
66 (CARET, EQ) => return (1, Op::Composite(CARETEQ, 2)),
67 (PIPE, PIPE) => return (3, Op::Composite(PIPEPIPE, 2)),
68 (AMP, AMP) => return (4, Op::Composite(AMPAMP, 2)),
69 (L_ANGLE, EQ) => return (5, Op::Composite(LTEQ, 2)),
70 (R_ANGLE, EQ) => return (5, Op::Composite(GTEQ, 2)),
71 (L_ANGLE, L_ANGLE) => return (9, Op::Composite(SHL, 2)),
72 (R_ANGLE, R_ANGLE) => return (9, Op::Composite(SHR, 2)),
73 _ => (),
74 }
77 } 75 }
78 76
79 let bp = match p.current() { 77 let bp = match p.current() {
diff --git a/crates/libsyntax2/src/parser_api.rs b/crates/libsyntax2/src/parser_api.rs
index c78c6e43a..bb34fe973 100644
--- a/crates/libsyntax2/src/parser_api.rs
+++ b/crates/libsyntax2/src/parser_api.rs
@@ -68,12 +68,12 @@ impl<'t> Parser<'t> {
68 self.current() == kind 68 self.current() == kind
69 } 69 }
70 70
71 pub(crate) fn at_compound2(&self, c1: SyntaxKind, c2: SyntaxKind) -> bool { 71 pub(crate) fn next2(&self) -> Option<(SyntaxKind, SyntaxKind)> {
72 self.0.at_compound2(c1, c2) 72 self.0.next2()
73 } 73 }
74 74
75 pub(crate) fn at_compound3(&self, c1: SyntaxKind, c2: SyntaxKind, c3: SyntaxKind) -> bool { 75 pub(crate) fn next3(&self) -> Option<(SyntaxKind, SyntaxKind, SyntaxKind)> {
76 self.0.at_compound3(c1, c2, c3) 76 self.0.next3()
77 } 77 }
78 78
79 /// Checks if the current token is contextual keyword with text `t`. 79 /// Checks if the current token is contextual keyword with text `t`.
diff --git a/crates/libsyntax2/src/parser_impl/mod.rs b/crates/libsyntax2/src/parser_impl/mod.rs
index 06c16cdb4..14cceced5 100644
--- a/crates/libsyntax2/src/parser_impl/mod.rs
+++ b/crates/libsyntax2/src/parser_impl/mod.rs
@@ -65,15 +65,26 @@ impl<'t> ParserImpl<'t> {
65 self.events 65 self.events
66 } 66 }
67 67
68 pub(super) fn at_compound2(&self, c1: SyntaxKind, c2: SyntaxKind) -> bool { 68 pub(super) fn next2(&self) -> Option<(SyntaxKind, SyntaxKind)> {
69 self.inp.kind(self.pos) == c1 && self.inp.kind(self.pos + 1) == c2 69 let c1 = self.inp.kind(self.pos);
70 && self.inp.start(self.pos + 1) == self.inp.start(self.pos) + self.inp.len(self.pos) 70 let c2 = self.inp.kind(self.pos + 1);
71 if self.inp.start(self.pos + 1) == self.inp.start(self.pos) + self.inp.len(self.pos) {
72 Some((c1, c2))
73 } else {
74 None
75 }
71 } 76 }
72 77
73 pub(super) fn at_compound3(&self, c1: SyntaxKind, c2: SyntaxKind, c3: SyntaxKind) -> bool { 78 pub(super) fn next3(&self) -> Option<(SyntaxKind, SyntaxKind, SyntaxKind)> {
74 self.inp.kind(self.pos) == c1 && self.inp.kind(self.pos + 1) == c2 && self.inp.kind(self.pos + 2) == c3 79 let c1 = self.inp.kind(self.pos);
75 && self.inp.start(self.pos + 1) == self.inp.start(self.pos) + self.inp.len(self.pos) 80 let c2 = self.inp.kind(self.pos + 1);
76 && self.inp.start(self.pos + 2) == self.inp.start(self.pos + 1) + self.inp.len(self.pos + 1) 81 let c3 = self.inp.kind(self.pos + 2);
82 if self.inp.start(self.pos + 1) == self.inp.start(self.pos) + self.inp.len(self.pos)
83 && self.inp.start(self.pos + 2) == self.inp.start(self.pos + 1) + self.inp.len(self.pos + 1){
84 Some((c1, c2, c3))
85 } else {
86 None
87 }
77 } 88 }
78 89
79 pub(super) fn nth(&self, n: u32) -> SyntaxKind { 90 pub(super) fn nth(&self, n: u32) -> SyntaxKind {
diff --git a/crates/libsyntax2/src/syntax_kinds/generated.rs b/crates/libsyntax2/src/syntax_kinds/generated.rs
index b04dfe55c..fc387c93d 100644
--- a/crates/libsyntax2/src/syntax_kinds/generated.rs
+++ b/crates/libsyntax2/src/syntax_kinds/generated.rs
@@ -50,6 +50,11 @@ pub enum SyntaxKind {
50 GTEQ, 50 GTEQ,
51 PLUSEQ, 51 PLUSEQ,
52 MINUSEQ, 52 MINUSEQ,
53 PIPEEQ,
54 AMPEQ,
55 CARETEQ,
56 SLASHEQ,
57 STAREQ,
53 AMPAMP, 58 AMPAMP,
54 PIPEPIPE, 59 PIPEPIPE,
55 SHL, 60 SHL,
@@ -288,6 +293,11 @@ impl SyntaxKind {
288 GTEQ => &SyntaxInfo { name: "GTEQ" }, 293 GTEQ => &SyntaxInfo { name: "GTEQ" },
289 PLUSEQ => &SyntaxInfo { name: "PLUSEQ" }, 294 PLUSEQ => &SyntaxInfo { name: "PLUSEQ" },
290 MINUSEQ => &SyntaxInfo { name: "MINUSEQ" }, 295 MINUSEQ => &SyntaxInfo { name: "MINUSEQ" },
296 PIPEEQ => &SyntaxInfo { name: "PIPEEQ" },
297 AMPEQ => &SyntaxInfo { name: "AMPEQ" },
298 CARETEQ => &SyntaxInfo { name: "CARETEQ" },
299 SLASHEQ => &SyntaxInfo { name: "SLASHEQ" },
300 STAREQ => &SyntaxInfo { name: "STAREQ" },
291 AMPAMP => &SyntaxInfo { name: "AMPAMP" }, 301 AMPAMP => &SyntaxInfo { name: "AMPAMP" },
292 PIPEPIPE => &SyntaxInfo { name: "PIPEPIPE" }, 302 PIPEPIPE => &SyntaxInfo { name: "PIPEPIPE" },
293 SHL => &SyntaxInfo { name: "SHL" }, 303 SHL => &SyntaxInfo { name: "SHL" },