-
Notifications
You must be signed in to change notification settings - Fork 211
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Began Work on Fixing Nested Syntax #551
base: master
Are you sure you want to change the base?
Conversation
@@ -58,6 +58,9 @@ const binaryOps = ["+", "-", "*", "/", "%","<<", ">>", ">>>", "&", "|", "^", | |||
|
|||
const unaryOps = ["++", "--", "~", "!", "delete", "void", "typeof", "yield", "throw", "new"]; | |||
|
|||
// Any -> Boolean | |||
const isNotFalse = R.compose(R.not, R.curry(R.equals)(false)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I generally agree with this style, but this just seems counterproductive :).
const isNotFalse = R.compose(R.not, R.curry(R.equals)(false));
// vs
const isNotFalse = function (b) { return b !== false; };
(also, why isn't R.equals
curried by default in Ramda?)
EDIT: it actually is! That'd work:
const isNotFalse = R.compose(R.not, R.equals(false));
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fair enough :)
I just was trying to emulate the existing style as much as I could. I can change that to a simple function instead.
So I just had a crazy idea. Syntax template are already syntactically special so what if we just don't escape them? Beginning ( Normal templates still need to be escaped of course. syntax m = ctx => {
return #`
syntax n = ctx => {
let s = \`foo\`;
return #`
syntax o = ctx => {
return #`1`
}
`
}
`
} This avoids the need to count backslashes and all that. This approach confuses existing syntax highlighters a little but since all the backticks must be balanced the confusion is localized to the syntax templates themselves. Does this seem reasonable or am I missing something? |
@disnet That seems perfectly reasonable (it's the same approach Racket takes!) |
Oh! The trick is nested interpolations: let s = #`
let ss = #`foo \${42}`
`; You'll need to count escapes for those I think. |
Okay, so a double escape look like |
How would |
Using the standard escaping for
|
Ah! I see what you meant. Yeah do that 😄 |
@disnet if we took care of syntax templates with a combination of reader macros and syntactic extensions, we could do this: syntax m = ctx => {
return #`
syntax n = ctx => {
let s = \`foo\`;
return ${ #`
syntax o = ctx => {
return ${ #`1` }
}
` }
}
`
} This way a syntax m = ctx => {
return syntaxTemplate`
syntax n = ctx => {
let s = \`foo\`;
return ${ syntaxTemplate`
syntax o = ctx => {
return ${ syntaxTemplate`1` }
}
` }
}
`
} Thus syntax n = ctx => {
let s = \`foo\`;
return ${ #`
syntax o = ctx => {
return ${ #`1` }
}
` }
} This way we don't have to invent a special escape syntax for nested interpolations and IMO looks a lot cleaner. |
@gabejohnson humm...I'm not following. Could you expand (ha!) on what you meant? |
😝 My point is that if you just require interpolating if you're nesting syntax templates you can avoid any special syntax and just parallel the syntax used by template literals already: syntax m = ctx => {
return #`
syntax n = ctx => {
let s = \`foo\`;
return ${ #`
syntax o = ctx => {
return ${ #`${ ctx.next().value }` }
}
` }
}
`
} vs. syntax m = ctx => {
return #`
syntax n = ctx => {
let s = \`foo\`;
return #\`
syntax o = ctx => {
return #\`\\${ ctx.next().value }\`
}
\`
}
`
} or syntax m = ctx => {
return #`
syntax n = ctx => {
let s = \`foo\`;
return #`
syntax o = ctx => {
return #`\\${ ctx.next().value }`
}
`
}
`
} While there are more characters at shallow nesting depths, you don't have to count slashes as you nest. |
@gabejohnson I like that, I think it feels the most natural. |
Something I just thought of. Which context does the innermost |
NOTE: This PR is not ready to merge!
I have begun working on fixing #519, but I have reached a bit of a stumbling block. I have gotten
shift-reader.js
to accept files with nested syntax, but something is getting garbled in between (details below), leading me to believe that I'm missing some step in the expander pipeline.To explain where I'm at, here's what I know:
src/shift-reader.js
.src/shift-reader.js
'sadvance
function (master) returns a token of typeLSYNTAX
.is that the handler for
LSYNTAX
bundles all of the read pieces together into an immutable list.advance
insrc/shift-reader.js
does not handle the"
"` character (or it's escaped variant), so it delegates to the superclass (which also does not handle it).Thus, I figured that fixing the error would just be a matter of adding the proper escapes to
advance
, allowing nested syntax objects to be read correctly. As far as reading the syntax goes, this all seems to work correctly. Note: This change is what the first commit of this PR reflects.So, what happened? I tried to run this modified version on the following code:
The result was the following error messsage:
Let's first dissect the syntax object in question as follows:
Now, here's what I can tell happens:
read
(my fork's copy) will tokenize<ret>
and<ret_nested>
just fine;<ret>
is an immutable list with an entry at index-whatever that is another immutable list corresponding to <ret_nested>deserializer.read(str)
inloadForCompileTime
(my fork's copy), the location of<ret_nested>
in<ret>
is set tonull
. Why? Not a clue.And that is where I'm at. Am I missing some step here? I feel like this is, if nothing else a step in the right direction; nested syntax is a powerful feature to have, so I'd love to get this fixed!