Skip to content

Commit

Permalink
specialized labels into either definition or declaration; allowed pro…
Browse files Browse the repository at this point in the history
…perty declarations to be any value (which may be a singleton type occupied by that value)
  • Loading branch information
akollegger committed Oct 1, 2024
1 parent d4ba7a6 commit 7a13ddb
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 15 deletions.
8 changes: 6 additions & 2 deletions gram.ne
Original file line number Diff line number Diff line change
Expand Up @@ -69,15 +69,19 @@ Attributes -> Identity:? Labels:? Record:?

Identity -> Value

Labels -> (":" Label):+
Labels -> (DeclaredLabels | DefinedLabels)

DeclaredLabels -> (Declare Label):+

DefinedLabels -> (Define Label):+

Label -> Symbol

Record ->
"{" _ "}" _
| "{" _ Property ("," _ Property ):* "}" _

Property -> Symbol _ (Declare _ Symbol | Define _ Value)
Property -> Symbol _ (Declare | Define ) _ Value

Declare -> "::"

Expand Down
34 changes: 21 additions & 13 deletions src/lib/generated-grammar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,17 +138,17 @@ const grammar: Grammar = {
{"name": "Pattern$ebnf$1$subexpression$1", "symbols": ["_", {"literal":","}, "_", "PatternElement"]},
{"name": "Pattern$ebnf$1", "symbols": ["Pattern$ebnf$1", "Pattern$ebnf$1$subexpression$1"], "postprocess": (d) => d[0].concat([d[1]])},
{"name": "Pattern", "symbols": ["PatternElement", "Pattern$ebnf$1"]},
{"name": "PatternElement$ebnf$1", "symbols": []},
{"name": "PatternElement$ebnf$1$subexpression$1", "symbols": ["Annotation", "_"]},
{"name": "PatternElement$ebnf$1", "symbols": ["PatternElement$ebnf$1$subexpression$1"], "postprocess": id},
{"name": "PatternElement$ebnf$1", "symbols": [], "postprocess": () => null},
{"name": "PatternElement$ebnf$1", "symbols": ["PatternElement$ebnf$1", "PatternElement$ebnf$1$subexpression$1"], "postprocess": (d) => d[0].concat([d[1]])},
{"name": "PatternElement$subexpression$1", "symbols": ["Subject"]},
{"name": "PatternElement$subexpression$1", "symbols": ["Path"]},
{"name": "PatternElement", "symbols": ["PatternElement$ebnf$1", "PatternElement$subexpression$1"]},
{"name": "Subject$ebnf$1", "symbols": ["Association"], "postprocess": id},
{"name": "Subject$ebnf$1", "symbols": [], "postprocess": () => null},
{"name": "Subject", "symbols": [{"literal":"["}, "_", "Attributes", "_", "Subject$ebnf$1", {"literal":"]"}]},
{"name": "Association", "symbols": ["Membership", "_", "IndividualMembers"]},
{"name": "Association", "symbols": ["Composition", "_", "PairedMembers"]},
{"name": "Association", "symbols": ["Ordering", "_", "PairedMembers"]},
{"name": "IndividualMembers$ebnf$1", "symbols": []},
{"name": "IndividualMembers$ebnf$1$subexpression$1", "symbols": ["_", {"literal":","}, "_", "AssociationMember"]},
{"name": "IndividualMembers$ebnf$1", "symbols": ["IndividualMembers$ebnf$1", "IndividualMembers$ebnf$1$subexpression$1"], "postprocess": (d) => d[0].concat([d[1]])},
Expand All @@ -163,8 +163,8 @@ const grammar: Grammar = {
{"name": "AssociationMember", "symbols": ["AssociationMember$subexpression$1"]},
{"name": "Reference", "symbols": ["Identity"]},
{"name": "Membership", "symbols": [{"literal":"|"}]},
{"name": "Composition$string$1", "symbols": [{"literal":"-"}, {"literal":">"}], "postprocess": (d) => d.join('')},
{"name": "Composition", "symbols": ["Composition$string$1"]},
{"name": "Ordering$string$1", "symbols": [{"literal":"-"}, {"literal":">"}], "postprocess": (d) => d.join('')},
{"name": "Ordering", "symbols": ["Ordering$string$1"]},
{"name": "Containment", "symbols": [{"literal":"^"}, "_", "Symbol", "_", {"literal":"^"}]},
{"name": "Path", "symbols": ["Node"]},
{"name": "Path", "symbols": ["Relationship"]},
Expand Down Expand Up @@ -226,20 +226,28 @@ const grammar: Grammar = {
{"name": "Attributes$ebnf$3", "symbols": [], "postprocess": () => null},
{"name": "Attributes", "symbols": ["Attributes$ebnf$1", "Attributes$ebnf$2", "Attributes$ebnf$3"]},
{"name": "Identity", "symbols": ["Value"]},
{"name": "Labels$ebnf$1$subexpression$1", "symbols": [{"literal":":"}, "Label"]},
{"name": "Labels$ebnf$1", "symbols": ["Labels$ebnf$1$subexpression$1"]},
{"name": "Labels$ebnf$1$subexpression$2", "symbols": [{"literal":":"}, "Label"]},
{"name": "Labels$ebnf$1", "symbols": ["Labels$ebnf$1", "Labels$ebnf$1$subexpression$2"], "postprocess": (d) => d[0].concat([d[1]])},
{"name": "Labels", "symbols": ["Labels$ebnf$1"]},
{"name": "Labels$subexpression$1", "symbols": ["DeclaredLabels"]},
{"name": "Labels$subexpression$1", "symbols": ["DefinedLabels"]},
{"name": "Labels", "symbols": ["Labels$subexpression$1"]},
{"name": "DeclaredLabels$ebnf$1$subexpression$1", "symbols": ["Declare", "Label"]},
{"name": "DeclaredLabels$ebnf$1", "symbols": ["DeclaredLabels$ebnf$1$subexpression$1"]},
{"name": "DeclaredLabels$ebnf$1$subexpression$2", "symbols": ["Declare", "Label"]},
{"name": "DeclaredLabels$ebnf$1", "symbols": ["DeclaredLabels$ebnf$1", "DeclaredLabels$ebnf$1$subexpression$2"], "postprocess": (d) => d[0].concat([d[1]])},
{"name": "DeclaredLabels", "symbols": ["DeclaredLabels$ebnf$1"]},
{"name": "DefinedLabels$ebnf$1$subexpression$1", "symbols": ["Define", "Label"]},
{"name": "DefinedLabels$ebnf$1", "symbols": ["DefinedLabels$ebnf$1$subexpression$1"]},
{"name": "DefinedLabels$ebnf$1$subexpression$2", "symbols": ["Define", "Label"]},
{"name": "DefinedLabels$ebnf$1", "symbols": ["DefinedLabels$ebnf$1", "DefinedLabels$ebnf$1$subexpression$2"], "postprocess": (d) => d[0].concat([d[1]])},
{"name": "DefinedLabels", "symbols": ["DefinedLabels$ebnf$1"]},
{"name": "Label", "symbols": ["Symbol"]},
{"name": "Record", "symbols": [{"literal":"{"}, "_", {"literal":"}"}, "_"]},
{"name": "Record$ebnf$1", "symbols": []},
{"name": "Record$ebnf$1$subexpression$1", "symbols": [{"literal":","}, "_", "Property"]},
{"name": "Record$ebnf$1", "symbols": ["Record$ebnf$1", "Record$ebnf$1$subexpression$1"], "postprocess": (d) => d[0].concat([d[1]])},
{"name": "Record", "symbols": [{"literal":"{"}, "_", "Property", "Record$ebnf$1", {"literal":"}"}, "_"]},
{"name": "Property$subexpression$1", "symbols": ["Declare", "_", "Symbol"]},
{"name": "Property$subexpression$1", "symbols": ["Define", "_", "Value"]},
{"name": "Property", "symbols": ["Symbol", "_", "Property$subexpression$1"]},
{"name": "Property$subexpression$1", "symbols": ["Declare"]},
{"name": "Property$subexpression$1", "symbols": ["Define"]},
{"name": "Property", "symbols": ["Symbol", "_", "Property$subexpression$1", "_", "Value"]},
{"name": "Declare$string$1", "symbols": [{"literal":":"}, {"literal":":"}], "postprocess": (d) => d.join('')},
{"name": "Declare", "symbols": ["Declare$string$1"]},
{"name": "Define", "symbols": [{"literal":":"}]},
Expand Down
20 changes: 20 additions & 0 deletions src/lib/gram-nodes.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,26 @@ describe('node labels', () => {
const result = await Effect.runPromiseExit(task)
expect(Either.isRight(result)).toBeTruthy();
})

test.each([
'(a::Aye)',
'(ab::Aye::Bee)',
])
('can be declarations like: %s', async (gram) => {
const task = parse(gram);
const result = await Effect.runPromiseExit(task)
expect(Either.isRight(result)).toBeTruthy();
})

test.each([
'(ab::Aye:Bee)',
])
('can NOT mix definitions and declarations like: %s', async (gram) => {
const task = parse(gram);
const result = await Effect.runPromiseExit(task)
expect(Either.isLeft(result)).toBeTruthy();
})

test.each([
'(a:)',
'(a:1)',
Expand Down

0 comments on commit 7a13ddb

Please sign in to comment.