Skip to content

Commit

Permalink
✨ feat: Add lbracket, rbracket, lbrace, rbrace to tokens
Browse files Browse the repository at this point in the history
  • Loading branch information
caoccao committed Mar 22, 2024
1 parent 1e85efb commit 14e4903
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 0 deletions.
4 changes: 4 additions & 0 deletions rust/src/ast_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -394,6 +394,10 @@ pub fn token_and_spans_to_java_list<'local>(
Token::Bang => java_ast_token_factory.create_generic_operator(env, AstTokenType::Bang, index_range),
Token::LParen => java_ast_token_factory.create_generic_operator(env, AstTokenType::LParen, index_range),
Token::RParen => java_ast_token_factory.create_generic_operator(env, AstTokenType::RParen, index_range),
Token::LBracket => java_ast_token_factory.create_generic_operator(env, AstTokenType::LBracket, index_range),
Token::RBracket => java_ast_token_factory.create_generic_operator(env, AstTokenType::RBracket, index_range),
Token::LBrace => java_ast_token_factory.create_generic_operator(env, AstTokenType::LBrace, index_range),
Token::RBrace => java_ast_token_factory.create_generic_operator(env, AstTokenType::RBrace, index_range),
_ => java_ast_token_factory.create_unknown(env, &text, index_range),
};
java_array_list.add(env, &list, &ast_token);
Expand Down
12 changes: 12 additions & 0 deletions rust/src/enums.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,10 @@ pub enum AstTokenType {
Bang, // 46
LParen, // 47
RParen, // 48
LBracket, // 49
RBracket, // 50
LBrace, // 51
RBrace, // 52
}

impl IdentifiableEnum<AstTokenType> for AstTokenType {
Expand Down Expand Up @@ -134,6 +138,10 @@ impl IdentifiableEnum<AstTokenType> for AstTokenType {
AstTokenType::Bang => 46,
AstTokenType::LParen => 47,
AstTokenType::RParen => 48,
AstTokenType::LBracket => 49,
AstTokenType::RBracket => 50,
AstTokenType::LBrace => 51,
AstTokenType::RBrace => 52,
_ => 0,
}
}
Expand Down Expand Up @@ -187,6 +195,10 @@ impl IdentifiableEnum<AstTokenType> for AstTokenType {
46 => AstTokenType::Bang,
47 => AstTokenType::LParen,
48 => AstTokenType::RParen,
49 => AstTokenType::LBracket,
50 => AstTokenType::RBracket,
51 => AstTokenType::LBrace,
52 => AstTokenType::RBrace,
_ => AstTokenType::Unknown,
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,10 @@ public enum Swc4jAstTokenType {
Bang(46, "!", false, true),
LParen(47, "(", false, true),
RParen(48, ")", false, true),
LBracket(49, "[", false, true),
RBracket(50, "]", false, true),
LBrace(51, "{", false, true),
RBrace(52, "}", false, true),
;

private static final int LENGTH = values().length;
Expand Down
4 changes: 4 additions & 0 deletions src/test/java/com/caoccao/javet/swc4j/TestSwc4j.java
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,10 @@ public void testParseTypeScriptWithCaptureTokens() throws Swc4jCoreException {
parseAndAssert("!true", options, Swc4jAstTokenType.Bang, "!", 0, 1, 0, 2);
parseAndAssert("a()", options, Swc4jAstTokenType.LParen, "(", 1, 2, 1, 3);
parseAndAssert("a()", options, Swc4jAstTokenType.RParen, ")", 2, 3, 2, 3);
parseAndAssert("a[0]", options, Swc4jAstTokenType.LBracket, "[", 1, 2, 1, 4);
parseAndAssert("a[0]", options, Swc4jAstTokenType.RBracket, "]", 3, 4, 3, 4);
parseAndAssert("a={}", options, Swc4jAstTokenType.LBrace, "{", 2, 3, 2, 4);
parseAndAssert("a={}", options, Swc4jAstTokenType.RBrace, "}", 3, 4, 3, 4);
}

@Test
Expand Down

0 comments on commit 14e4903

Please sign in to comment.