-
Notifications
You must be signed in to change notification settings - Fork 49
DSLTree #134
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
DSLTree #134
Conversation
4e6ecf6
to
fb53d30
Compare
/// An embedded literal | ||
case regexLiteral(AST.Node) |
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.
Would an embedded literal be able to contain global options?
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.
Hmm, global options that pertain only to that fragment I suppose. How would global options interact with the ability to interpolate regex literals?
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.
Hmm yeah, I guess they would have to form their own scope in which they're only active in that portion of the regex
/// (?(cond) true-branch | false-branch) | ||
case conditional( | ||
AST.Conditional.Condition.Kind, Node, Node) |
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.
Should the condition kind get converted too (as it can contain a recursive AST.Group
)?
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.
Ah, I didn't look into that part far enough yet. Good catch.
// No need to nest single children concatenations | ||
if astChildren.count == 1 { | ||
return astChildren.first!.dslTreeNode | ||
} |
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.
When do single-child concatenations occur? I kind of wonder whether AST.Concatenation
should enforce that children.count >= 2
(and maybe have a utility that produces concat-or-self), or is it better for compatibility with the DSL to allow them?
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’m in favor of enforcing a plural count.
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.
How would we enforce that in the DSL? Would we error out if given a single member? I worry there could be impact with sensible refactoring like quoting a literal run of characters vs listing each separately.
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.
The builder DSL always supports having a singular element in a block, e.g. Regex { "a" }
. It's just that buildBlock(_:)
(unary) never creates a concatenation in this scenario, but returns the argument instead. As such, I'm not sure a singular concatenation would ever be created.
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.
Ok, I'm fine with the invariant on the parser's AST, though we could still argue that we want to coalesce runs of characters into quotes anyways, so that abc|def
is
Alternation {
"abc"
"def"
}
but I agree it doesn't have to be part of this transformation, could be part of printing, etc.
We'll want to do some analysis and optimization, and doing so on a tree is a classic compiler smell, but I doubt we'll have a real IR in the near future.
65cb15b
to
4ee95a0
Compare
4ee95a0
to
30875af
Compare
@swift-ci please test linux platform |
@hamishknight @rxwei I had to move some stuff around, can you take a look at this PR again to see if it's mergeable? |
DSLTree, a shared representation for compilation and printing Bug fix in matching engine for reading subsequences out of bounds DSLTree hooked up to legacy VMs
DSLTree is an internal representation shared between literals and result builders.