value field of declaration node is required in node-types.json but does not exist in parse tree
See original GitHub issueIt is said that value field of declaration node is required in node-types.json. The following code is related part of node-types.json.
{
"type": "declaration",
"named": true,
"fields": {
.....
"value": {
"multiple": false,
"required": true,
"types": [
{
"type": "_expression",
"named": true
},
{
"type": "initializer_list",
"named": true
}
]
},
.....
},
However, value field of declaration node does not exist in the parse tree generated by tree sitter. The parse tree of source code int func();
is,
declaration:
children: [
primitive_tive,
function_declarator,
;
]
...
The field name of primitive_tive
child node is type
and field name of function_declarator
child node is declarator
. However, there is no child node with value
field name.
Issue Analytics
- State:
- Created 3 years ago
- Reactions:1
- Comments:6 (4 by maintainers)
Top Results From Across the Web
thought: using tree-sitter for AST transformation/codegen #642
We do generate JSON "type declarations" for each type of syntax node, in src/node-types.json . Some people have used these to generate code ......
Read more >Using Parsers - Tree-sitter
Tree -sitter makes this information available via a generated file called node-types.json . This node types file provides structured data about every possible ......
Read more >HTML DOM Element nodeType Property - W3Schools
If the node is an element node, the nodeType property will return 1. ... Represents a CDATA section in a document (text that...
Read more >Lezer Reference Manual - CodeMirror
Lezer syntax trees are not abstract, they just tell you which nodes were parsed ... Since there's four values per node, this is...
Read more >Working With JSON (Application Developer's Guide)
MarkLogic Server models JSON documents as a tree of nodes, rooted at a ... means that field value and field range queries do...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Ok, a couple of answers:
The
default_value
field was already correct. Theoperator_cast_declaration
has an optionaldefault_value
field, and as @CamilleTeruel points out, theoperator_cast_declaration
is aliased as adeclaration
in the grammar.This means that at runtime, a syntax node of type
declaration
may have been generated by theoperator_cast_declaration
rule, so it can optionally have adefault_value
field.The
value
field was not correct. It should indeed be present for a similar reason asdefault_value
, but it should haverequired
set tofalse
. Therequired
flag was being computed incorrectly due to a bug in Tree-sitter, which is now fixed in commit https://github.com/tree-sitter/tree-sitter/commit/9d182bb0785f158ba5b6ab14df8fae0eff8aa819. I am publishing a new release of the Tree-sitter CLI and then I will regenerate the node-types.Thanks for the fix @maxbrunsfeld, that was fast!
Oh I see, I was interpreting the aliasing feature the wrong way 😄 (
operator_cast_declaration
nodes with the same fields thandeclaration
plus extra ones).Sure, we use tree-sitter from python. We use
node-type.json
to generate:I guess it is somewhat similar to what
haskell-tree-sitter
/semantic
are doing.