From 0676f1f16bfe8f5333b7170b83151886a0e586ed Mon Sep 17 00:00:00 2001 From: John Haugeland Date: Sun, 4 Jun 2017 19:36:59 -0700 Subject: [PATCH] add atoms; remove useless subexpitem; remove < > from atoms; add tests for empty arrow descriptions and single item descriptions --- src/js/jssm-dot.peg | 18 +++++++++--------- src/js/tests/parse.js | 9 +++++++++ 2 files changed, 18 insertions(+), 9 deletions(-) diff --git a/src/js/jssm-dot.peg b/src/js/jssm-dot.peg index 2f31e577..8d0f6994 100644 --- a/src/js/jssm-dot.peg +++ b/src/js/jssm-dot.peg @@ -11,9 +11,6 @@ TwoWayArrow "two way arrow" Arrow = ForwardArrow / TwoWayArrow -String "string" - = QuoteMark chars:Char* QuoteMark { return chars.join(""); } - HexDigit = [0-9a-fA-F] @@ -39,12 +36,18 @@ Escape = "\\" QuoteMark = '"' Unescaped = [\x20-\x21\x23-\x5B\x5D-\u10FFFF] +String "string" + = QuoteMark chars:Char* QuoteMark { return chars.join(""); } + +Atom "atom" + = text:[0-9a-zA-Z\.\+\_\&\(\)\%\$\#\@\!\?\,\']+ { return text.join(''); } + Label "label" - = text:[0-9a-zA-Z\.\+\_\&\(\)\%\$\#\@\!\?\<\>\,\:\']+ { return text.join(''); } - / text:String { return text.join(''); } + = atom:Atom + / string:String DescValue - = string:String + = label:Label DescItem = text:Label ":" value:DescValue ";" @@ -64,9 +67,6 @@ Subexp return {kind: arrow, to: label, se:(tail === [])? undefined: tail}; } -SubexpItem - = Subexp - Exp = label:Label se:Subexp Whitespace ';' Whitespace { return {from: label, se:(se === [])? undefined: se}; diff --git a/src/js/tests/parse.js b/src/js/tests/parse.js index fe89edd0..a8e0465a 100644 --- a/src/js/tests/parse.js +++ b/src/js/tests/parse.js @@ -14,6 +14,15 @@ describe('parse/1', async it => { it('a-> b;', t => t.deepEqual([0,1], jssm.parse('a-> b;') )); it('a -> b;', t => t.deepEqual([0,1], jssm.parse('a -> b;') )); + it('a{}->b;', t => t.deepEqual([], jssm.parse('a{}->b;') )); + it('a->{}b;', t => t.deepEqual([0], jssm.parse('a->{}b;') )); + it('a{}->{}b;', t => t.deepEqual([0,1], jssm.parse('a{}->{}b;') )); + + it('a{c:d}->b;', t => t.deepEqual([], jssm.parse('a{c:d}->b;') )); + it('a{c:"d"}->b;', t => t.deepEqual([], jssm.parse('a{c:"d"}->b;') )); + it('a{"c":d}->b;', t => t.deepEqual([], jssm.parse('a{"c":d}->b;') )); + it('a{"c":"d"}->b;', t => t.deepEqual([], jssm.parse('a{"c":"d"}->b;') )); + }); // stochable