Skip to content

Output is just a nested array of characters #645

@cocosbeans

Description

@cocosbeans

I'm not the sharpest tool in the shed, and I just picked up Nearley.

Here's what my grammar.ne is:

@builtin "whitespace.ne"
@builtin "string.ne"
@builtin "number.ne"

identifier -> dstrchar:+
type -> "strl"
      | "str" "[]":?
      | "int" "[]":?
      | "bool" "[]":?

bool -> "true" | "false"
value -> int | dqstring | bool

assign -> type __ identifier _ "=" _ value _ ";":?

Here's my index.js:

const nearley = require('nearley')
const grammar = require('./grammar.js')
const parser = new nearley.Parser(nearley.Grammar.fromCompiled(grammar));
parser.feed("int x = 5;")
console.log(parser.results)

And, for some reason, here's my output:

[
    [
        [
            'i', 'n', 't', ' ',
            'x', ' ', '=', ' ',
            '5', ';'
        ]
    ]
]

What's the issue? This is just a quick test by the way, I haven't decided what I want to start working on

Edit: I made a typo in the Issue.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions