Permalink
Browse files

FIX: one-lines working AND so is everything else

  • Loading branch information...
shanebdavis committed Sep 26, 2017
1 parent 2e9137a commit 7ed195bdc5f5270e01c439ed6e2332d495a8b7b9
@@ -4,13 +4,20 @@ import &StandardImport
@rule
_: "" / +/ comment?
end: :lineEndComment
onelinerEnd: "" _? comment? /; */ comment?
comment:
{} pattern: "/##[^\n]*/ unparsedBlock*"
{} pattern: /\ *#([^\n$\w\u007f-\uffff]+[^\n]*|(?=\n|$))/
_end: /( *(\n|; *|$))+/
_end:
///
(\ * (\n | ;\ * | $) )+
|
(\ * (?=\)))
# A close-parenthesis can be considered an 'end'
# This is makes this parse: (-> 1).
# Without it, the "1" wouldn't be a statement.
# NOTE: the close-paren is not 'consumed' by this regexp.
lineStartComment: "comment _end" "_end"
lineEndComment: "_? comment? _end lineStartComment*"
@@ -1,74 +1,48 @@
import &StandardImport, &CaffeineEight
getPropertySetters = (node, list = []) ~>
if node
if prop = node.shouldSetProperty?()
list.push prop
else
each match in node.matches
getPropertySetters match, list
list
->
@rule
functionDefinition:
"args:argsDefinition? _arrow_ body:oneLinerBody"
"args:argsDefinition? _arrow_ body:functionDefinitionBodyBlock?"
{}
stnFactory: :FunctionDefinitionStn
stnProps: ~>
bound: switch @_arrow_.text.match(/(=>|~>|->)/)[0]
when :=> then true
when :~> then false
when :-> then :auto
else throw new Error
@rule
functionDefinitionBodyBlock: Extensions.IndentBlocks.getPropsToSubparseBlock()
semicolonStatement: "onelinerEnd statementWithoutEnd"
@rule
oneLinerBody: "statementWithoutEnd semicolonStatement*"
{} stnFactory: :StatementsStn
@rule
argsDefinition:
"openParen_ argDefList? _closeParen"
{}
stnFactory: :FunctionDefinitionArgsStn
@rule
argDefList:
"argDef _comma_ argDefList"
"argDef _ argDefList"
"argDef"
@rule
argDef:
"at:/@/? target:identifier argIdentifierExtension?"
"target:destructuringTarget argIdentifierExtension?"
{}
stnFactory: "FunctionDefinitionArgStn"
stnProps: ~> rest: !!@argIdentifierExtension?.ellipsis, assignThisProperty: !!@at
@rule
argIdentifierExtension:
:defaultValue
:ellipsis
defaultValue:
pattern: "_equals_ expression"
@rule superFunctionInvocation:
"openParen_ simpleValueList? _closeParen"
"_? valueList"
@rule
functionInvocationExtension:
"existanceTest:questionMark? openParen_ values:simpleValueList? _closeParen"
"existanceTest:questionMark? !/[-+]/ _? values:valueList"
{}
stnFactory: "FunctionInvocationStn"
stnExtension: true
stnProps: ~> existanceTest: !!@existanceTest
stnChildren: ~> @values?.getStn()
functionDefinition:
"args:argsDefinition? _arrow_ body:functionDefinitionBodyBlock?"
stnFactory: :FunctionDefinitionStn
stnProps: ~>
bound: switch @_arrow_.text.match(/(=>|~>|->)/)[0]
when :=> then true
when :~> then false
when :-> then :auto
else throw new Error
functionDefinitionBodyBlock: Extensions.IndentBlocks.getPropsToSubparseToEolAndBlock
allowPartialMatch: true
argsDefinition:
"openParen_ argDefList? _closeParen"
stnFactory: :FunctionDefinitionArgsStn
argDefList:
"argDef _comma_ argDefList"
"argDef _ argDefList"
"argDef"
argDef:
"at:/@/? target:identifier argIdentifierExtension?"
"target:destructuringTarget argIdentifierExtension?"
stnFactory: "FunctionDefinitionArgStn"
stnProps: ~> rest: !!@argIdentifierExtension?.ellipsis, assignThisProperty: !!@at
argIdentifierExtension:
:defaultValue
:ellipsis
defaultValue:
pattern: "_equals_ expression"
superFunctionInvocation:
"openParen_ simpleValueList? _closeParen"
"_? valueList"
functionInvocationExtension:
"existanceTest:questionMark? openParen_ values:simpleValueList? _closeParen"
"existanceTest:questionMark? !/[-+]/ _? values:valueList"
stnFactory: "FunctionInvocationStn"
stnExtension: true
stnProps: ~> existanceTest: !!@existanceTest
stnChildren: ~> @values?.getStn()
@@ -6,12 +6,11 @@ Caf.defMod(module, () => {
{
_: "/ +/ comment?",
end: "lineEndComment",
onelinerEnd: "_? comment? /; */ comment?",
comment: [
{ pattern: "/##[^\n]*/ unparsedBlock*" },
{ pattern: /\ *#([^\n$\w\u007f-\uffff]+[^\n]*|(?=\n|$))/ }
],
_end: /( *(\n|; *|$))+/,
_end: /( *(\n|; *|$))+|( *(?=\)))/,
lineStartComment: ["comment _end", "_end"],
lineEndComment: "_? comment? _end lineStartComment*"
},
@@ -1,34 +1,14 @@
"use strict";
let Caf = require("caffeine-script-runtime");
Caf.defMod(module, () => {
let getPropertySetters, Extensions, Error;
let Extensions, Error;
({ Extensions, Error } = Caf.import(
["Extensions", "Error"],
[global, require("../StandardImport"), require("caffeine-eight")]
));
getPropertySetters = function(node, list = []) {
let prop;
if (node) {
if (
(prop = Caf.isF(node.shouldSetProperty) && node.shouldSetProperty())
) {
list.push(prop);
} else {
Caf.each(node.matches, undefined, (match, k, into) => {
getPropertySetters(match, list);
});
}
}
return list;
};
return function() {
this.rule(
{
functionDefinition: [
"args:argsDefinition? _arrow_ body:oneLinerBody",
"args:argsDefinition? _arrow_ body:functionDefinitionBodyBlock?"
]
},
return {
functionDefinition: [
"args:argsDefinition? _arrow_ body:functionDefinitionBodyBlock?",
{
stnFactory: "FunctionDefinitionStn",
stnProps: function() {
@@ -50,29 +30,18 @@ Caf.defMod(module, () => {
};
}
}
);
this.rule({
functionDefinitionBodyBlock: Extensions.IndentBlocks.getPropsToSubparseBlock(),
semicolonStatement: "onelinerEnd statementWithoutEnd"
});
this.rule(
{ oneLinerBody: "statementWithoutEnd semicolonStatement*" },
{ stnFactory: "StatementsStn" }
);
this.rule(
{ argsDefinition: "openParen_ argDefList? _closeParen" },
],
functionDefinitionBodyBlock: Extensions.IndentBlocks.getPropsToSubparseToEolAndBlock(
{ allowPartialMatch: true }
),
argsDefinition: [
"openParen_ argDefList? _closeParen",
{ stnFactory: "FunctionDefinitionArgsStn" }
);
this.rule({
argDefList: ["argDef _comma_ argDefList", "argDef _ argDefList", "argDef"]
});
this.rule(
{
argDef: [
"at:/@/? target:identifier argIdentifierExtension?",
"target:destructuringTarget argIdentifierExtension?"
]
},
],
argDefList: ["argDef _comma_ argDefList", "argDef _ argDefList", "argDef"],
argDef: [
"at:/@/? target:identifier argIdentifierExtension?",
"target:destructuringTarget argIdentifierExtension?",
{
stnFactory: "FunctionDefinitionArgStn",
stnProps: function() {
@@ -86,24 +55,16 @@ Caf.defMod(module, () => {
};
}
}
);
this.rule({
argIdentifierExtension: ["defaultValue", "ellipsis"],
defaultValue: { pattern: "_equals_ expression" }
});
this.rule({
superFunctionInvocation: [
"openParen_ simpleValueList? _closeParen",
"_? valueList"
]
});
return this.rule(
{
functionInvocationExtension: [
"existanceTest:questionMark? openParen_ values:simpleValueList? _closeParen",
"existanceTest:questionMark? !/[-+]/ _? values:valueList"
]
},
],
argIdentifierExtension: ["defaultValue", "ellipsis"],
defaultValue: { pattern: "_equals_ expression" },
superFunctionInvocation: [
"openParen_ simpleValueList? _closeParen",
"_? valueList"
],
functionInvocationExtension: [
"existanceTest:questionMark? openParen_ values:simpleValueList? _closeParen",
"existanceTest:questionMark? !/[-+]/ _? values:valueList",
{
stnFactory: "FunctionInvocationStn",
stnExtension: true,
@@ -115,6 +76,6 @@ Caf.defMod(module, () => {
return Caf.exists((cafBase = this.values)) && cafBase.getStn();
}
}
);
]
};
});
@@ -78,11 +78,18 @@ module.exports = suite: parseTestSuite
insideParens:
"(-> 1)": "(function() {return 1;});"
"(-> (~> 1))": "(function() {return function() {return 1;};});"
# "(-> (~> 1))": "(function() {return function() {return 1;};});"
multistatement:
"-> 1; 2": "(function() {1; return 2;});"
regressions:
"""
a: ~> b: 1
c: 2
""": "({a: function() {return {b: 1};}, c: 2});"
argDestructuring:
basic:
"({a}) =>": "({a}) => {};"

0 comments on commit 7ed195b

Please sign in to comment.