UNPKG

functionalscript

Version:

FunctionalScript is a purely functional subset of JavaScript

55 lines (54 loc) 1.28 kB
import { cp, range, remove, set, str } from "../bnf/func/module.f.js"; import { digit, json, unicode, ws0, ws1, wsNoNewLine0 } from "./json.f.js"; export const wsModule = () => [[ws0, module]]; const module = () => [ [json, ws0], [fjs], ]; const fjs = () => [ [], [...str('const'), ws1, id, ws0, cp('='), ws0, json, wsNoNewLine0, fjsTail], [...str('export'), ws1, ...str('default'), ws1, json], ]; const fjsTail = () => [ [], [cp('\n'), ws0, fjs], ]; // line comment const lineItem = () => remove(unicode, [cp('\n')]); const line = () => [ [], [lineItem, line] ]; const lineComment = () => [ [cp('/'), commentTail, cp('\n')] ]; const multiLineSkip = () => remove(unicode, [cp('/')]); const multiLineItem = () => remove(unicode, [cp('*')]); const multiLine = () => [ [cp('*'), multiLineTail], [multiLineItem, multiLine] ]; const multiLineTail = () => [ [cp('/')], [multiLineSkip, multiLine] ]; const commentTail = () => [ [cp('/'), lineComment], [cp('*'), multiLine], ]; // id const id = () => [[alpha, idTail0]]; const alpha = () => [ [range('AZ')], [range('az')], ...set('_$'), ]; const idTail0 = () => [ [], [alphaDigit, idTail0], ]; const alphaDigit = () => [ [alpha], [digit], ];