s-expression

Is there something similar to Nokogiri for parsing Ruby code?

允我心安 提交于 2019-12-04 03:57:27
Nokogiri is awesome. I can do things like #css('.bla') which will return the first matching element. Right now we need to do some parsing of Ruby source code - finding all methods within a class etc. We're using the ruby_parser gem, but all it does is comb your source code and spit out S-expressions. Is there anything like Nokogiri for these S-expressions which can do things like "return S-expression for first method found named 'foo'"? The only thing I can think of, is Adam Sanderson's SExpPath library . Although I am accepting Jörg's answer because it is more complete, I ended up discovering

Parsing Lisp S-Expressions with known schema in C#

喜你入骨 提交于 2019-12-03 20:41:04
I'm working with a service that provides data as a Lisp-like S-Expression string. This data is arriving thick and fast, and I want to churn through it as quickly as possible, ideally directly on the byte stream (it's only single-byte characters) without any backtracking. These strings can be quite lengthy and I don't want the GC churn of allocating a string for the whole message. My current implementation uses CoCo/R with a grammar, but it has a few problems. Due to the backtracking, it assigns the whole stream to a string. It's also a bit fiddly for users of my code to change if they have to.

S-Expressions parsing

*爱你&永不变心* 提交于 2019-12-03 17:27:10
I ran into this question earlier today: Example Input: I ran into Joe and Jill and then we went shopping Example Output: [TOP [S [S [NP [PRP I]] [VP [VBD ran] [PP [IN into] [NP [NNP Joe] [CC and] [NNP Jill]]]]] [CC and] [S [ADVP [RB then]] [NP [PRP we]] [VP [VBD went] [NP [NN shopping]]]]]] I was about to suggest simply parsing the expected output (as it looks like an s-expression) into an object (in our case a tree) and then using simple LINQ methods to process it. However, to my surprise, I was unable to find a C# s-expression parser. The only thing I could think of is using Clojure to parse

Do you know of a language with Static Type checking where Code is Data? [closed]

*爱你&永不变心* 提交于 2019-12-03 05:57:45
Can you name languages with static type checking (like Java) and where code is data (like in LISP)? I mean both things in one language. Qi is a statically-typed Lisp dialect. Also, many other Lisp dialects have (optional) static typing. Java itself has very limited capabilities of this kind. The interesting question is not so much whether you can have metaprogramming and static typing, it's whether you can have dynamic metaprogramming be statically type-safe . There is Template Haskell which does metaprogramming and is type-safe, but it is static metaprogramming. At the moment I can not think

How do I manipulate parse trees?

人走茶凉 提交于 2019-12-03 03:54:47
问题 I've been playing around with natural language parse trees and manipulating them in various ways. I've been using Stanford's Tregex and Tsurgeon tools but the code is a mess and doesn't fit in well with my mostly Python environment (those tools are Java and aren't ideal for tweaking). I'd like to have a toolset that would allow for easy hacking when I need more functionality. Are there any other tools that are well suited for doing pattern matching on trees and then manipulation of those

Emacs: bulletproof up-list?

老子叫甜甜 提交于 2019-12-01 22:29:26
I'm getting up-list: Scan error: "Unbalanced parentheses" from this position: (foo "bar|") Snippet from up-list doc: This command assumes point is not in a string or comment. So this is the expected behavior. But I don't care. I just want to go upwards from a list. Could someone suggest an up-list clone that does the proper thing? I'm looking for something better than this naive code: (defun up-list-naive () (interactive) (while (not (ignore-errors (up-list) t)) (forward-char))) Tyler EDIT: incorporated Andreas Rohler's suggestion: This works for me in your test case: (defun my-up-list ()

Why do we need `nil`?

家住魔仙堡 提交于 2019-12-01 21:42:10
问题 I do not see why we need nil [1] when to cons a sequence (so-called proper list) of items. It seems to me we can achieve the same goal by using the so-called improper list ( cons -ed pairs without an ending nil ) alone. Since Lisps [2] have already provided a primitive procedure to distinguish between a pair? and an atom (some implementations even provide atom? ), when defining a procedure on a list, e.g., length , I can do the same with just dotted-pairs, as shown below: (define len (lambda

Why do we need `nil`?

拈花ヽ惹草 提交于 2019-12-01 19:24:43
I do not see why we need nil [1] when to cons a sequence (so-called proper list) of items. It seems to me we can achieve the same goal by using the so-called improper list ( cons -ed pairs without an ending nil ) alone. Since Lisps [2] have already provided a primitive procedure to distinguish between a pair? and an atom (some implementations even provide atom? ), when defining a procedure on a list, e.g., length , I can do the same with just dotted-pairs, as shown below: (define len (lambda (l) (cond ((pair? l) (+ 1 (len (cdr l)))) (else 1) ) ) ) It is obvious that we can apply this procedure

Do any lisps have a s-expression as their head, e.g. ((f 2) 3 4)? If not, why?

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-01 01:47:07
问题 Do any lisps support nested s-expression on their head? For example ((f 2) 3 4) for which (f 2) presumably evaluates to a function/macro to apply on 3 4 . Is it possible to have a lisp supporting such a thing? Or are there technical limitations that prohibit this/make it impractical? 回答1: In those Lisps, which have single namespace for variables and functions, your expression is valid. These are called Lisp-1. Scheme and Clojure are examples of such Lisps. In those Lisps, which have separate

Parsing S-Expressions in Python [closed]

寵の児 提交于 2019-11-27 02:52:20
问题 Are there any python modules available for parsing and manipulating symbolic expressions in Python similar to how Lisp expressions are evaluated? 回答1: pyparsing (dead link - but see github: pyparsing) comes with an S-expression parser as an example, see here. 回答2: Also, depending on how much work with sexpressions you are doing you might want to check out python hy: https://github.com/hylang/hy 来源: https://stackoverflow.com/questions/3182594/parsing-s-expressions-in-python