mirror of
https://activitypub.software/TransFem-org/sfm-js
synced 2024-11-24 23:15:14 +00:00
✌️
This commit is contained in:
parent
656a389aca
commit
303ba2827a
11 changed files with 157 additions and 36 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -1,3 +1,4 @@
|
|||
node_modules
|
||||
built
|
||||
package-lock.json
|
||||
temp
|
||||
|
|
24
README.md
24
README.md
|
@ -1,2 +1,24 @@
|
|||
# mfm-parser-pegjs
|
||||
A trial of creating a MFM parser with peg.js
|
||||
## Description
|
||||
A trial of creating a MFM parser with peg.js
|
||||
|
||||
## Installation
|
||||
```
|
||||
npm i
|
||||
```
|
||||
|
||||
## Build
|
||||
For production:
|
||||
```
|
||||
npm run build
|
||||
```
|
||||
|
||||
For development:
|
||||
```
|
||||
npm run build-dev
|
||||
```
|
||||
|
||||
## Start
|
||||
```
|
||||
npm start
|
||||
```
|
||||
|
|
21
package.json
21
package.json
|
@ -2,24 +2,29 @@
|
|||
"private": true,
|
||||
"name": "mfm-parser-pegjs",
|
||||
"version": "0.1.0",
|
||||
"main": "./built/index.js",
|
||||
"scripts": {
|
||||
"build": "npm run peg && npm run tsc",
|
||||
"build-debug": "npm run peg-debug && npm run tsc",
|
||||
"peg": "mkdirp ./built && pegjs -o built/coreParser.js src/coreParser.pegjs",
|
||||
"peg-debug": "mkdirp ./built && pegjs -o built/coreParser.js --trace src/coreParser.pegjs",
|
||||
"tsc": "tsc"
|
||||
"build": "npm run peg && npm run tsc && npm run webpack",
|
||||
"build-dev": "npm run peg-dev && npm run tsc && npm run webpack-dev",
|
||||
"peg": "mkdirp ./built/parser && pegjs -o built/parser/coreParser.js src/parser/coreParser.pegjs",
|
||||
"peg-dev": "mkdirp ./built/parser && pegjs -o built/parser/coreParser.js --trace src/parser/coreParser.pegjs",
|
||||
"tsc": "tsc",
|
||||
"webpack": "webpack --mode=production",
|
||||
"webpack-dev": "webpack --mode=development",
|
||||
"start": "node ."
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+https://github.com/marihachi/mfm-parser-pegjs.git"
|
||||
},
|
||||
"author": "Marihachi",
|
||||
"dependencies": {
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/node": "^12.0.4",
|
||||
"mkdirp": "^0.5.1",
|
||||
"pegjs": "^0.10.0",
|
||||
"typescript": "3.7.x"
|
||||
"ts-loader": "6.2.x",
|
||||
"typescript": "3.7.x",
|
||||
"webpack": "4.40.x",
|
||||
"webpack-cli": "3.3.x"
|
||||
}
|
||||
}
|
||||
|
|
13
src/client/mainEntry.ts
Normal file
13
src/client/mainEntry.ts
Normal file
|
@ -0,0 +1,13 @@
|
|||
import { PegParser } from '../parser/pegParser';
|
||||
|
||||
async function entryPoint() {
|
||||
const coreParser: PegParser = require('../../built/parser/coreParser.js');
|
||||
|
||||
const input = '[hoge]';
|
||||
console.log('parsing input:', input);
|
||||
const result = coreParser.parse(input);
|
||||
console.log('parsing result:');
|
||||
console.log(result);
|
||||
}
|
||||
entryPoint()
|
||||
.catch(err => console.log(err));
|
8
src/index.ts
Normal file
8
src/index.ts
Normal file
|
@ -0,0 +1,8 @@
|
|||
import { PegParser } from './parser/pegParser';
|
||||
|
||||
const coreParser: PegParser = require('./parser/coreParser');
|
||||
const input = '[hoge]';
|
||||
console.log('parsing input:', input);
|
||||
const result = coreParser.parse(input);
|
||||
console.log('parsing result:');
|
||||
console.log(result);
|
|
@ -1 +0,0 @@
|
|||
const coreParser = require('./coreParser.js');
|
|
@ -54,35 +54,45 @@ blockCode
|
|||
|
||||
// parts
|
||||
|
||||
plain
|
||||
= emoji
|
||||
/ text
|
||||
// plain
|
||||
// = emoji
|
||||
// / text
|
||||
|
||||
// block
|
||||
// = title
|
||||
// / quote
|
||||
// / search
|
||||
// / blockCode
|
||||
// / mathBlock
|
||||
// / center
|
||||
|
||||
// inline
|
||||
// = big
|
||||
// / bold
|
||||
// / small
|
||||
// / italic
|
||||
// / strike
|
||||
// / motion
|
||||
// / spin
|
||||
// / jump
|
||||
// / flip
|
||||
// / inlineCode
|
||||
// / mathInline
|
||||
// / mention
|
||||
// / hashtag
|
||||
// / url
|
||||
// / link
|
||||
// / plain
|
||||
|
||||
// root
|
||||
// = block
|
||||
// / inline
|
||||
|
||||
block
|
||||
= title
|
||||
/ quote
|
||||
/ search
|
||||
/ blockCode
|
||||
/ mathBlock
|
||||
/ center
|
||||
|
||||
inline
|
||||
= big
|
||||
/ bold
|
||||
/ small
|
||||
/ italic
|
||||
/ strike
|
||||
/ motion
|
||||
/ spin
|
||||
/ jump
|
||||
/ flip
|
||||
/ inlineCode
|
||||
/ mathInline
|
||||
/ mention
|
||||
/ hashtag
|
||||
/ url
|
||||
/ link
|
||||
/ plain
|
||||
inline = "inline"
|
||||
|
||||
root
|
||||
= block
|
6
src/parser/pegParser.d.ts
vendored
Normal file
6
src/parser/pegParser.d.ts
vendored
Normal file
|
@ -0,0 +1,6 @@
|
|||
export interface PegParserOptions {
|
||||
startRule?: string;
|
||||
}
|
||||
export interface PegParser {
|
||||
parse(input: string, options?: PegParserOptions): any;
|
||||
}
|
30
tsconfig.client.json
Normal file
30
tsconfig.client.json
Normal file
|
@ -0,0 +1,30 @@
|
|||
{
|
||||
"compilerOptions": {
|
||||
/* Basic Options */
|
||||
"target": "ES2015", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017','ES2018' or 'ESNEXT'. */
|
||||
"module": "ESNext",
|
||||
"moduleResolution": "node",
|
||||
"outDir": "./built/client/", /* Redirect output structure to the directory. */
|
||||
"rootDir": "./src/client/", /* Specify the root directory of input files. Use to control the output directory structure with --outDir. */
|
||||
"removeComments": false,
|
||||
|
||||
/* Strict Type-Checking Options */
|
||||
"strict": true, /* Enable all strict type-checking options. */
|
||||
"strictFunctionTypes": true, /* Enable strict checking of function types. */
|
||||
|
||||
/* Additional Checks */
|
||||
"noImplicitReturns": true, /* Report error when not all code paths in function return a value. */
|
||||
|
||||
/* Module Resolution Options */
|
||||
"esModuleInterop": true, /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */
|
||||
|
||||
"experimentalDecorators": true,
|
||||
},
|
||||
"include": [
|
||||
"src/client/**/*",
|
||||
],
|
||||
"exclude": [
|
||||
"node_modules",
|
||||
"test/**/*.ts",
|
||||
]
|
||||
}
|
|
@ -3,7 +3,7 @@
|
|||
/* Basic Options */
|
||||
"target": "es2017", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017','ES2018' or 'ESNEXT'. */
|
||||
"module": "commonjs", /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', or 'ESNext'. */
|
||||
"declaration": true, /* Generates corresponding '.d.ts' file. */
|
||||
//"declaration": true, /* Generates corresponding '.d.ts' file. */
|
||||
"outDir": "./built/", /* Redirect output structure to the directory. */
|
||||
"rootDir": "./src/", /* Specify the root directory of input files. Use to control the output directory structure with --outDir. */
|
||||
"removeComments": true, /* Do not emit comments to output. */
|
||||
|
@ -23,6 +23,7 @@
|
|||
],
|
||||
"exclude": [
|
||||
"node_modules",
|
||||
"test/**/*.ts",
|
||||
"src/client/**/*",
|
||||
"test/**/*",
|
||||
]
|
||||
}
|
||||
|
|
26
webpack.config.js
Normal file
26
webpack.config.js
Normal file
|
@ -0,0 +1,26 @@
|
|||
module.exports = {
|
||||
entry: './src/client/mainEntry.ts',
|
||||
output: {
|
||||
path: `${__dirname}/built/client`,
|
||||
publicPath: '/', // base path of URL
|
||||
filename: 'bundle.js',
|
||||
chunkFilename: "bundle.[name].js",
|
||||
},
|
||||
module: {
|
||||
rules: [
|
||||
{
|
||||
test: /\.ts$/,
|
||||
exclude: /node_modules/,
|
||||
use: [
|
||||
{
|
||||
loader: 'ts-loader',
|
||||
options: { configFile: 'tsconfig.client.json' },
|
||||
},
|
||||
],
|
||||
},
|
||||
]
|
||||
},
|
||||
resolve: {
|
||||
extensions: ['.ts'],
|
||||
},
|
||||
};
|
Loading…
Reference in a new issue