Feat: add new Markdown parser (#39800)

and change all the challenges to new `md` format.
This commit is contained in:
Oliver Eyton-Williams
2020-11-27 19:02:05 +01:00
committed by GitHub
parent a07f84c8ec
commit 0bd52f8bd1
2580 changed files with 113436 additions and 111979 deletions

View File

@ -1,65 +1,61 @@
---
title: S-Expressions
id: 59667989bf71cf555dd5d2ff
title: S-Expressions
challengeType: 5
forumTopicId: 302303
---
## Description
<section id='description'>
<a href="https://en.wikipedia.org/wiki/S-Expression" title="wp: S-Expression" target="_blank">S-Expressions</a> are one convenient way to parse and store data.
</section>
# --description--
[S-Expressions](https://en.wikipedia.org/wiki/S-Expression "wp: S-Expression") are one convenient way to parse and store data.
# --instructions--
## Instructions
<section id='instructions'>
Write a simple reader/parser for S-Expressions that handles quoted and unquoted strings, integers and floats.
The function should read a single but nested S-Expression from a string and return it as a (nested) array.
Newlines and other whitespace may be ignored unless contained within a quoted string.
"<tt>()</tt>" inside quoted strings are not interpreted, but treated as part of the string.
Handling escaped quotes inside a string is optional; thus "<tt>(foo"bar)</tt>" may be treated as a string "<tt>foo"bar</tt>", or as an error.
For this, the reader need not recognize "<tt>\</tt>" for escaping, but should, in addition, recognize numbers if the language has appropriate data types.
Note that with the exception of "<tt>()"</tt>" ("<tt>\</tt>" if escaping is supported) and whitespace there are no special characters. Anything else is allowed without quotes.
"`()`" inside quoted strings are not interpreted, but treated as part of the string.
Handling escaped quotes inside a string is optional; thus "`(foo"bar)`" may be treated as a string "`foo"bar`", or as an error.
For this, the reader need not recognize "`\`" for escaping, but should, in addition, recognize numbers if the language has appropriate data types.
Note that with the exception of "`()"`" ("`\`" if escaping is supported) and whitespace there are no special characters. Anything else is allowed without quotes.
The reader should be able to read the following input
<pre>
((data "quoted data" 123 4.5)
<pre>((data "quoted data" 123 4.5)
(data (!@# (4.5) "(more" "data)")))
</pre>
and turn it into a native data structure. (See the <a href="https://rosettacode.org/wiki/S-Expressions#Pike" title="#Pike" target="_blank">Pike</a>, <a href="https://rosettacode.org/wiki/S-Expressions#Python" title="#Python" target="_blank">Python</a> and <a href="https://rosettacode.org/wiki/S-Expressions#Ruby" title="#Ruby" target="_blank">Ruby</a> implementations for examples of native data structures.)
</section>
## Tests
<section id='tests'>
and turn it into a native data structure. (See the [Pike](https://rosettacode.org/wiki/S-Expressions#Pike "\#Pike"), [Python](https://rosettacode.org/wiki/S-Expressions#Python "\#Python") and [Ruby](https://rosettacode.org/wiki/S-Expressions#Ruby "\#Ruby") implementations for examples of native data structures.)
```yml
tests:
- text: <code>parseSexpr</code> should be a function.
testString: assert(typeof parseSexpr === 'function');
- text: <code>parseSexpr('(data1 data2 data3)')</code> should return <code>['data1', 'data2', 'data3']</code>
testString: assert.deepEqual(parseSexpr(simpleSExpr), simpleSolution);
- text: <code>parseSexpr('(data1 data2 data3)')</code> should return an array with 3 elements.
testString: assert.deepEqual(parseSexpr(basicSExpr), basicSolution);
# --hints--
```
</section>
## Challenge Seed
<section id='challengeSeed'>
<div id='js-seed'>
`parseSexpr` should be a function.
```js
function parseSexpr(str) {
return true;
}
assert(typeof parseSexpr === 'function');
```
</div>
`parseSexpr('(data1 data2 data3)')` should return `['data1', 'data2', 'data3']`
```js
assert.deepEqual(parseSexpr(simpleSExpr), simpleSolution);
```
### After Test
<div id='js-teardown'>
`parseSexpr('(data1 data2 data3)')` should return an array with 3 elements.
```js
assert.deepEqual(parseSexpr(basicSExpr), basicSolution);
```
# --seed--
## --after-user-code--
```js
const simpleSExpr = '(data1 data2 data3)';
@ -69,13 +65,16 @@ const basicSExpr = '((data "quoted data" 123 4.5) (data (!@# (4.5) "(more" "data
const basicSolution = [["data","\"quoted data\"",123,4.5],["data",["!@#",[4.5],"\"(more\"","\"data)\""]]];
```
</div>
## --seed-contents--
</section>
```js
function parseSexpr(str) {
## Solution
<section id='solution'>
return true;
}
```
# --solutions--
```js
function parseSexpr(str) {
@ -93,7 +92,4 @@ function parseSexpr(str) {
}
return c ? undefined : eval(t.join(''));
}
```
</section>