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
8 changes: 4 additions & 4 deletions reprolang/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ deterministic test cases for any SCIP capability.
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.
No keyword needed. To reference a symbol defined in another project, write
the project name followed by the descriptors.
- **Local**: Scoped to a single file. Use the `local` keyword.

## Example
Expand All @@ -34,8 +34,8 @@ reference local myHelper
reference forward_definition abc#
definition abc#

# Cross-repo reference
reference global other-repo animal#
# Cross-repo reference (project name + descriptors)
reference other-repo animal#

# Relationships
definition dog# implements animal#
Expand Down
42 changes: 18 additions & 24 deletions reprolang/grammar.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// Reprolang grammar. See README.md for an overview and ./testdata/snapshots
// for examples.
module.exports = grammar({
name: 'reprolang',
extras: $ => [/\s+/],
Expand All @@ -6,50 +8,42 @@ module.exports = grammar({
rules: {
source_file: $ => repeat($._statement),
_statement: $ =>
seq(
choice(
$.definition_statement,
$.reference_statement,
$.relationships_statement,
$.comment
),
'\n'
choice(
$.definition_statement,
$.reference_statement,
$.relationships_statement,
$.comment
),
definition_statement: $ =>
seq(
field('docstring', optional(seq($.docstring, '\n'))),
field('docstring', optional($.docstring)),
'definition',
field('name', $.identifier),
field('roles', repeat($._definition_relations))
field('relations', repeat($._definition_relations))
),
reference_statement: $ =>
seq(
'reference',
field('forward_definition', optional('forward_definition')),
field('forward_definition', optional($.forward_definition)),
field('name', $.identifier)
),
forward_definition: $ => 'forward_definition',
_definition_relations: $ =>
choice(
$.implementation_relation,
$.type_definition_relation,
$.references_relation
),
implementation_relation: $ =>
seq('implements', field('name', $.identifier)),
type_definition_relation: $ =>
seq('type_defines', field('name', $.identifier)),
references_relation: $ => seq('references', field('name', $.identifier)),
choice($.implements, $.type_defines, $.references),
implements: $ => seq('implements', field('name', $.identifier)),
type_defines: $ => seq('type_defines', field('name', $.identifier)),
references: $ => seq('references', field('name', $.identifier)),
// Meant to be used primarily when trying to construct indexes with
// relationships for symbols which lack a definition themselves,
// and are defined by some other symbol.
relationships_statement: $ =>
seq(
'relationships',
field('name', $.identifier),
field('roles', repeat($._all_relations))
field('relations', repeat($._all_relations))
),
_all_relations: $ => choice($._definition_relations, $.defined_by_relation),
defined_by_relation: $ => seq('defined_by', field('name', $.identifier)),
_all_relations: $ => choice($._definition_relations, $.defined_by),
defined_by: $ => seq('defined_by', field('name', $.identifier)),
comment: $ => seq('#', /.*/),
docstring: $ => seq('# docstring:', /.*/),
identifier: $ =>
Expand Down
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 (name)) roles: (implementation_relation name: (identifier (name)))))",
"(source_file (definition_statement name: (identifier (name)) relations: (implements name: (identifier (name)))))",
tree.RootNode().ToSexp(),
)
}
76 changes: 31 additions & 45 deletions reprolang/grammar/grammar.json

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

40 changes: 16 additions & 24 deletions reprolang/grammar/node-types.json

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

Loading