Created
September 26, 2015 11:17
-
-
Save hastern/ac2d7eab7a2a85f588d1 to your computer and use it in GitHub Desktop.
Simple S-Expression parsing with pyparsing
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 pyparsing as pp | |
LP = pp.Literal("(").suppress() | |
RP = pp.Literal(")").suppress() | |
String = pp.Word(pp.alphanums + '_') | |
SingleQuoteString = pp.QuotedString(quoteChar="'", unquoteResults=False) | |
DoubleQuoteString = pp.QuotedString(quoteChar='"', unquoteResults=False) | |
QuotedString = SingleQuoteString | DoubleQuoteString | |
Atom = String | QuotedString | |
SExpr = pp.Forward() | |
SExprList = pp.Group(pp.ZeroOrMore(SExpr | Atom)) | |
SExpr << (LP + SExprList + RP) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
could you append it with a simple example? I struggle a bit applying it with my example:
(union (bgp (triple <http://dbpedia.org/resource/Diane_Fletcher> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> ?x1)) (bgp (triple <http://dbpedia.org/resource/Diane_Fletcher> <http://www.w3.org/2000/01/rdf-schema#label> ?x2)))
thanks