This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Less(Optional(Less(Less(OneOf([Less(Literal('0'), Literal('0'))]), Literal('\U000523a9')), Less(Less(Sequence([Literal('0')]), OneOf([Literal('0')])), Sequence([Optional(Literal('0')), Less(Literal('0'), Literal('0')), OneOf([Literal('0')]), Range('0', '0'), Sequence([Literal('0')]), Optional(Literal('0')), Sequence([Literal('0')]), OneOf([Literal('0')]), Optional(Literal('0')), OneOf([Literal('0')])])))), OneOf([Many(Many(Range(' ', ','))), Optional(OneOf([OneOf([Literal('0'), Literal('0'), Literal('0'), Literal('0'), Literal('0')]), Literal('\x0c'), Sequence([Literal('0'), Literal('0'), Literal('0'), Literal('0'), Literal('0'), Literal('0'), Literal('0'), Literal('0'), Literal('0'), Literal('0'), Literal('0'), Literal('0'), Literal('0'), Literal('0'), Literal('0'), Literal('0')]), Any(), Sequence([Literal('0'), Literal('0')]), Range('%', '\U000a562f')])), Sequence([Any(), Sequence([OneOf([Literal('0')]), Many(Literal('0')), Range('0', '0'), Many(Literal('0')), Sequence([Literal('0')]), Many(Literal('0')), S |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
>>> from grhammer import * | |
>>> math = Grammar(lambda math: { | |
... 'number': Sequence([Range('1', '9'), Many(Range('0', '9'))]), | |
... 'addition': Sequence([math.number, Literal('+'), math.number]), | |
... }) | |
>>> print(math) | |
addition: ( number, '+', number ) ; | |
number: ( '1'..'9', { '0'..'9' } ) ; | |
>>> math.addition.parse("1+3abc") | |
ParseOk([['1', []], '+', ['3', []]], 'abc') |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
math = Grammer({ | |
number: Sequence([Range('1', '9'), Many(Range('0', '9'))]), | |
addition: Sequence([number, Literal('+'), number]), | |
}) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
>>> from parse import * | |
>>> number = Sequence([Range('1', '9'), Many(Range('0', '9'))]) | |
>>> print(number) | |
( '1'-'9' [ '0'-'9' ] ) | |
>>> number.parse("1234 hello!") | |
ParseOk(['1', ['2', '3', '4']], ' hello!') | |
>>> number.parse("0123") | |
ParseError("Expected '1'-'9' found '0'") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{- fun '\EOT' getChar -} | |
fun :: (Monad m, Eq a) => a -> m a -> m [a] | |
fun t f = do | |
x <- f | |
if x == t | |
then return [] | |
else fmap (x :) (fun t f) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import scala.util.{Either, Left, Right} | |
import scala.annotation.tailrec | |
import scala.scalanative.posix.unistd | |
import scala.scalanative.unsafe._ | |
import scala.scalanative.libc | |
import libc.errno.errno | |
import libc.string.strerror |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Main where | |
import Text.Parsec | |
import qualified Data.ByteString as B | |
import qualified Data.ByteString.Char8 as C | |
magic :: Parsec B.ByteString () () | |
magic = string "\x72\xb5\x4a\x86" >> return () | |
main :: IO () |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fix = lambda f: lambda x: f(fix(f), x) | |
# presume Python's obsession with iterators... | |
join = __import__('itertools').chain.from_iterable | |
bind = lambda f, xs: join(map(f, xs)) | |
# I/O primitives... |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
quoted = lambda s: '"' + str.replace(s, '"', '\\"') + '"' | |
unquoted = lambda s: str.replace(s[1:-1], '\\"', '"') | |
slash = lambda s: str.replace(s, '\\', '\\\\') | |
unslash = lambda s: str.replace(s, '\\\\', '\\') | |
shell_escape = lambda s: quoted(slash(s)) | |
shell_unescape = lambda s: unslash(unquoted(s)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <asoundlib.h> | |
int main() { | |
int retcode, dir; | |
char name[32]; | |
for (int card = -1; snd_card_next(&card) == 0 && card >= 0;) | |
{ sprintf(name, "hw:%d", card); | |
snd_ctl_t *ctl; | |
snd_ctl_open(&ctl, name, 0); |