Skip to content

Commit

Permalink
Use inline exports
Browse files Browse the repository at this point in the history
  • Loading branch information
sobkulir committed Nov 15, 2019
1 parent 95006d0 commit 2d8c098
Show file tree
Hide file tree
Showing 27 changed files with 125 additions and 264 deletions.
3 changes: 1 addition & 2 deletions frontend/components/text-area.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ const Cursor: React.SFC<CursorProps> = (props) => {
return (<div style={getCursorStyles(props.letterSize)} />)
}

interface TextAreaProps extends EditorState {
export interface TextAreaProps extends EditorState {
setCursorPosition: typeof _setCursorPosition,
addSignAfterCursor: typeof _addSignAfterCursor,
moveCursor: typeof _moveCursor,
Expand Down Expand Up @@ -172,7 +172,6 @@ class TextArea extends React.Component<TextAreaProps, {}> {
}
}

export { TextAreaProps }
export default connect(
(state: State) => ({
...state.editor,
Expand Down
5 changes: 1 addition & 4 deletions frontend/lib/editor.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
import { Text } from '../redux/editor/types'
import { Sign } from './sign'

function CodeToString(text: Text): string {
export function CodeToString(text: Text): string {
return text.map(
(row) => row.letters.map((letter) => `${Sign[letter.sign]};`).join('')
).join('\n')
}

export { CodeToString }

5 changes: 1 addition & 4 deletions frontend/lib/sign.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
enum Sign {
export enum Sign {
A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S, T, U, V, W, X, Y, Z,
a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z,
_,
Expand All @@ -11,6 +11,3 @@ enum Sign {
CLASS, FUNCTION, RETURN, CONTINUE, BREAK,
SPACE, SEMICOLON, QUOTE, COMMA, PROP,
}

export { Sign }

26 changes: 13 additions & 13 deletions frontend/lib/text-area.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,23 @@ function CreateId(): string {
return Math.random().toString(36).substr(2, 5)
}

class LetterImp implements Letter {
export class LetterImp implements Letter {
[immerable] = true
readonly id: string
constructor(readonly sign: Sign) {
this.id = `${sign}_${CreateId()}`
}
}

class LetterRowImp implements LetterRow {
export class LetterRowImp implements LetterRow {
[immerable] = true
readonly id: string
constructor(readonly letters: Letter[]) {
this.id = CreateId()
}
}

function TrimPositionRowCol(position: PositionRowCol, text: Text):
export function TrimPositionRowCol(position: PositionRowCol, text: Text):
PositionRowCol {
const rowLength = (text.length > 0) ? text.length - 1 : 0
const row = Math.min(rowLength, position.row)
Expand All @@ -32,7 +32,7 @@ function TrimPositionRowCol(position: PositionRowCol, text: Text):
return { row, col }
}

function PositionPixelsToRowCol(
export function PositionPixelsToRowCol(
letterSize: LetterSize, position: PositionPixels): PositionRowCol {
const boxSize = letterSize.edgePx + 2 * letterSize.marginPx
const row = Math.floor(position.y / boxSize)
Expand All @@ -41,7 +41,7 @@ function PositionPixelsToRowCol(
return { row, col }
}

function PositionRowColToPixels(
export function PositionRowColToPixels(
letterSize: LetterSize, position: PositionRowCol): PositionPixels {
const boxSize = letterSize.edgePx + 2 * letterSize.marginPx
const x = position.col * boxSize
Expand All @@ -50,7 +50,8 @@ function PositionRowColToPixels(
}

// Expects cursor to be in a valid state.
function MoveCursorRight(position: PositionRowCol, text: Text): PositionRowCol {
export function MoveCursorRight(
position: PositionRowCol, text: Text): PositionRowCol {
const rowWidth = text[position.row].letters.length
if (position.col + 1 <= rowWidth) {
return { row: position.row, col: position.col + 1 }
Expand All @@ -62,7 +63,8 @@ function MoveCursorRight(position: PositionRowCol, text: Text): PositionRowCol {
}

// Expects cursor to be in a valid state.
function MoveCursorLeft(position: PositionRowCol, text: Text): PositionRowCol {
export function MoveCursorLeft(
position: PositionRowCol, text: Text): PositionRowCol {
if (position.col - 1 >= 0) {
return { row: position.row, col: position.col - 1 }
} else if (position.row - 1 >= 0) {
Expand All @@ -73,7 +75,8 @@ function MoveCursorLeft(position: PositionRowCol, text: Text): PositionRowCol {
}

// Expects cursor to be in a valid state.
function MoveCursorUp(position: PositionRowCol, text: Text): PositionRowCol {
export function MoveCursorUp(
position: PositionRowCol, text: Text): PositionRowCol {
const rowUp = position.row - 1
if (rowUp >= 0) {
return {
Expand All @@ -89,7 +92,8 @@ function MoveCursorUp(position: PositionRowCol, text: Text): PositionRowCol {
}

// Expects cursor to be in a valid state.
function MoveCursorDown(position: PositionRowCol, text: Text): PositionRowCol {
export function MoveCursorDown(
position: PositionRowCol, text: Text): PositionRowCol {
const rowDown = position.row + 1
if (rowDown < text.length) {
return {
Expand All @@ -104,7 +108,3 @@ function MoveCursorDown(position: PositionRowCol, text: Text): PositionRowCol {
}
}
}


export { LetterImp, LetterRowImp, PositionPixelsToRowCol, PositionRowColToPixels, TrimPositionRowCol, MoveCursorRight, MoveCursorLeft, MoveCursorDown, MoveCursorUp }

6 changes: 1 addition & 5 deletions frontend/redux/configure-store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,8 +133,4 @@ const rootReducer = (
else return action.reducer(state)
}


const configureStore = () => createStore(rootReducer, getInitialState())

export { configureStore }

export const configureStore = () => createStore(rootReducer, getInitialState())
31 changes: 15 additions & 16 deletions frontend/redux/editor/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { LetterImp, LetterRowImp, MoveCursorDown, MoveCursorLeft, MoveCursorRigh
import { MyAction, State } from '../types'
import { PositionPixels, RunState } from './types'

const setCursorPosition =
export const setCursorPosition =
(positionPixels: PositionPixels): MyAction<PositionPixels> => ({
type: 'Set cursor position',
payload: positionPixels,
Expand All @@ -22,7 +22,7 @@ const setCursorPosition =
})
})

const addSignAfterCursor =
export const addSignAfterCursor =
(sign: Sign): MyAction<Sign> => ({
type: 'Add sign after cursor',
payload: sign,
Expand All @@ -35,9 +35,9 @@ const addSignAfterCursor =
})
})

enum Direction { UP, RIGHT, DOWN, LEFT }
export enum Direction { UP, RIGHT, DOWN, LEFT }

const moveCursor =
export const moveCursor =
(direction: Direction): MyAction<Direction> => ({
type: 'Move cursor',
payload: direction,
Expand All @@ -61,7 +61,7 @@ const moveCursor =
})
})

const removeAfterCursor =
export const removeAfterCursor =
(): MyAction<void> => ({
type: 'Remove after cursor',
reducer: produce((state: State) => {
Expand All @@ -78,7 +78,7 @@ const removeAfterCursor =
})
})

const newlineAfterCursor =
export const newlineAfterCursor =
(): MyAction<void> => ({
type: 'Newline after cursor',
reducer: produce((state: State) => {
Expand All @@ -92,7 +92,7 @@ const newlineAfterCursor =
})
})

const appendToOutput =
export const appendToOutput =
(output: string): MyAction<string> => ({
type: 'Append to output',
payload: output,
Expand All @@ -101,7 +101,7 @@ const appendToOutput =
})
})

const finishExecution =
export const finishExecution =
(): MyAction<void> => ({
type: 'Execution finished',
reducer: produce((state: State) => {
Expand All @@ -114,11 +114,12 @@ const finishExecution =
})
})

type NextStepArgs = {
export type NextStepArgs = {
resolveNextStep: () => void,
lineno: number
}
const newNextStep =

export const newNextStep =
(args: NextStepArgs): MyAction<NextStepArgs> => ({
type: 'New next step',
payload: args,
Expand All @@ -130,7 +131,7 @@ const newNextStep =
})


const giflangSetup: GiflangSetup = {
export const giflangSetup: GiflangSetup = {
onPrint:
(str: string) => { storeInstance.dispatch(appendToOutput(str))},
onFinish:
Expand All @@ -145,7 +146,7 @@ const giflangSetup: GiflangSetup = {
}
}

const executionStarted =
export const executionStarted =
(worker: Worker, isDebugMode: boolean): MyAction<Worker> => ({
type: 'Execution started',
reducer: produce((state: State) => {
Expand All @@ -155,7 +156,7 @@ const executionStarted =
})
})

async function StartExecution(code: string, isDebugMode: boolean) {
export async function StartExecution(code: string, isDebugMode: boolean) {
const vanillaWorker = new Worker()
const workerProxy =
Comlink.wrap<
Expand All @@ -169,7 +170,7 @@ async function StartExecution(code: string, isDebugMode: boolean) {
worker.run(code)
}

const startExecution =
export const startExecution =
(isDebugMode: boolean): MyAction<boolean> => ({
type: 'Start execution',
reducer: produce((state: State) => {
Expand All @@ -178,5 +179,3 @@ const startExecution =
StartExecution(CodeToString(state.editor.text), isDebugMode)
})
})
export { setCursorPosition, addSignAfterCursor, moveCursor, Direction, removeAfterCursor, newlineAfterCursor, appendToOutput, startExecution, finishExecution }

30 changes: 13 additions & 17 deletions frontend/redux/editor/types.ts
Original file line number Diff line number Diff line change
@@ -1,57 +1,53 @@
import { Sign } from '../../lib/sign'

interface LetterSize {
export interface LetterSize {
edgePx: number
marginPx: number
}

interface Letter {
export interface Letter {
id: string
sign: Sign
}

interface LetterRow {
export interface LetterRow {
id: string
letters: Letter[]
}

type AlphabetCategory = { name: string, signs: Sign[] }
type CategorizedAlphabet = AlphabetCategory[]
type Text = LetterRow[]
type FileName = string
type SignToGifMap = Map<Sign, FileName>
export type AlphabetCategory = { name: string, signs: Sign[] }
export type CategorizedAlphabet = AlphabetCategory[]
export type Text = LetterRow[]
export type FileName = string
export type SignToGifMap = Map<Sign, FileName>

interface PositionPixels {
export interface PositionPixels {
x: number
y: number
}

interface PositionRowCol {
export interface PositionRowCol {
row: number
col: number
}

enum RunState {
export enum RunState {
STARTING, RUNNING, DEBUG_WAITING, DEBUG_RUNNING, NOT_RUNNING
}

interface ExecutionState {
export interface ExecutionState {
state: RunState
output: string
worker: Worker | null
resolveNextStep: () => void
lineno: number
}

interface EditorState {
export interface EditorState {
text: Text,
cursorPosition: PositionRowCol
letterSize: LetterSize,
signToGifMap: SignToGifMap,
alphabet: CategorizedAlphabet,
execution: ExecutionState,
}


export { EditorState, RunState, Text, ExecutionState, LetterSize, SignToGifMap, PositionRowCol, PositionPixels, Letter, LetterRow, CategorizedAlphabet, AlphabetCategory }

5 changes: 1 addition & 4 deletions frontend/redux/storage/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { produce } from 'immer'
import { CodeToString } from '../../lib/editor'
import { MyAction, State } from '../types'

const saveCode =
export const saveCode =
(): MyAction<void> => ({
type: 'Save code',
reducer: produce((state: State) => {
Expand All @@ -14,6 +14,3 @@ const saveCode =
})
})
})

export { saveCode }

7 changes: 2 additions & 5 deletions frontend/redux/types.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,13 @@
import { EditorState } from './editor/types'

interface State {
export interface State {
readonly editor: EditorState
}

// "My" prefix is used to distinguish this interface from "Action" interface
// found in redux.
interface MyAction<Payload = undefined> {
export interface MyAction<Payload = undefined> {
type: string
payload?: Payload
reducer: (state: State) => State
}

export { State, MyAction }

7 changes: 2 additions & 5 deletions interpreter/ast/ast-node.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
type JisonLocator = {
export type JisonLocator = {
first_line: number,
first_column: number,
last_line: number,
last_column: number
}

abstract class AstNode {
export abstract class AstNode {
constructor(readonly locator: JisonLocator) { }
}

export { AstNode, JisonLocator }

Loading

0 comments on commit 2d8c098

Please sign in to comment.