-
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?
Changes from all commits
579b68f
4d39453
2d0b3a5
7217aba
95e7b06
40ef52d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,3 @@ | ||
#!/bin/bash | ||
|
||
elm-doc-test | ||
elm-test | ||
elm-test |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,6 +12,7 @@ module Xml.Decode exposing (decode, decodeInt, decodeString, decodeFloat, decode | |
import Dict | ||
import Regex exposing (Regex) | ||
import Xml exposing (Value(..)) | ||
import Tuple exposing (second) | ||
|
||
|
||
{-| Try and decode the props from a string | ||
|
@@ -72,12 +73,20 @@ findProps = | |
>> Dict.fromList | ||
|
||
|
||
type Tag | ||
= OpenTag | ||
| CloseTag | ||
|
||
|
||
parseSlice : Int -> Int -> String -> Result String ( Value, Int ) | ||
parseSlice first firstClose trimmed = | ||
let | ||
beforeClose = | ||
String.slice (first + 1) firstClose trimmed | ||
|
||
afterOpen = | ||
String.slice (first + 1) (String.length trimmed) trimmed | ||
|
||
words = | ||
beforeClose | ||
|> String.words | ||
|
@@ -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 commentThe 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 |
||
|> Regex.regex | ||
|
||
openTags = | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. type signatures here would help make the code readable |
||
Regex.find Regex.All openTag afterOpen | ||
|> List.map (.index >> (,) OpenTag) | ||
|
||
closeTags = | ||
String.indexes closeTag trimmed | ||
|> List.map ((,) CloseTag) | ||
|
||
allTags = | ||
openTags | ||
++ closeTags | ||
|> List.sortBy second | ||
|
||
reduce list = | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||
case list of | ||
( OpenTag, i1 ) :: ( CloseTag, i2 ) :: rest -> | ||
reduce rest | ||
|
||
( OpenTag, i1 ) :: rest -> | ||
case reduce rest of | ||
( CloseTag, i2 ) :: rest -> | ||
reduce rest | ||
|
||
rest -> | ||
rest | ||
|
||
_ -> | ||
list | ||
in | ||
case String.indexes closeTag trimmed of | ||
[] -> | ||
case List.head <| reduce allTags of | ||
Nothing -> | ||
if String.startsWith "?" tagName then | ||
Ok ( DocType tagName props, firstClose + 1 ) | ||
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 commentThe 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 commentThe 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. :) |
||
String.slice 0 -1 tagName | ||
else | ||
tagName | ||
in | ||
Ok ( Tag tag props (Object []), firstClose + 1 ) | ||
else if String.startsWith "!" tagName then | ||
Ok ( Object [], firstClose + 1 ) | ||
else | ||
"Failed to find close tag for " | ||
++ tagName | ||
|> Err | ||
|
||
firstCloseTag :: _ -> | ||
Just ( _, firstCloseTag ) -> | ||
let | ||
contents = | ||
String.slice (firstClose + 1) (firstCloseTag) trimmed | ||
|
This file was deleted.
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.
https://github.com/stoeffel/elm-verify-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.
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