Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove redundant raw properties #54

Open
mathiasbynens opened this issue Jul 1, 2014 · 3 comments
Open

Remove redundant raw properties #54

mathiasbynens opened this issue Jul 1, 2014 · 3 comments

Comments

@mathiasbynens
Copy link
Collaborator

Here’s the current AST for [a-z]:

{
    "type": "characterClass",
    "body": [
        {
            "type": "characterClassRange",
            "min": {
                "type": "value",
                "kind": "symbol",
                "codePoint": 97,
                "range": [
                    1,
                    2
                ],
                "raw": "a"
            },
            "max": {
                "type": "value",
                "kind": "symbol",
                "codePoint": 122,
                "range": [
                    3,
                    4
                ],
                "raw": "z"
            },
            "range": [
                1,
                4
            ],
            "raw": "a-z"
        }
    ],
    "negative": false,
    "range": [
        0,
        5
    ],
    "raw": "[a-z]"
}

All the raw properties here can be removed except "raw": "a" and "raw": "z". Should they be removed?

@mathiasbynens
Copy link
Collaborator Author

I strongly feel like they should be removed. It doesn’t make sense to duplicate data like this: this only makes it harder to modify the AST (as you now have to perform the modification in several places).

@jviereck
Copy link
Owner

jviereck commented Jul 1, 2014

I see where you are going. I think there are multiple answers to this:

  1. let's assume we have a new flag verbose: true/false for the parser. In the case verbose=false, I think there should be no raw entries at all on the AST. In this case, modifying the AST is easy. In such a mode, I would also leave out the "kind": "symbol" property.
  2. store the minimal information to recover the original. For this, removing most of the raw properties as proposed by you seems to be the right thing todo
  3. make it easier to debug the AST. In this case, having the current version of raw property on every AST entry seems the optimal solution

@mathiasbynens, as you want to modify the AST, is 1. the solution you seek for?

@mathiasbynens
Copy link
Collaborator Author

1 sounds good to me. (2 would be fine, too.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants