Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/astupdate.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,9 @@ const formMultiPatternAst = (funcdecl, patterndecls) => {

const isArrowFuncDecl = (decl) => {
const declarations = decl.declarations

if (
declarations !== undefined &&
declarations[0].init &&
declarations[0].init.type === 'ArrowFunctionExpression'
) { return true }
return false
Expand Down
29 changes: 29 additions & 0 deletions lib/basicParsers.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ const estemplate = require('./estemplate')
const {
maybe,
isLanguageConstruct,
isReservedFnCall,
isStaticIOMethod,
isIOMethod,
isDOMmethod,
Expand Down Expand Up @@ -33,6 +34,8 @@ const openParensRegex = () => /^(\()((.|\n)*)$/
const closeParensRegex = () => /^(\))((.|\n)*)$/
const commaRegex = () => /^(,)((.|\n)*)$/
const colonRegex = () => /^(:)((.|\n)*)$/
const vBarRegex = () => /^(\|\s+)((.|\n)*)$/
const otherwiseRegex = () => /^(otherwise)((.|\n)*)$/
const singleLineCommentRegex = () => /^((\/\/)(.*)(?=\n|))((.|\n)*)$/
const multiLineCommentRegex = () =>
/^((\/\*)((.|\n)*?)(\*\/))((.|\n)*)$/
Expand All @@ -50,6 +53,7 @@ const dotRegex = () => /^(\.)((.|\n)*)$/
const ifRegex = () => /^(if\s+)((.|\n)*)$/
const thenRegex = () => /^(then\s+)((.|\n)*)$/
const elseRegex = () => /^(else\s+)((.|\n)*)$/
const whereRegex = () => /^(where\s+)((.|\n)*)$/
const doRegex = () => /^(do)((.|\n)*)$/
const returnKeywordRegex = () => /^(return)((.|\n)*)$/
const includeKeywordRegex = () => /^(include)((.|\n)*)$/
Expand Down Expand Up @@ -84,6 +88,8 @@ const ifParser = (input) => parser.regex(ifRegex)(input)
const thenParser = (input) => parser.regex(thenRegex)(input)
const elseParser = (input) => parser.regex(elseRegex)(input)

const whereParser = (input) => parser.regex(whereRegex)(input)

const doParser = (input) => parser.regex(doRegex)(input)

const returnKeywordParser = (input) =>
Expand Down Expand Up @@ -119,6 +125,17 @@ const nonReservedIdParser = (input) =>
: [estemplate.identifier(name), rest]
)

const nonReservedIdFnCallParser = (input) =>
maybe(idParser(input), (name, rest) =>
isLanguageConstruct(name) ||
isReservedFnCall(name) ||
isStaticIOMethod(name) ||
isIOMethod(name) ||
isDOMmethod(name)
? null
: [estemplate.identifier(name), rest]
)

const identifierParser = (input) =>
maybe(idParser(input), (name, rest) => [
estemplate.identifier(name),
Expand Down Expand Up @@ -222,6 +239,14 @@ const colonParser = (input) =>
rest
])

const vBarParser = (input) =>
maybe(parser.regex(vBarRegex)(input), (bar, rest) => [
bar,
rest
])

const otherwiseParser = (input) => parser.regex(otherwiseRegex)(input)

const singleLineCommentParser = (input) =>
maybe(singleLineCommentRegex().exec(input.str), (...vals) => {
const [, , , val, rest] = vals
Expand Down Expand Up @@ -319,6 +344,7 @@ module.exports = {
maybeNewLineAndIndent,
numberParser,
nonReservedIdParser,
nonReservedIdFnCallParser,
identifierParser,
domMethodParser,
ioFuncNameParser,
Expand All @@ -335,6 +361,8 @@ module.exports = {
closeSquareBracketParser,
commaParser,
colonParser,
vBarParser,
otherwiseParser,
singleLineCommentParser,
multiLineCommentParser,
binaryOperatorParser,
Expand All @@ -347,6 +375,7 @@ module.exports = {
ifParser,
thenParser,
elseParser,
whereParser,
doParser,
equalSignParser,
slashParser,
Expand Down
23 changes: 13 additions & 10 deletions lib/estemplate.js
Original file line number Diff line number Diff line change
Expand Up @@ -160,14 +160,15 @@ estemplate.printexpression = (args) => ({
sType: 'IO'
})

estemplate.fnCall = (val, args) =>
val.name === 'print'
? estemplate.printexpression(args)
: {
type: 'CallExpression',
callee: extractExpr(val),
arguments: args.map(extractExpr)
}
estemplate.reservedCalls = {
print: (args) => estemplate.printexpression(args)
}

estemplate.fnCall = (val, args) => ({
type: 'CallExpression',
callee: extractExpr(val),
arguments: args.map(extractExpr)
})

estemplate.lambda = (params, body) => ({
type: 'ExpressionStatement',
Expand Down Expand Up @@ -220,12 +221,14 @@ estemplate.ifthenelse = (condition, result1, result2) => ({
}
})

estemplate.ifStmt = (predicate, consequent) => ({
estemplate.ifStmt = (predicate, consequent, isReturn = false) => ({
type: 'IfStatement',
test: predicate,
consequent: {
type: 'BlockStatement',
body: [consequent, estemplate.returnStmt(null)]
body: isReturn
? [estemplate.returnStmt(consequent)]
: [consequent, estemplate.returnStmt(null)]
},
alternate: null
})
Expand Down
13 changes: 10 additions & 3 deletions lib/languageConstructs.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,17 @@ const languageConstructs = {
false: true,
null: true,
do: true,
console: true,
return: true,
delete: true,
defineProp: true
defineProp: true,
otherwise: true
}

module.exports = languageConstructs
const reservedFnCalls = {
print: true
}

module.exports = {
languageConstructs,
reservedFnCalls
}
Loading