-
Notifications
You must be signed in to change notification settings - Fork 14
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
Parse nested tags with equal name (solves #3) #8
base: master
Are you sure you want to change the base?
Conversation
…ore '/>'. Add '<there/>' example to the test suite. Update the tests for version 4.2 to 5 of elm-test. No more Main.elm. Remove elm-doc-test installation and use. There aren't any doc tests, and it was generating files that didn't compile on my machine.
I made a pull request on myrho's fork which fixes one small bug and also updates the tests for the latest version of elm-test, fixing the problem that makes this pull request fail. But myrho has not replied. I could package up both his and my changes as a pull request here, if you'd like. You may also be interested in billstclair/elm-xml-extra, which makes it easy to write JSON Decoders for simple XML (ignoring the attributes). |
Parse a self-closing tag with no attributes and no space before '/>'
The test failure is a Travis problem. The macOS build worked. Restart the Linux build, and it should also work. |
@@ -24,7 +24,6 @@ install: | |||
- npm --version | |||
- npm install -g elm@$ELM_VERSION | |||
- npm install -g elm-test | |||
- npm install -g elm-doc-test |
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.
why was this removed? 🤔
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.
It wasn't working for me, likely due to an elm-doc-test bug when there aren't any doc tests. It's a good template, but wasn't used by this package. I'd prefer a solution that made it work, but I was too lazy at the time. Will work on a proper solution if you want.
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.
It was used by this package. There are multiple doc tests. They likely need to be upgraded to use elm-verify-examples: but they should be upgraded, not dropped.
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 see that elm-doc-test has been renamed to elm-verify-examples.
elm-doc-test 4.0.0 creates elm files that don't compile, when there are no doc tests.
The latest version of elm-verify-examples does not have that problem. I'll push a change to use that instead.
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.
thanks!
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.
These are doc tests: https://github.com/eeue56/elm-xml/blob/master/src/Xml/Decode.elm#L171
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. Perhaps at one time ">>>" was the magic prefix for a doc test. Now it is "-->". I've never used them, so I have no memory of when that changed.
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.
Yep. So in order to switch, you'll need to change the syntax of the examples
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 figured out what happened. Referencing https://github.com/stoeffel/elm-verify-examples/commits/master :
Jun 14, "Proposal new dsl" changed the syntax.
Jun 16, "Version 4.0.0" (of elm-doc-test) released.
Jun 16, "Renaming to elm-verify-examples".
Jun 17, "Version 1.0.1" (of elm-verify-examples) released.
The Travis script was getting elm-doc-test version 4.0.0, with the new syntax, hence failing.
I added a PR to @myrho's fork to update all the comment tests to the new syntax. Travis is happy in Linux, but still waiting to run the macOS test.
Hopefully, @myrho will check in soon, fix the other issues, and commit to add his and my fixes to this PR.
I also added syconfcpus to the Travis script, to speed "elm make" from minutes to seconds. Yes. It's that amazing.
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.
Just open a new PR against here, no need to merge into the fork
@@ -92,19 +101,59 @@ parseSlice first firstClose trimmed = | |||
|
|||
closeTag = | |||
"</" ++ tagName ++ ">" | |||
|
|||
openTag = | |||
"<" ++ Regex.escape tagName ++ "[\\s\\n]*[^/]*?>" |
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.
Defining regexes at runtime like this can lead to runtime errors, they should instead be defined as flatly as possible, see propRegex
. In the cases where they can't, I'd rather not use a regex for that.
"<" ++ Regex.escape tagName ++ "[\\s\\n]*[^/]*?>" | ||
|> Regex.regex | ||
|
||
openTags = |
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.
type signatures here would help make the code readable
++ closeTags | ||
|> List.sortBy second | ||
|
||
reduce list = |
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.
This name doesn't make it obvious to me what this function is meant to do
else if (String.contains "/>" trimmed) then | ||
Ok ( Tag tagName props (Object []), firstClose + 1 ) | ||
else if String.endsWith "/" beforeClose then | ||
let tag = if String.endsWith "/" tagName then |
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.
this should be on a newline
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.
Sorry. I just started using elm-format. Was naughty about such things in the past. Will fix. By saving in my editor. :)
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.
see comments for things I'd like answered before merging. sorry for taking so long, I didn't get a notification for this til today!
@myrho Would be great if you could rebase this PR on master now that it has updated tests etc :) |
Code and tests to allow parsing of
<tag><tag></tag></tag>
strings.Looks ahead for open and close tags, puts 'em in a list and then reduces consecutive pairs in the list to elements.