realthunder / sexp_parser

Python S-Expression Object Model
MIT License
6 stars 4 forks source link

parsing SPECCTRA dsn file #1

Open alpo opened 3 years ago

alpo commented 3 years ago

Is it possible to modify your code to allow it to parse SPECCTRA .dsn files correctly? There is a troublesome fragment at the beginning:

  (parser
    (string_quote ")
    (space_in_quoted_tokens on)
    (host_cad "KiCad's Pcbnew")
    (host_version "5.1.7-a382d34a8~88~ubuntu18.04.1")
  )

In the beginning, it should be parsed without quoting, but after string_quote the quoting should start working. Your code, however, completely turns the parser section into a mess.

The description of this piece of the format:

string_quote
Temporarily disables parentheses as delimiters for text strings. A blank space is an absolute delimiter in a design file unless you set `space_in_quoted_tokens on` Once you define the < quote_char>, you can use it to include parentheses in < id> strings such as net names, component names, and layer names. You must include a blank space after the closing string quote character. Within a command, if a name or other < id > string includes a parentheses, enclose the string within string quote characters. For example, if the string quote character is the single quotation mark, you can enter the command `select net 'DATA_BUS(0)'` Valid string quote characters are single quotation mark ('), double quotation mark ("), and dollar sign ($). There is no default string quote character.
space_in_quoted_tokens
Controls the use of blank spaces within quoted strings. By default (off), blank spaces are an absolute delimiter. For example, a blank space indicates the end of the string if its used within a quoted string. When on, blank spaces are permitted within quoted strings. You must use the closing quote to end a string.
luzpaz commented 2 years ago

@realthunder did you see this?

realthunder commented 2 years ago

I've add an argument quote_no_parse to sexp_parser.parseSexp(). This parameter is just to match one (or more) first token of some S-expression, and once matched, treat the quote as regular character in the rest of the tokens. Check the doc string for more information.

To test

sexp = r'''
  (parser
    (string_quote ")
    (space_in_quoted_tokens on)
    (host_cad "KiCad's Pcbnew")
    (host_version "5.1.7-a382d34a8~88~ubuntu18.04.1")
  )
'''
import sexp_parser
sexp_parser.parseSexp(sexp, 'string_quote')