OvermindDL1/ex_spirit
{ "createdAt": "2017-02-07T00:29:30Z", "defaultBranch": "master", "description": null, "fullName": "OvermindDL1/ex_spirit", "homepage": null, "language": "Elixir", "name": "ex_spirit", "pushedAt": "2018-03-07T15:29:31Z", "stargazersCount": 27, "topics": [ "elixir", "elixir-lang", "elixir-library", "elixir-programming-language", "parser", "parser-combinators", "parser-library" ], "updatedAt": "2024-07-20T06:33:13Z", "url": "https://github.com/OvermindDL1/ex_spirit"}ExSpirit
Section titled “ExSpirit”Spirit-style PEG-like parsing library for Elixir.
Please see ExSpirit.Parser for details about the parser.
Installation
Section titled “Installation”Available in hex.pm.
Add to dependencies with:
def deps do [{:ex_spirit, "~> 0.1"}]endFull docs can be found at: https://hexdocs.pm/ex_spirit
Examples
Section titled “Examples”See the examples directory for examples and run them with mix run examples/<filename>.
Current examples are:
number_adder.exs
Section titled “number_adder.exs”Takes a list of simple integers of base 10, separated by commas, with optional spaces between them, adds them together, and returns them (all within the parser), requires at least one number.
Example Run:
$ mix run examples/number_adder.exsInput simple number separated by comma's and optionally spaces and press enter:
<unknown>:1:1: Parse error: Parsing uint with radix of 10 had 0 digits but 1 minimum digits were required RuleStack: [added_number] Input:
$ mix run examples/number_adder.exsdInput simple number separated by comma's and optionally spaces and press enter:<unknown>:1:1: Parse error: Parsing uint with radix of 10 had 0 digits but 1 minimum digits were required RuleStack: [added_number] Input: d
$ mix run examples/number_adder.exsInput simple number separated by comma's and optionally spaces and press enter:42Result: 42
$ mix run examples/number_adder.exsInput simple number separated by comma's and optionally spaces and press enter:1,2,3 , 4, 5 ,6 , 7Result: 28
$ mix run examples/number_adder.exsInput simple number separated by comma's and optionally spaces and press enter:1 ,Result: 1Leftover: " ,\n"roman_numerals.exs
Section titled “roman_numerals.exs”Takes a typed in roman numeral from stdin and an enter, parses out the number up to the thousands position and reports back any errors and remaining leftovers.
Example Run:
$ mix run examples/roman_numerals.exsInput Roman Numerals and press enter:MDMXXIVResult: 1924
$ mix run examples/roman_numerals.exsInput Roman Numerals and press enter:zzzzResult: 0Leftover: "zzzz\n"
$ mix run examples/roman_numerals.exsInput Roman Numerals and press enter:XVIzzzResult: 16Leftover: "zzz\n"simple_xml.exs
Section titled “simple_xml.exs”A simple xml parser, no attributes, just nodes and text.
Example Run:
$ mix run examples/simple_xml.exsInput a single line of xml-like syntax:<test1>Some text<test2>Hi</test2> and more</test1>Result: {"test1", ["Some text", {"test2", ["Hi"]}, " and more"]}
$ mix run examples/simple_xml.exsInput a single line of xml-like syntax:<a-tag>How about an improperly terminated tag</b-tag><unknown>:1:48: Expectation Failure: literal `a-tag` did not match the input RuleStack: [tag, node_] Input: b-tag>
$ mix run examples/simple_xml.exsInput a single line of xml-like syntax:<<unknown>:1:1: Parse error: Repeating over a parser failed due to not reaching the minimum amount of 1 with only a repeat count of 0 RuleStack: [text, node_] Input: <