Skip to content
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

Open
wants to merge 6 commits into
base: master
Choose a base branch
from

Conversation

myrho
Copy link

@myrho myrho commented Jun 1, 2017

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.

myrho and others added 5 commits February 27, 2017 07:50
…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.
@billstclair
Copy link
Contributor

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 '/>'
@billstclair
Copy link
Contributor

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
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why was this removed? 🤔

Copy link
Contributor

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.

Copy link
Owner

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.

Copy link
Contributor

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.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks!

Copy link
Owner

@eeue56 eeue56 Dec 5, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor

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.

https://github.com/stoeffel/elm-verify-examples

Copy link
Owner

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

Copy link
Contributor

@billstclair billstclair Dec 6, 2017

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.

Copy link
Owner

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]*[^/]*?>"
Copy link
Owner

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 =
Copy link
Owner

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 =
Copy link
Owner

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
Copy link
Owner

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

Copy link
Contributor

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. :)

Copy link
Owner

@eeue56 eeue56 left a 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!

@eeue56
Copy link
Owner

eeue56 commented Dec 6, 2017

@myrho Would be great if you could rebase this PR on master now that it has updated tests etc :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants