In this tutorial we're going to build a set of parser combinators.
We'll answer the above question in 2 steps
- what is a parser?
- and.. what is a parser combinator?
So first question: What is parser?
| @echo off | |
| if _%1_==__ goto USAGE | |
| openssl req -x509 -nodes -days 365 -newkey rsa:1024 -keyout mycert.pem -out mycert.pem -subj "/CN=My Cert Name" | |
| openssl pkcs12 -export -out mycert.pfx -inkey mycert.pem -in mycert.pem -passout pass:%1 | |
| openssl x509 -inform pem -in mycert.pem -outform der -out mycert.cer | |
| openssl pkcs12 -in mycert.pfx -nodes -passin pass:%1 | openssl x509 -noout -fingerprint | |
| openssl x509 -in mycert.pem -noout -fingerprint |
| import contextlib | |
| import OpenSSL.crypto | |
| import os | |
| import requests | |
| import ssl | |
| import tempfile | |
| @contextlib.contextmanager | |
| def pfx_to_pem(pfx_path, pfx_password): | |
| ''' Decrypts the .pfx file to be used with requests. ''' |
| import java.util.ArrayList; | |
| class Solution | |
| { | |
| public int solution(int[] H) | |
| { | |
| // rules | |
| /* | |
| * so when we find two indices that are of the same height, we can use the same block, providing all the values in-between are higher. | |
| * |
| import sys | |
| def factorial(n): | |
| if n == 0: | |
| return 1 | |
| else: | |
| return n * factorial(n - 1) | |
| def choose(n, m): | |
| return factorial(n) / (factorial(m) * factorial(n - m)) |
| """ | |
| Port of nanoparsec in typed python from https://github.com/sdiehl/write-you-a-haskell/blob/master/chapter3/parsec.hs. | |
| pip install attrs mypy | |
| """ | |
| from typing import Callable, Sequence, Text, Tuple, TypeVar | |
| import attr |
| class Automaton: | |
| def __init__(self, nstates): | |
| self.transitions = [{} for i in range(nstates)] | |
| self.accept_states = [False] * nstates | |
| def register(self, source_state, char, target_state): | |
| self.transitions[source_state][char] = target_state | |
| def register_accept(self, state): | |
| self.accept_states[state] = True |
| #!/usr/bin/env python | |
| import random | |
| import operator | |
| import time | |
| from collections import OrderedDict | |
| import unittest | |
| class ordered_dict(dict): | |
| def __init__(self): | |
| self.order = {} |
| # Located in Lib/collections/__init__.py | |
| ################################################################################ | |
| ### OrderedDict | |
| ################################################################################ | |
| class _OrderedDictKeysView(KeysView): | |
| def __reversed__(self): | |
| yield from reversed(self._mapping) |