Add single quoted strings and regexes to javascript grammar
This commit is contained in:
parent
6d40dcf881
commit
a2c125998e
4 changed files with 10956 additions and 10884 deletions
|
|
@ -79,7 +79,14 @@ namespace tree_sitter_examples {
|
|||
sym("ternary"),
|
||||
sym("math_op"),
|
||||
sym("bool_op"),
|
||||
sym("literal"),
|
||||
sym("object"),
|
||||
sym("array"),
|
||||
sym("regex"),
|
||||
sym("string"),
|
||||
sym("number"),
|
||||
sym("true"),
|
||||
sym("false"),
|
||||
sym("null"),
|
||||
sym("identifier"),
|
||||
in_parens(sym("expression")) }) },
|
||||
{ "math_op", choice({
|
||||
|
|
@ -125,14 +132,6 @@ namespace tree_sitter_examples {
|
|||
sym("identifier") }),
|
||||
in_brackets(sym("expression")) }) }) },
|
||||
{ "formal_parameters", in_parens(comma_sep(sym("identifier"))) },
|
||||
{ "literal", choice({
|
||||
sym("object"),
|
||||
sym("array"),
|
||||
sym("string"),
|
||||
sym("number"),
|
||||
sym("true"),
|
||||
sym("false"),
|
||||
sym("null"), }) },
|
||||
|
||||
// Literals
|
||||
{ "object", in_braces(comma_sep(err(seq({
|
||||
|
|
@ -159,7 +158,19 @@ namespace tree_sitter_examples {
|
|||
|
||||
{ "comment", pattern("//[^\n]*") },
|
||||
{ "_terminator", pattern("[;\n]") },
|
||||
{ "string", pattern("\"([^\"]|\\\\\")+\"") },
|
||||
{ "regex", token(seq({
|
||||
str("/"),
|
||||
pattern("([^/]|\\\\/)+"),
|
||||
str("/") })) },
|
||||
{ "string", token(choice({
|
||||
seq({
|
||||
str("\""),
|
||||
pattern("([^\"]|\\\\\")+"),
|
||||
str("\"") }),
|
||||
seq({
|
||||
str("'"),
|
||||
pattern("([^\']|\\\\\')+"),
|
||||
str("'") }) })) },
|
||||
{ "identifier", pattern("[\\a_$][\\w_$]*") },
|
||||
{ "number", pattern("\\d+(\\.\\d+)?") },
|
||||
});
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load diff
|
|
@ -1,3 +1,22 @@
|
|||
==========================================
|
||||
parses literals
|
||||
==========================================
|
||||
theFunction(
|
||||
100.0,
|
||||
200,
|
||||
/the-regex/,
|
||||
'the-single-quoted-string',
|
||||
"the-double-quoted-string"
|
||||
);
|
||||
---
|
||||
(program (expression_statement (function_call
|
||||
(identifier)
|
||||
(number)
|
||||
(number)
|
||||
(regex)
|
||||
(string)
|
||||
(string))))
|
||||
|
||||
==========================================
|
||||
parses multiple statements
|
||||
==========================================
|
||||
|
|
|
|||
|
|
@ -51,6 +51,8 @@ namespace tree_sitter {
|
|||
return "\\0";
|
||||
case '"':
|
||||
return "\\\"";
|
||||
case '\'':
|
||||
return "\\'";
|
||||
case '\n':
|
||||
return "\\n";
|
||||
case '\r':
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue