Skip to content

Commit

Permalink
restructure
Browse files Browse the repository at this point in the history
  • Loading branch information
alkizer committed Aug 8, 2019
1 parent d58dbd1 commit b386715
Show file tree
Hide file tree
Showing 22 changed files with 101 additions and 9 deletions.
4 changes: 2 additions & 2 deletions generateParser.ts
Expand Up @@ -4,11 +4,11 @@ from 'fs';

import {
parseGrammar
} from './lib/grammarParser/grammarParser';
} from './src/grammar-parser/lib/grammarParser';

import {
generateParser
} from './lib/parserGenerator/parserGenerator';
} from './src/parser-generator/lib/parserGenerator';

const grammarSource: string = fs.readFileSync(`./kizerlang.kzrgrammar`, `utf8`);

Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
62 changes: 62 additions & 0 deletions libOLD/grammarParser/index.ts
@@ -0,0 +1,62 @@
interface Target {
readonly type: TargetType;
readonly value: string;
}

enum TargetType {
LiteralTarget = 'LiteralTarget',
TerminalTarget = 'TerminalTarget',
NonTerminalTarget = 'NonTerminalTarget'
}

interface LiteralTarget extends Target {

}

interface TerminalTarget extends Target {
readonly name: string;
}

interface NonTerminalTarget extends Target {
readonly production: Production;
}

interface Terminal {
readonly type: TerminalType
readonly definition: string;
}

enum TerminalType {
LiteralTerminal,
RegexTerminal,
BuiltInTerminal
}

interface Derivation {
readonly tokens: Target[];
}

interface Production {
readonly nonTerminalName: string;
readonly derivations: Derivation[];
}

interface Grammar {
readonly productions: Production[];
readonly startingProduction: Production;
}

const parseGrammar: (grammarSource: string) => Grammar = (grammarSource: string): Grammar => {
return null; // TODO
};

export {
Target as Token,
LiteralTarget,
TerminalTarget,
NonTerminalTarget,
Derivation,
Production,
Grammar,
parseGrammar
};
File renamed without changes.
Empty file added src/code-gen/index.ts
Empty file.
Empty file added src/grammar-parser/index.ts
Empty file.
File renamed without changes.
Empty file.
@@ -1,4 +1,4 @@
import { IGrammar } from "../parserGenerator/parserGenerator";
import { IGrammar } from "../../parser-generator/lib/parserGenerator";

import { IDirective } from "./grammarParser";

Expand Down
Empty file.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
@@ -1,6 +1,7 @@
import
IParsedGrammarElement
from './IParsedGrammarElement';
import { LineProvider } from './lineProvider';

enum LineType {
ProductionLine,
Expand Down Expand Up @@ -298,9 +299,12 @@ const parseLine = (line: string, lineNumber: number) => {
return parsedLine;
};

const getLines = (grammarSourceCode: string) => {
//const lines = grammarSourceCode.replace(/;[^\n]*\n/g, `\n`).trim().split(`\n`);
const lines = grammarSourceCode.replace(/\r/g, ``).split(`\n`);
const getLines = (lineProvider: LineProvider) => {
let lines = [],
line;
while (line = lineProvider.next()) {
lines.push(line);
}
const parsedLines = lines.map(parseLine).filter(line => !!line);
return parsedLines;
};
Expand Down
Empty file.
26 changes: 26 additions & 0 deletions src/grammar-parser/lib/lineProvider.ts
@@ -0,0 +1,26 @@
interface LineProvider {
next(): string | null;
}

class FromStringLineProvider implements LineProvider {
private _string: string;
private _lines: string[];
private _nextLineIndex: number = 0;

constructor (string: string) {
this._string = string;
this._lines = string.replace(/\r/g, ``).split(`\n`);
}

next () {
if (this._nextLineIndex >= this._lines.length) {
return null;
}
return this._lines[this._nextLineIndex++];
}
}

export {
LineProvider,
FromStringLineProvider
};
Empty file added src/parser-generator/index.ts
Empty file.
File renamed without changes.
@@ -1,16 +1,16 @@
import {
SourceCodeBuilder
} from '../codeGenerationLib';
} from '../../../libOLD/codeGenerationLib';

import {
IGrammar, IDerivation, IParsedTarget, IProduction
} from '../grammarParser/grammarParser';
} from '../../grammar-parser/lib/grammarParser';

import
builtInTerminals
from './builtInTerminals';

import IParsedGrammarElement from '../grammarParser/IParsedGrammarElement';
import IParsedGrammarElement from '../../grammar-parser/lib/IParsedGrammarElement';

const gen = new SourceCodeBuilder({
tabWidth: 4
Expand Down

0 comments on commit b386715

Please sign in to comment.