Skip to content
Merged
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
12 changes: 6 additions & 6 deletions reprolang/.gitattributes
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
src/grammar.json linguist-generated=true
src/node-types.json linguist-generated=true
src/parser.c linguist-generated=true
src/tree_sitter/alloc.h linguist-generated=true
src/tree_sitter/array.h linguist-generated=true
src/tree_sitter/parser.h linguist-generated=true
grammar/grammar.json linguist-generated=true
grammar/node-types.json linguist-generated=true
grammar/parser.c linguist-generated=true
grammar/tree_sitter/alloc.h linguist-generated=true
grammar/tree_sitter/array.h linguist-generated=true
grammar/tree_sitter/parser.h linguist-generated=true
15 changes: 14 additions & 1 deletion reprolang/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,26 @@ relationships between them. The indexer parses these files with a tree-sitter
grammar and emits a complete SCIP index, making it possible to write concise,
deterministic test cases for any SCIP capability.

## Symbol scoping

Reprolang supports two levels of symbol scope:

- **Global** (default): Visible across all files in the same project.
No keyword needed. Use the `global` keyword with a project name and
descriptors to reference symbols from an external project/dependency.
- **Local**: Scoped to a single file. Use the `local` keyword.

## Example

```
# Define a symbol and reference it
# Define a global symbol and reference it
definition hello().
reference hello().

# Local symbol (file-scoped)
definition local myHelper
reference local myHelper

# Forward reference (reference before definition)
reference forward_definition abc#
definition abc#
Expand Down
14 changes: 6 additions & 8 deletions reprolang/grammar.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
module.exports = grammar({
name: 'reprolang',
extras: $ => [/\s+/],
word: $ => $.workspace_identifier,
word: $ => $.name,

rules: {
source_file: $ => repeat($._statement),
Expand Down Expand Up @@ -54,15 +54,13 @@ module.exports = grammar({
docstring: $ => seq('# docstring:', /.*/),
identifier: $ =>
choice(
field('local', $.local_identifier),
field('global', $.global_identifier),
field('workspace', $.workspace_identifier)
$.name
),
local_identifier: $ => seq('local', field('name', $.name)),
global_identifier: $ =>
seq(
'global',
field('project_name', $.workspace_identifier),
field('descriptors', $.workspace_identifier)
),
workspace_identifier: $ => /[^\s]+/,
seq(field('project_name', $.name), field('descriptors', $.name)),
name: $ => /[^\s]+/,
},
})
2 changes: 1 addition & 1 deletion reprolang/grammar/binding_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ func TestParse(t *testing.T) {
tree := parser.Parse([]byte("definition a implements b\n"), nil)
defer tree.Close()
assert.Equal(
"(source_file (definition_statement name: (identifier workspace: (workspace_identifier)) roles: (implementation_relation name: (identifier workspace: (workspace_identifier)))))",
"(source_file (definition_statement name: (identifier (name)) roles: (implementation_relation name: (identifier (name)))))",
tree.RootNode().ToSexp(),
)
}
37 changes: 27 additions & 10 deletions reprolang/grammar/grammar.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

46 changes: 36 additions & 10 deletions reprolang/grammar/node-types.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading