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?
| #!/usr/bin/env python | |
| # -*- coding: utf-8 -*- | |
| """ | |
| pip install networkx distance pattern | |
| In Flipboard's article[1], they kindly divulge their interpretation | |
| of the summarization technique called LexRank[2]. |
| # -fobjc-arc: enables ARC | |
| # -fmodules: enables modules so you can import with `@import AppKit;` | |
| # -mmacosx-version-min=10.6: support older OS X versions, this might increase the binary size | |
| clang main.m -fobjc-arc -fmodules -mmacosx-version-min=10.6 -o main |
| from django.db.models import SubfieldBase | |
| from django.core.exceptions import ImproperlyConfigured | |
| from django_extensions.db.fields import ShortUUIDField | |
| class XidField(ShortUUIDField): | |
| """ | |
| XID stands for external ID. | |
| Randomly generated IDs (base62 encoded UUID) used for public display purposes. | |
| The random ID gets a short textual prefix for improved legibility, like Stripe's IDs. |
| #include <stdio.h> | |
| #include <string.h> | |
| #include <assert.h> | |
| FILE *in; long M[1<<24]={0}, *D, *R, H=0x130000, IP=0, T; | |
| long getu() { long t, h = getc(in); if (h < 0xC0) return h; | |
| t = ((h&0x1F) << 6) | (getc(in) & 0x3F); if (h < 0xE0) return t; | |
| t = ( t << 6) | (getc(in) & 0x3F); if (h < 0xF0) return t; | |
| t = ( t << 6) | (getc(in) & 0x3F); return t & 0x1FFFFF; } | |
| void putu(long c) { if (c < 0x80) { putchar(c); return; } | |
| if (c < 0x7FF) { putchar(0xC0|(c>>6)); } else { |