mirror of
https://github.com/mdgriffith/elm-optimize-level-2.git
synced 2024-11-29 12:46:32 +03:00
separate out tree-sitter and parsing primitives
This commit is contained in:
parent
b72d088290
commit
192e2f9c10
2
package-lock.json
generated
2
package-lock.json
generated
@ -1,5 +1,5 @@
|
||||
{
|
||||
"name": "lib",
|
||||
"name": "elm-optimize-more",
|
||||
"version": "0.1.0",
|
||||
"lockfileVersion": 1,
|
||||
"requires": true,
|
||||
|
@ -1,6 +1,9 @@
|
||||
/*
|
||||
*/
|
||||
|
||||
import Parser from 'tree-sitter';
|
||||
import Elm from 'tree-sitter-elm';
|
||||
import { ElmVariant } from './types';
|
||||
import { ElmVariant } from '../types';
|
||||
import * as fs from 'fs';
|
||||
import * as path from 'path';
|
||||
|
||||
@ -8,51 +11,6 @@ import * as path from 'path';
|
||||
const elmParser = new Parser();
|
||||
elmParser.setLanguage(Elm);
|
||||
|
||||
// List variants
|
||||
|
||||
const nil: ElmVariant = {
|
||||
typeName: 'List',
|
||||
name: 'Nil',
|
||||
jsName: '_List_Nil',
|
||||
index: 0,
|
||||
slots: [],
|
||||
totalTypeSlotCount: 2,
|
||||
};
|
||||
|
||||
const cons: ElmVariant = {
|
||||
typeName: 'List',
|
||||
name: 'Cons',
|
||||
jsName: '_List_Nil',
|
||||
index: 1,
|
||||
slots: ['a'],
|
||||
totalTypeSlotCount: 2,
|
||||
};
|
||||
|
||||
const listVariants = [nil, cons];
|
||||
|
||||
// Maybe variants
|
||||
|
||||
const nothing: ElmVariant = {
|
||||
typeName: 'Maybe',
|
||||
name: 'Nothing',
|
||||
jsName: '$elm$core$Maybe$Nothing',
|
||||
index: 1,
|
||||
slots: [],
|
||||
totalTypeSlotCount: 1,
|
||||
};
|
||||
|
||||
const just: ElmVariant = {
|
||||
typeName: 'Maybe',
|
||||
name: 'Just',
|
||||
jsName: '$elm$core$Maybe$Just',
|
||||
index: 0,
|
||||
slots: ['a'],
|
||||
totalTypeSlotCount: 1,
|
||||
};
|
||||
const maybe = [nothing, just];
|
||||
|
||||
export const primitives = listVariants.concat(maybe);
|
||||
|
||||
export const parseElm = ({
|
||||
author,
|
||||
project,
|
||||
@ -194,10 +152,10 @@ export const parseDir = (dir: string): ElmVariant[] => {
|
||||
let variants: ElmVariant[] = [];
|
||||
const files = fs.readdirSync(dir);
|
||||
|
||||
files.forEach(function(author) {
|
||||
files.forEach(function (author) {
|
||||
if (fs.statSync(dir + '/' + author).isDirectory()) {
|
||||
const projs = fs.readdirSync(path.join(dir, author));
|
||||
projs.forEach(function(project) {
|
||||
projs.forEach(function (project) {
|
||||
if (fs.statSync(path.join(dir, author, project)).isDirectory()) {
|
||||
const vars = parseElmFilesInDirectory(
|
||||
path.join(dir, author, project),
|
||||
@ -238,10 +196,10 @@ const parseElmFilesInDirectory = (
|
||||
return variants;
|
||||
};
|
||||
|
||||
var walkSync = function(dir: string, filelist: string[]) {
|
||||
var walkSync = function (dir: string, filelist: string[]) {
|
||||
var files = fs.readdirSync(dir);
|
||||
filelist = filelist || [];
|
||||
files.forEach(function(file: string) {
|
||||
files.forEach(function (file: string) {
|
||||
if (fs.statSync(path.join(dir, file)).isDirectory()) {
|
||||
filelist = walkSync(path.join(dir, file), filelist);
|
||||
} else {
|
46
src/parsing/primitives.ts
Normal file
46
src/parsing/primitives.ts
Normal file
@ -0,0 +1,46 @@
|
||||
import { ElmVariant } from '../types';
|
||||
|
||||
// List variants
|
||||
|
||||
const nil: ElmVariant = {
|
||||
typeName: 'List',
|
||||
name: 'Nil',
|
||||
jsName: '_List_Nil',
|
||||
index: 0,
|
||||
slots: [],
|
||||
totalTypeSlotCount: 2,
|
||||
};
|
||||
|
||||
const cons: ElmVariant = {
|
||||
typeName: 'List',
|
||||
name: 'Cons',
|
||||
jsName: '_List_Nil',
|
||||
index: 1,
|
||||
slots: ['a'],
|
||||
totalTypeSlotCount: 2,
|
||||
};
|
||||
|
||||
const listVariants = [nil, cons];
|
||||
|
||||
// Maybe variants
|
||||
|
||||
const nothing: ElmVariant = {
|
||||
typeName: 'Maybe',
|
||||
name: 'Nothing',
|
||||
jsName: '$elm$core$Maybe$Nothing',
|
||||
index: 1,
|
||||
slots: [],
|
||||
totalTypeSlotCount: 1,
|
||||
};
|
||||
|
||||
const just: ElmVariant = {
|
||||
typeName: 'Maybe',
|
||||
name: 'Just',
|
||||
jsName: '$elm$core$Maybe$Just',
|
||||
index: 0,
|
||||
slots: ['a'],
|
||||
totalTypeSlotCount: 1,
|
||||
};
|
||||
const maybe = [nothing, just];
|
||||
|
||||
export const primitives = listVariants.concat(maybe);
|
@ -1,4 +1,5 @@
|
||||
import { primitives } from './parseElm';
|
||||
import { primitives } from './parsing/primitives';
|
||||
// import { parseElm } from './parsing/parseElm';
|
||||
import ts from 'typescript';
|
||||
import { createCustomTypesTransformer } from './transforms/variantShapes';
|
||||
import { Mode, Transforms, InlineLists } from './types';
|
||||
|
Loading…
Reference in New Issue
Block a user