Skip to content
This repository has been archived by the owner on Feb 10, 2021. It is now read-only.

added String modifier to parse-string #29

Open
wants to merge 58 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
58 commits
Select commit Hold shift + click to select a range
c58ef5d
Update elm-package.json
Feb 28, 2018
402eea1
Update Combine.elm
Feb 28, 2018
20c7fc3
modifyState added
Feb 28, 2018
01d960b
updated test for string/macro injection
Nov 6, 2018
cf67948
changed elm-package back to original
Nov 6, 2018
b9388e7
new/old test
Dec 20, 2018
9684d4b
new updated parsers ... removed all defined operators
Dec 20, 2018
64a716b
updated docs
Dec 20, 2018
1df794e
changed error to onerror
Dec 20, 2018
81d5bef
Calc example seems to work
Dec 20, 2018
069060b
ported Scheme example to new version parser
Dec 20, 2018
8d62279
Python lifted to newer verstion
Dec 20, 2018
05ebe89
updated tests
Dec 20, 2018
e816eb4
new version
Dec 20, 2018
5aa57d8
changed version number
Dec 20, 2018
6b55eeb
updated to new operator less version
Dec 20, 2018
f3c92e5
little regex optimizations
Dec 20, 2018
06c6a60
added missing string function
Dec 20, 2018
0b16bff
version bump
Dec 20, 2018
db2958c
updated to elm 0.19
Jan 8, 2019
8f75d0c
removed obsolete onsuccess
Jan 8, 2019
65b18d2
version changed back to 1.0.0
Jan 8, 2019
e993735
version changed back to 1.0.1
Jan 8, 2019
180b741
version bump
Jan 8, 2019
cca469b
new tag
Jan 8, 2019
acc766c
new new version 2.0.0
Jan 8, 2019
071b2da
updated Combine.Num and lazy doc
Jan 9, 2019
bf2337d
version bump
Jan 9, 2019
a34be36
updated examples
Jan 9, 2019
3c78b85
updated version
Jan 9, 2019
6794564
test updated and CHANGELOG updated
Jan 9, 2019
25f2a78
version bump
Jan 9, 2019
ec7d339
little optimizations
Jan 29, 2019
cfc8dfe
version bumb
Jan 29, 2019
da46c88
new regex functions added
Feb 7, 2019
8b4b9b2
new regex functions added
Feb 7, 2019
0e2b276
added regexSub
Feb 7, 2019
8e772b3
updated .travis.yml
Mar 30, 2019
8bc1a3c
Improve some parser failure messages
Apr 12, 2019
0bb23b4
Merge pull request #1 from declension/fix-some-parser-failure-messages
Apr 12, 2019
651e150
version bump patch
Apr 12, 2019
97a57cd
added a function and an example to ease the debugging with parser-com…
Sep 27, 2019
cd93fcb
updated debug function
Sep 27, 2019
88780fc
version bump
Sep 27, 2019
b848c85
added a string stream output function
Mar 10, 2020
30a77ce
updated convenience functions
Mar 13, 2020
0aa9e0d
version bump
Mar 13, 2020
8cc2c79
Adds many1Till & elm-review suggestions
andre-dietrich Jun 18, 2021
ab4f162
Version bump to 4.1.0
andre-dietrich Jun 21, 2021
c0c6ecb
improve(Num): little faster functions
andre-dietrich Oct 20, 2024
3c73274
docs: Correct typos in Conbine-Parsers
andre-dietrich Oct 21, 2024
2ce8325
feat: Add more convenience functions to Char
andre-dietrich Oct 23, 2024
8c2723d
new convenience functions for Combine
andre-dietrich Oct 23, 2024
48d1c6f
Version bump to 5.0.0
andre-dietrich Oct 23, 2024
a875911
docs: Improved examples and links
andre-dietrich Oct 24, 2024
fdbe729
Version bump to 5.0.1
andre-dietrich Oct 24, 2024
c0237c8
add missing helper functions
andre-dietrich Oct 24, 2024
7e2ac82
Version bump to 5.1.0
andre-dietrich Oct 24, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
/elm-stuff
elm.js
examples/elm-stuff
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ install:
make && make install;
cd ..;
fi
- npm install -g elm elm-test@0.18.7
- npm install -g elm elm-test

script:
- $TRAVIS_BUILD_DIR/sysconfcpus/bin/sysconfcpus -n 2 elm-test
42 changes: 38 additions & 4 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,19 +1,53 @@
# Changelog

## Version 3.0.2 (2019-01-09)

I hope, it is possible to transfer this back to the community repo. This is a
simple port of the community/parser-combinators package to elm 0.19.
Unfortunatelly all operators had to be removed or in other words replaced. And
lazyness is not supported anymore, these things can only be used by native elm
modules :.(.

**Basic changes:**

* `*>` was replaced by the new function `ignore`
* `<*` was replaced by the function `keep`
* `$>` is now function `onsuccess`
* while `<?>` is represented by the function `onerror`
* `lazy` can still be used, but in the manner, that it was replaced by the
function:

``` elm
lazy : (() -> Parser s a) -> Parser s a
lazy t =
succeed () |> andThen t
```

which tries to circumvent the bad-recursion problem

* Examples and test have been updated and a new the new function `modifyStream`
was added, which I personally use to inject code/macros at compile-time.
* Some minor optimization of regular expression ...

## Version 2.0.0 (2017-12-05)

No API change, but a major change. The internal implementation how locations (line/columns) are working has changed.
Lines were previously 1-based, and columns sometimes had negative values. This is changed into zero-based lines and columns can never have negative values anymore.
No API change, but a major change. The internal implementation how locations
(line/columns) are working has changed. Lines were previously 1-based, and
columns sometimes had negative values. This is changed into zero-based lines and
columns can never have negative values anymore.

If your application/library did not rely on parse locations, the update is seamless.
If your application/library did not rely on parse locations, the update is
seamless.

## Version 1.0.0 (2017-02-09)

* Transfer from `Bogdanp/elm-combine`.

---

> This repository is transferred from [Bogdanp/elm-combine](github.com/Bogdanp/elm-combine). The following changelog statements originate from that repository.
> This repository is transferred from
> [Bogdanp/elm-combine](github.com/Bogdanp/elm-combine).
> The following changelog statements originate from that repository.


---
Expand Down
20 changes: 0 additions & 20 deletions elm-package.json

This file was deleted.

21 changes: 21 additions & 0 deletions elm.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"type": "package",
"name": "andre-dietrich/parser-combinators",
"summary": "Port of the community parser combinator to elm 0.19",
"license": "BSD-3-Clause",
"version": "5.1.0",
"exposed-modules": [
"Combine",
"Combine.Char",
"Combine.Num"
],
"elm-version": "0.19.0 <= v < 0.20.0",
"dependencies": {
"elm/core": "1.0.1 <= v < 2.0.0",
"elm/regex": "1.0.0 <= v < 2.0.0",
"pilatch/flip": "1.0.0 <= v < 2.0.0"
},
"test-dependencies": {
"elm-explorations/test": "1.2.0 <= v < 2.0.0"
}
}
48 changes: 39 additions & 9 deletions examples/Calc.elm
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,14 @@ module Calc exposing (calc)

{-| An example parser that computes arithmetic expressions.

To run this example, simply enter the examples and:

1. run `elm repl`
2. type in `import Calc exposing (calc)`
3. try out some expressions like `calc "22*2+(3+18)"`

@docs calc

-}

import Combine exposing (..)
Expand All @@ -12,16 +19,16 @@ import Combine.Num exposing (int)
addop : Parser s (Int -> Int -> Int)
addop =
choice
[ (+) <$ string "+"
, (-) <$ string "-"
[ string "+" |> onsuccess (+)
, string "-" |> onsuccess (-)
]


mulop : Parser s (Int -> Int -> Int)
mulop =
choice
[ (*) <$ string "*"
, (//) <$ string "/"
[ string "*" |> onsuccess (*)
, string "/" |> onsuccess (//)
]


Expand All @@ -31,7 +38,7 @@ expr =
go () =
chainl addop term
in
lazy go
lazy go


term : Parser s Int
Expand All @@ -40,21 +47,44 @@ term =
go () =
chainl mulop factor
in
lazy go
lazy go


factor : Parser s Int
factor =
whitespace *> (parens expr <|> int) <* whitespace
whitespace
|> keep (or (parens expr) int)
|> ignore whitespace


{-| Compute the result of an expression.

import Calc exposing (calc)

calc "22*2+(3+18)"
-- Ok 65

calc "33 ** 12"
-- Err ("parse error: [ \"expected end of input\" ] , { data: 33 ** 12, input: ** 12, position: 3 }")

-}
calc : String -> Result String Int
calc s =
case parse (expr <* end) s of
case parse (expr |> ignore end) s of
Ok ( _, _, n ) ->
Ok n

Err ( _, stream, ms ) ->
Err ("parse error: " ++ toString ms ++ ", " ++ toString stream)
Err
("parse error: "
++ "[ \""
++ (ms |> List.intersperse "\", \"" |> String.concat)
++ "\" ] , "
++ "{ data: "
++ stream.data
++ ", input: "
++ stream.input
++ ", position: "
++ String.fromInt stream.position
++ " }"
)
72 changes: 72 additions & 0 deletions examples/Debugger.elm
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
module Debugger exposing (runDebug)

{-| An example parser defines a simple debugger, so that you are aware of the
current rule and location information ... state can be added accordingly...

To run this example, simply enter the examples and:

1. run `elm repl`
2. type in `import Debugger exposing (runDebug)`
3. try out some expressions like `runDebug "1234\nabcdef\nABCD"`

@docs calc

-}

import Combine exposing (..)


debug : String -> Parser s a -> Parser s a
debug log p =
withLine
(\y ->
withColumn
(\x ->
withSourceLine
(\s ->
let
output =
Debug.log log
( x
, y
, String.slice 0 x s
++ "["
++ String.slice x (x + 1) s
++ "]"
++ String.slice (x + 1) -1 s
)
in
p
)
)
)


runDebug : String -> Result String String
runDebug s =
case
parse
((regex "(.|\n)"
|> debug "regex"
)
|> many
)
s
of
Ok ( _, _, n ) ->
Ok <| String.concat n

Err ( _, stream, ms ) ->
Err
("parse error: "
++ "[ \""
++ (ms |> List.intersperse "\", \"" |> String.concat)
++ "\" ] , "
++ "{ data: "
++ stream.data
++ ", input: "
++ stream.input
++ ", position: "
++ String.fromInt stream.position
++ " }"
)
Loading