Current section
19 Versions
Jump to
Current section
19 Versions
Compare versions
3
files changed
+69
additions
-47
deletions
| @@ -11,4 +11,4 @@ | |
| 11 11 | {<<"maintainers">>,[<<"OvermindDL1">>]}. |
| 12 12 | {<<"name">>,<<"ex_spirit">>}. |
| 13 13 | {<<"requirements">>,[]}. |
| 14 | - {<<"version">>,<<"0.2.0">>}. |
| 14 | + {<<"version">>,<<"0.2.1">>}. |
| @@ -528,6 +528,24 @@ defmodule ExSpirit.Parser do | |
| 528 528 | |
| 529 529 | ``` |
| 530 530 | |
| 531 | + ## map_context_around |
| 532 | + |
| 533 | + Runs a function and parser with the both the context before and after the |
| 534 | + function call. |
| 535 | + |
| 536 | + ### Examples |
| 537 | + |
| 538 | + ```elixir |
| 539 | + |
| 540 | + iex> import ExSpirit.Tests.Parser |
| 541 | + iex> fun = fn {pre, post} -> %{post|result: {pre, post}} end |
| 542 | + iex> context = parse("42", map_context_around(fun.(), uint())) |
| 543 | + iex> {pre, post} = context.result |
| 544 | + iex> {context.error, pre.column, post.column, context.rest} |
| 545 | + {nil, 1, 3, ""} |
| 546 | + |
| 547 | + ``` |
| 548 | + |
| 531 549 | ## skip |
| 532 550 | |
| 533 551 | Runs the skipper now |
| @@ -1060,13 +1078,17 @@ defmodule ExSpirit.Parser do | |
| 1060 1078 | end |
| 1061 1079 | |
| 1062 1080 | |
| 1063 | - defmacro map_context_around(context_ast, parser_ast, mapper_ast) do |
| 1081 | + defmacro map_context_around(context_ast, mapper_ast, parser_ast) do |
| 1064 1082 | quote location: :keep do |
| 1065 1083 | context = unquote(context_ast) |
| 1066 1084 | if !valid_context?(context) do |
| 1067 1085 | context |
| 1068 1086 | else |
| 1069 | - context |> unquote(mapper_ast) |
| 1087 | + case context |> unquote(parser_ast) do |
| 1088 | + %{error: nil} = new_context -> |
| 1089 | + {context, new_context} |> unquote(mapper_ast) |
| 1090 | + bad_context -> bad_context |
| 1091 | + end |
| 1070 1092 | end |
| 1071 1093 | end |
| 1072 1094 | end |
| @@ -1,44 +1,44 @@ | |
| 1 | - defmodule ExSpirit.Mixfile do |
| 2 | - use Mix.Project |
| 3 | - |
| 4 | - def project do |
| 5 | - [app: :ex_spirit, |
| 6 | - version: "0.2.0", |
| 7 | - elixir: "~> 1.4", |
| 8 | - description: description(), |
| 9 | - package: package(), |
| 10 | - docs: [ |
| 11 | - #logo: "path/to/logo.png", |
| 12 | - extras: ["README.md"], |
| 13 | - main: "readme", |
| 14 | - ], |
| 15 | - build_embedded: Mix.env == :prod, |
| 16 | - start_permanent: Mix.env == :prod, |
| 17 | - deps: deps()] |
| 18 | - end |
| 19 | - |
| 20 | - def application do |
| 21 | - [extra_applications: []] |
| 22 | - end |
| 23 | - |
| 24 | - def description do |
| 25 | - """ |
| 26 | - Spirit-style PEG-like parsing library for Elixir. |
| 27 | - """ |
| 28 | - end |
| 29 | - |
| 30 | - def package do |
| 31 | - [ |
| 32 | - licenses: ["MIT"], |
| 33 | - name: :ex_spirit, |
| 34 | - maintainers: ["OvermindDL1"], |
| 35 | - links: %{"Github" => "https://github.com/OvermindDL1/ex_spirit"} |
| 36 | - ] |
| 37 | - end |
| 38 | - |
| 39 | - defp deps do |
| 40 | - [ |
| 41 | - {:ex_doc, "~> 0.14.5", only: [:dev]}, |
| 42 | - ] |
| 43 | - end |
| 44 | - end |
| 1 | + defmodule ExSpirit.Mixfile do |
| 2 | + use Mix.Project |
| 3 | + |
| 4 | + def project do |
| 5 | + [app: :ex_spirit, |
| 6 | + version: "0.2.1", |
| 7 | + elixir: "~> 1.4", |
| 8 | + description: description(), |
| 9 | + package: package(), |
| 10 | + docs: [ |
| 11 | + #logo: "path/to/logo.png", |
| 12 | + extras: ["README.md"], |
| 13 | + main: "readme", |
| 14 | + ], |
| 15 | + build_embedded: Mix.env == :prod, |
| 16 | + start_permanent: Mix.env == :prod, |
| 17 | + deps: deps()] |
| 18 | + end |
| 19 | + |
| 20 | + def application do |
| 21 | + [extra_applications: []] |
| 22 | + end |
| 23 | + |
| 24 | + def description do |
| 25 | + """ |
| 26 | + Spirit-style PEG-like parsing library for Elixir. |
| 27 | + """ |
| 28 | + end |
| 29 | + |
| 30 | + def package do |
| 31 | + [ |
| 32 | + licenses: ["MIT"], |
| 33 | + name: :ex_spirit, |
| 34 | + maintainers: ["OvermindDL1"], |
| 35 | + links: %{"Github" => "https://github.com/OvermindDL1/ex_spirit"} |
| 36 | + ] |
| 37 | + end |
| 38 | + |
| 39 | + defp deps do |
| 40 | + [ |
| 41 | + {:ex_doc, "~> 0.14.5", only: [:dev]}, |
| 42 | + ] |
| 43 | + end |
| 44 | + end |