Skip to content
This repository has been archived by the owner on Jun 3, 2022. It is now read-only.

feat(string_content): add string_content child node to non-emtpy string nodes #8

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions corpus/comments.txt
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,13 @@ Comments
(comment)

(comment)
(expression (string))
(expression (string (string_content)))
(comment)

(comment)

(comment)

(comment)
(expression (string))
(expression (string (string_content)))
(comment))
12 changes: 6 additions & 6 deletions corpus/expressions.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ local games = {
(program
(variable_declaration (variable_declarator (identifier))
(table
(field (string)
(field (string (string_content))
(table
(field (string) (true))
(field (string (string_content)) (true))
(field (identifier) (false))))))

(local_variable_declaration (variable_declarator (identifier))
Expand All @@ -31,10 +31,10 @@ local games = {
(table
(field
(table
(field (string))
(field (string))
(field (string))
(field (string)))))))))
(field (string (string_content)))
(field (string (string_content)))
(field (string (string_content)))
(field (string (string_content))))))))))

============================================
Binary operations
Expand Down
6 changes: 3 additions & 3 deletions corpus/functions.txt
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ a.b.f = function(self, test, ...) return 10 end

(variable_declaration (variable_declarator (identifier))
(function_definition (parameters)
(return_statement (string))))
(return_statement (string (string_content)))))

(variable_declaration (variable_declarator
(field_expression (field_expression (identifier) (property_identifier)) (property_identifier)))
Expand Down Expand Up @@ -77,12 +77,12 @@ f = function() return 'some string' end

(program
(local_function (identifier) (parameters)
(return_statement (string)))
(return_statement (string (string_content))))

(local_variable_declaration (variable_declarator (identifier)))
(variable_declaration (variable_declarator (identifier))
(function_definition (parameters)
(return_statement (string)))))
(return_statement (string (string_content))))))

============================================
Function calls
Expand Down
46 changes: 41 additions & 5 deletions corpus/primitives.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,25 +15,61 @@ a level 2 long literal string
with double brackets [[ a level 0 string completely ignored ]]
]==]

[===[
a level 3 long literal string
with level 1 brackets inside [=[ a level 1 string completely ignored ]=]
]===]

"a string with comment token inside -> -- disabled comment"

[[
a level 0 long literal string with comment token inside -> -- disabled comment
]]

[=[[a level 1 long literal string with brackets surrounding content]]=]

[=[]]=]

---

(program
(expression (string (string_content)))
(expression (string (string_content)))

(expression (string (string_content)))

(expression (string (string_content)))

(expression (string (string_content)))

(expression (string (string_content)))

(expression (string (string_content)))

(expression (string (string_content)))

(expression (string (string_content)))
)

============================================
Literam empty strings (short/long)
============================================

''
""
[[]]
[=[]=]
[====[]====]

---

(program
(expression (string))
(expression (string))

(expression (string))

(expression (string))

(expression (string))

(expression (string)))
)

============================================
Numeric constants
Expand Down
16 changes: 8 additions & 8 deletions corpus/statements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,10 @@ end
(if_statement
(condition_expression (binary_operation (identifier) (number)))
(function_call (identifier)
(arguments (string)))
(elseif (condition_expression (binary_operation (identifier) (string)))
(arguments (string (string_content))))
(elseif (condition_expression (binary_operation (identifier) (string (string_content))))
(function_call (field_expression (identifier) (property_identifier))
(arguments (string))))
(arguments (string (string_content)))))
(else
(variable_declaration (variable_declarator (identifier)) (number))

Expand All @@ -71,7 +71,7 @@ end
(arguments)))

(function_call (identifier)
(arguments (binary_operation (string) (identifier)))))))
(arguments (binary_operation (string (string_content)) (identifier)))))))

============================================
While statements
Expand Down Expand Up @@ -103,7 +103,7 @@ until num == 0

(program
(repeat_statement
(function_call (identifier) (arguments (string)))
(function_call (identifier) (arguments (string (string_content))))
(variable_declaration (variable_declarator (identifier))
(binary_operation (identifier) (number)))
(condition_expression (binary_operation (identifier) (number)))))
Expand Down Expand Up @@ -141,7 +141,7 @@ end
(binary_operation (identifier) (identifier))))

(variable_declaration (variable_declarator (identifier))
(table (field (string)) (field (string)) (field (number)) (field (string))))
(table (field (string (string_content))) (field (string (string_content))) (field (number)) (field (string (string_content)))))
(for_statement (loop_expression (identifier) (number) (unary_operation (identifier)))
(function_call (identifier) (arguments (identifier) (identifier)))))

Expand All @@ -166,10 +166,10 @@ end
(program
(for_in_statement (loop_expression (identifier) (identifier) (function_call (identifier) (arguments (identifier))))
(function_call (identifier) (arguments (identifier) (identifier))))

(for_in_statement (loop_expression (identifier) (identifier) (function_call (identifier) (arguments (identifier))))
(function_call (identifier) (arguments (identifier) (identifier))))

(for_in_statement (loop_expression (identifier) (identifier) (next) (identifier))
(function_call (identifier) (arguments (identifier) (identifier)))))

Expand Down
10 changes: 9 additions & 1 deletion grammar.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,9 @@ module.exports = grammar({

externals: $ => [
$.comment,
$.string
$._string_start,
$.string_content,
$._string_end,
],

rules: {
Expand Down Expand Up @@ -364,6 +366,12 @@ module.exports = grammar({
)),

// Expressions: Primitives
string: $ => seq(
alias($._string_start, '"'),
optional($.string_content),
alias($._string_end, '"'),
),

number: $ => {
const decimal_digits = /[0-9]+/
const signed_integer = seq(optional(choice('-', '+')), decimal_digits)
Expand Down
45 changes: 44 additions & 1 deletion src/grammar.json
Original file line number Diff line number Diff line change
Expand Up @@ -1965,6 +1965,41 @@
]
}
},
"string": {
"type": "SEQ",
"members": [
{
"type": "ALIAS",
"content": {
"type": "SYMBOL",
"name": "_string_start"
},
"named": false,
"value": "\""
},
{
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "string_content"
},
{
"type": "BLANK"
}
]
},
{
"type": "ALIAS",
"content": {
"type": "SYMBOL",
"name": "_string_end"
},
"named": false,
"value": "\""
}
]
},
"number": {
"type": "TOKEN",
"content": {
Expand Down Expand Up @@ -2420,7 +2455,15 @@
},
{
"type": "SYMBOL",
"name": "string"
"name": "_string_start"
},
{
"type": "SYMBOL",
"name": "string_content"
},
{
"type": "SYMBOL",
"name": "_string_end"
}
],
"inline": [
Expand Down
21 changes: 20 additions & 1 deletion src/node-types.json
Original file line number Diff line number Diff line change
Expand Up @@ -1749,6 +1749,21 @@
]
}
},
{
"type": "string",
"named": true,
"fields": {},
"children": {
"multiple": false,
"required": false,
"types": [
{
"type": "string_content",
"named": true
}
]
}
},
{
"type": "table",
"named": true,
Expand Down Expand Up @@ -2072,6 +2087,10 @@
]
}
},
{
"type": "\"",
"named": false
},
{
"type": "#",
"named": false
Expand Down Expand Up @@ -2297,7 +2316,7 @@
"named": true
},
{
"type": "string",
"type": "string_content",
"named": true
},
{
Expand Down
Loading