jecki / DHParser

DSL-Toolkit for Digital Humanities Applications (mirrors gitlab.lrz.de/badw-it/DHParser)
Apache License 2.0
6 stars 1 forks source link

How to ignore whitespace when match? #17

Open syheliel opened 4 weeks ago

syheliel commented 4 weeks ago

I have following rules:

function-type = (type | type-list-parens) `->` (type | type-list-parens)

I can't let it match:

[match:function_type]
M1: () -> (f32,i32)

here is the error:

Errors found by unit test "type_test.ini":

        Match test "M1" for parser "function_type" failed:
                Expr.:  `() -> (f32,i32)`
                1:3: Error (1040): Parser function_type->`->` did not match: » -> (f32,i32)«
            Most advanced fail:    1,  3:  function_type->`->` ;  FAIL;  " -> (f32,i32)"
            Last match:       1,  1:  function_type->type_list_parens;  MATCH;  "()";|

The directive is:

horizontal, linefeed, vertical
# Implicit whitespace is denoted by the tilde-character: ~
@ whitespace  = linefeed

# Implicit whitespace adjacent to literals: left, right, both, none
# E.g. if @literalws = right then ")" means the same as `)`~
@ literalws   = left

# Regular expression for comments, e.g. /#.*(?:\n|$)/
# Use: /(?:\/\/.*)|(?:\/\*(?:.|\n)*?\*\/)/ for C++-style comments: /* ... */ or // to EOL
@ comment     = /#.*/

# Case-sensitivity: True, False
@ ignorecase  = False

# Tree-simplification while parsing:  none, flatten, merge_treetops, merge
@ reduction   = flatten         # anonymous nodes are being reduced where possible

# Tags that may be replaced with their content while parsing
@ disposable  = EOF

# Tags that will be dropped with all their content while parsing or any of
# the special values: strings, backticked, whitespace, regexps
# Here, EOF and insignificant whitespace (tilde) will be dropped
@ drop        = whitespace, strings
jecki commented 3 weeks ago

Looks like a whitespace issue, because the parser stopped short just before a blank character. Maybe you forget to code whitespace in your grammar? You might try @literalws = right, or @literalws = both.

You might want to check out the sections on whitespace and, in particular, on in significant whitespace in the manual:

If this is still an issue, you might want to attach your complete grammar or at least the EBNF-statements that are supposed to capture constructs like "() -> (f32,i32)", so I can give it a try.

syheliel commented 3 weeks ago

Thanks, I find the problem is that I should use " instead of ` to mark a literal string. I may have some other try to check if there are other problems related to whitespace before closing the issue :)