Skip to content

Commit

Permalink
Fixed build configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
mationai committed Jul 2, 2022
1 parent 36cf5a2 commit 29f206c
Show file tree
Hide file tree
Showing 10 changed files with 89 additions and 207 deletions.
22 changes: 11 additions & 11 deletions .pnp.cjs

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

Binary file not shown.
Binary file removed .yarn/cache/vite-npm-2.9.9-d1063e48c9-9292b8ba51.zip
Binary file not shown.
1 change: 1 addition & 0 deletions .yarnrc.yml
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
yarnPath: .yarn/releases/yarn-3.2.0.cjs
enableScripts: false
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@ yarn add 'mation-spec' // When package is published
```

```js
import { parse } from 'mation-spec'
import parser from 'mation-spec'

const result = parse(`
const result = parser.parse(`
a: 1,
b: 2,
/** md **
Expand Down Expand Up @@ -73,6 +73,8 @@ yarn run build // To build dist
yarn add pkg-name // -D for dev only dep
```

Grammar is developed with [Ohm](https://ohmjs.org/). Ohm provides an [online editor](https://ohmjs.org/editor/) where you can play around with the syntax.

### Tests

```cs
Expand Down
57 changes: 30 additions & 27 deletions dist/index.es.js
Original file line number Diff line number Diff line change
Expand Up @@ -4384,7 +4384,7 @@ parse$1.literal = (literal = {}) => {
case "stringLiteral":
return sourceString.slice(1, -1);
}
throw new Error(`Handler missing for literal of type: ${ctorName}`);
throw new Error(`Parser missing handler for literal of type: ${ctorName}`);
};
parse$1.List = (iter = {}) => {
if (iter.ctorName === "Commands")
Expand Down Expand Up @@ -4419,8 +4419,10 @@ parse$1.Value = (node = {}) => {
return parse$1.KeyValue(node.child(0), node.child(2));
case "Map":
return parse$1.Map(node);
case "EmptyMap":
return {};
}
throw new Error(`Handler missing for Value of type: ${node.ctorName}`);
throw new Error(`Parser missing handler for Value of type: ${node.ctorName}`);
};
parse$1.Command = (Command = {}) => {
const [identifier, Values] = Command.children;
Expand Down Expand Up @@ -4478,18 +4480,13 @@ parser.parse = (userText, g, options = {}) => {
out.markdowns = markdowns;
return out;
};
const parse = (userText = "", options = {}) => {
const g = ohm.grammar(typeof options.grammarText === "string" ? options.grammarText : grammar);
const res = parser.parse(userText, g, options);
return res;
};
const grammar = String.raw`
mationGrammar {
var grammar = `mationGrammar {
Program = (markdown | KeyValues)*
KeyValues = (KeyValue ","?)+ //> ","? // Nonempty needed for + on parent
KeyValue = Key ":" Value
Map = "{" KeyValues "}"
EmptyMap = "{" "}" // can't be lexical rule
Key
= identifier
Expand All @@ -4498,6 +4495,7 @@ mationGrammar {
Value
= KeyValue
| Map
| EmptyMap
| identifier
| literal
| List
Expand All @@ -4523,7 +4521,7 @@ mationGrammar {
/* It's a backtick, which is used to create a code block. */
comment = "//" (~nl any)* (nl | end)
nl = "\n" | "\r\n"
nl = "\\n" | "\\r\\n"
space += ws | nl | comment
identifier = ~reservedWord identName
Expand All @@ -4534,30 +4532,30 @@ mationGrammar {
otherIPart = "-" | "+"
unicode = unicodeStart unicodePart*
unicodeStart = "\\" unicodeEscSeq
unicodeStart = "\\\\" unicodeEscSeq
unicodeEscSeq = "u" hexDigit hexDigit hexDigit hexDigit
unicodePart = unicodeStart | unicodeCM | unicodeDigit | unicodeCP | "\u200C" | "\u200D"
unicodePart = unicodeStart | unicodeCM | unicodeDigit | unicodeCP | "\\u200C" | "\\u200D"
literal = nullLiteral | booleanLiteral | numericLiteral | stringLiteral
nullLiteral = "null" ~identPart
booleanLiteral = ("true" | "false") ~identPart
reservedWord = nullLiteral | booleanLiteral
ws = " "
| "\t"
| "\x0B" -- verticalTab
| "\x0C" -- formFeed
| "\u00A0" -- noBreakSpace
| "\uFEFF" -- byteOrderMark
| "\\t"
| "\\x0B" -- verticalTab
| "\\x0C" -- formFeed
| "\\u00A0" -- noBreakSpace
| "\\uFEFF" -- byteOrderMark
| unicodeSpace
stringLiteral = "\"" nonDoubleQuoteChar* "\""
stringLiteral = "\\"" nonDoubleQuoteChar* "\\""
| "'" nonSingleQuoteChar* "'"
nonDoubleQuoteChar = ~("\"" | "\\" | nl) sourceChar -- nonEscaped
| "\\" escapeSeqence -- escaped
nonSingleQuoteChar = ~("'" | "\\" | nl ) sourceChar -- nonEscaped
| "\\" escapeSeqence -- escaped
nonDoubleQuoteChar = ~("\\"" | "\\\\" | nl) sourceChar -- nonEscaped
| "\\\\" escapeSeqence -- escaped
nonSingleQuoteChar = ~("'" | "\\\\" | nl ) sourceChar -- nonEscaped
| "\\\\" escapeSeqence -- escaped
escapeSeqence = unicodeEscSeq
| hexEscSeq
Expand All @@ -4569,18 +4567,18 @@ mationGrammar {
| zeroToThree octalDigit ~decimalDigit -- eightTimesZeroToThree
| octalDigit ~decimalDigit -- octalDigits
hexEscSeq = "x" hexDigit hexDigit
singleEscapeChar = "'" | "\"" | "\\" | "b" | "f" | "n" | "r" | "t" | "v"
singleEscapeChar = "'" | "\\"" | "\\\\" | "b" | "f" | "n" | "r" | "t" | "v"
nonEscapeChar = ~(escapeChar | nl) sourceChar
escapeChar = singleEscapeChar | decimalDigit | "x" | "u"
unicodeDigit (a digit)
= "\u0030".."\u0039" | "\u0660".."\u0669" | "\u06F0".."\u06F9" | "\u0966".."\u096F" | "\u09E6".."\u09EF" | "\u0A66".."\u0A6F" | "\u0AE6".."\u0AEF" | "\u0B66".."\u0B6F" | "\u0BE7".."\u0BEF" | "\u0C66".."\u0C6F" | "\u0CE6".."\u0CEF" | "\u0D66".."\u0D6F" | "\u0E50".."\u0E59" | "\u0ED0".."\u0ED9" | "\u0F20".."\u0F29" | "\uFF10".."\uFF19"
= "\\u0030".."\\u0039" | "\\u0660".."\\u0669" | "\\u06F0".."\\u06F9" | "\\u0966".."\\u096F" | "\\u09E6".."\\u09EF" | "\\u0A66".."\\u0A6F" | "\\u0AE6".."\\u0AEF" | "\\u0B66".."\\u0B6F" | "\\u0BE7".."\\u0BEF" | "\\u0C66".."\\u0C6F" | "\\u0CE6".."\\u0CEF" | "\\u0D66".."\\u0D6F" | "\\u0E50".."\\u0E59" | "\\u0ED0".."\\u0ED9" | "\\u0F20".."\\u0F29" | "\\uFF10".."\\uFF19"
unicodeCM (Unicode combining mark)
= "\u0300".."\u0345" | "\u0360".."\u0361" | "\u0483".."\u0486" | "\u0591".."\u05A1" | "\u05A3".."\u05B9" | "\u05BB".."\u05BD" | "\u05BF".."\u05BF" | "\u05C1".."\u05C2" | "\u05C4".."\u05C4" | "\u064B".."\u0652" | "\u0670".."\u0670" | "\u06D6".."\u06DC" | "\u06DF".."\u06E4" | "\u06E7".."\u06E8" | "\u06EA".."\u06ED" | "\u0901".."\u0902" | "\u093C".."\u093C" | "\u0941".."\u0948" | "\u094D".."\u094D" | "\u0951".."\u0954" | "\u0962".."\u0963" | "\u0981".."\u0981" | "\u09BC".."\u09BC" | "\u09C1".."\u09C4" | "\u09CD".."\u09CD" | "\u09E2".."\u09E3" | "\u0A02".."\u0A02" | "\u0A3C".."\u0A3C" | "\u0A41".."\u0A42" | "\u0A47".."\u0A48" | "\u0A4B".."\u0A4D" | "\u0A70".."\u0A71" | "\u0A81".."\u0A82" | "\u0ABC".."\u0ABC" | "\u0AC1".."\u0AC5" | "\u0AC7".."\u0AC8" | "\u0ACD".."\u0ACD" | "\u0B01".."\u0B01" | "\u0B3C".."\u0B3C" | "\u0B3F".."\u0B3F" | "\u0B41".."\u0B43" | "\u0B4D".."\u0B4D" | "\u0B56".."\u0B56" | "\u0B82".."\u0B82" | "\u0BC0".."\u0BC0" | "\u0BCD".."\u0BCD" | "\u0C3E".."\u0C40" | "\u0C46".."\u0C48" | "\u0C4A".."\u0C4D" | "\u0C55".."\u0C56" | "\u0CBF".."\u0CBF" | "\u0CC6".."\u0CC6" | "\u0CCC".."\u0CCD" | "\u0D41".."\u0D43" | "\u0D4D".."\u0D4D" | "\u0E31".."\u0E31" | "\u0E34".."\u0E3A" | "\u0E47".."\u0E4E" | "\u0EB1".."\u0EB1" | "\u0EB4".."\u0EB9" | "\u0EBB".."\u0EBC" | "\u0EC8".."\u0ECD" | "\u0F18".."\u0F19" | "\u0F35".."\u0F35" | "\u0F37".."\u0F37" | "\u0F39".."\u0F39" | "\u0F71".."\u0F7E" | "\u0F80".."\u0F84" | "\u0F86".."\u0F87" | "\u0F90".."\u0F95" | "\u0F97".."\u0F97" | "\u0F99".."\u0FAD" | "\u0FB1".."\u0FB7" | "\u0FB9".."\u0FB9" | "\u20D0".."\u20DC" | "\u20E1".."\u20E1" | "\u302A".."\u302F" | "\u3099".."\u309A" | "\uFB1E".."\uFB1E" | "\uFE20".."\uFE23"
= "\\u0300".."\\u0345" | "\\u0360".."\\u0361" | "\\u0483".."\\u0486" | "\\u0591".."\\u05A1" | "\\u05A3".."\\u05B9" | "\\u05BB".."\\u05BD" | "\\u05BF".."\\u05BF" | "\\u05C1".."\\u05C2" | "\\u05C4".."\\u05C4" | "\\u064B".."\\u0652" | "\\u0670".."\\u0670" | "\\u06D6".."\\u06DC" | "\\u06DF".."\\u06E4" | "\\u06E7".."\\u06E8" | "\\u06EA".."\\u06ED" | "\\u0901".."\\u0902" | "\\u093C".."\\u093C" | "\\u0941".."\\u0948" | "\\u094D".."\\u094D" | "\\u0951".."\\u0954" | "\\u0962".."\\u0963" | "\\u0981".."\\u0981" | "\\u09BC".."\\u09BC" | "\\u09C1".."\\u09C4" | "\\u09CD".."\\u09CD" | "\\u09E2".."\\u09E3" | "\\u0A02".."\\u0A02" | "\\u0A3C".."\\u0A3C" | "\\u0A41".."\\u0A42" | "\\u0A47".."\\u0A48" | "\\u0A4B".."\\u0A4D" | "\\u0A70".."\\u0A71" | "\\u0A81".."\\u0A82" | "\\u0ABC".."\\u0ABC" | "\\u0AC1".."\\u0AC5" | "\\u0AC7".."\\u0AC8" | "\\u0ACD".."\\u0ACD" | "\\u0B01".."\\u0B01" | "\\u0B3C".."\\u0B3C" | "\\u0B3F".."\\u0B3F" | "\\u0B41".."\\u0B43" | "\\u0B4D".."\\u0B4D" | "\\u0B56".."\\u0B56" | "\\u0B82".."\\u0B82" | "\\u0BC0".."\\u0BC0" | "\\u0BCD".."\\u0BCD" | "\\u0C3E".."\\u0C40" | "\\u0C46".."\\u0C48" | "\\u0C4A".."\\u0C4D" | "\\u0C55".."\\u0C56" | "\\u0CBF".."\\u0CBF" | "\\u0CC6".."\\u0CC6" | "\\u0CCC".."\\u0CCD" | "\\u0D41".."\\u0D43" | "\\u0D4D".."\\u0D4D" | "\\u0E31".."\\u0E31" | "\\u0E34".."\\u0E3A" | "\\u0E47".."\\u0E4E" | "\\u0EB1".."\\u0EB1" | "\\u0EB4".."\\u0EB9" | "\\u0EBB".."\\u0EBC" | "\\u0EC8".."\\u0ECD" | "\\u0F18".."\\u0F19" | "\\u0F35".."\\u0F35" | "\\u0F37".."\\u0F37" | "\\u0F39".."\\u0F39" | "\\u0F71".."\\u0F7E" | "\\u0F80".."\\u0F84" | "\\u0F86".."\\u0F87" | "\\u0F90".."\\u0F95" | "\\u0F97".."\\u0F97" | "\\u0F99".."\\u0FAD" | "\\u0FB1".."\\u0FB7" | "\\u0FB9".."\\u0FB9" | "\\u20D0".."\\u20DC" | "\\u20E1".."\\u20E1" | "\\u302A".."\\u302F" | "\\u3099".."\\u309A" | "\\uFB1E".."\\uFB1E" | "\\uFE20".."\\uFE23"
unicodeCP (Unicode Connector Punctuation) = "\u005F" | "\u203F".."\u2040" | "\u30FB" | "\uFE33".."\uFE34" | "\uFE4D".."\uFE4F" | "\uFF3F" | "\uFF65"
unicodeSpace = "\u2000".."\u200B" | "\u3000"
unicodeCP (Unicode Connector Punctuation) = "\\u005F" | "\\u203F".."\\u2040" | "\\u30FB" | "\\uFE33".."\\uFE34" | "\\uFE4D".."\\uFE4F" | "\\uFF3F" | "\\uFF65"
unicodeSpace = "\\u2000".."\\u200B" | "\\u3000"
octalDigit = "0".."7"
decimalDigit = "0".."9"
Expand Down Expand Up @@ -4610,4 +4608,9 @@ mationGrammar {
sourceChar = any
}`;
const parse = (userText = "", options = {}) => {
const g = ohm.grammar(typeof options.grammarText === "string" ? options.grammarText : grammar);
const res = parser.parse(userText, g, options);
return res;
};
export { parse };
Loading

0 comments on commit 29f206c

Please sign in to comment.