OMeta underscore and dots
Asked Answered
E

0

6

Hello I need to modify the following OMeta PEG :

using OMetaSharp;
using System.Collections;
using System.Text;

ometa SExpression.GeneratedCode.SExpressionParser : Parser {
    SExpression = Spaces Atom:a Spaces -> { a }
                | Spaces List:l Spaces -> { l.As<SExprList>() },


    EscapeChar  = '\\' Character:c          -> { c },

    Atom        = String:s -> { new SExprAtomString(s.ToString()) }
                | Number:n -> { new SExprAtomNumber(n.ToString()) }
                | Symbol:sy -> { new SExprAtomSymbol(sy.ToString()) },

    Symbol      = FirstAndRest("Letter", "LetterOrDigit") | '+' | '-' | '*' | '/' | '^',

    String      = '"' (EscapeChar | ~'"' Character)*:s '"'  -> { s },

    Number      = Digit+,

    List        = '(' SExpression*:xs ')' -> { new SExprList(xs.ToIEnumerable<ISExpression>()) }
}

to support Symbols including underscore and dot characters. Dots should also be supported in Numbers.

I tried to modify Number rules with the following production (taken from original Ometa# site) but it ends up with a runtime error when generating the SExpression parser:

Number = Number:n Digit:D           -> (n * 10 + d)
         | Digit,

and this seems not to work either:

Number      = Digit+
            | Digit+ '.' Digit+,

In this case I'm able to produce the parser but I got an OMeta exception when I try to parse something like 0.25.

I wrote also these rules to allow parsing underscore (and dot) rich Symbols but it doesn't work either:

Atom        = Sub:s                                     -> { new SExprAtomString(s.ToString()) }
            | Number:n                                  -> { new SExprAtomNumber(n.ToString()) }
            | Symbol:sy                                 -> { new SExprAtomSymbol(sy.ToString()) },

Sub         = String
            | String '_' String
            | String '.' String,

The expression I'm trying to parse is the following:

(fp_text value V23105 (at -2 0 180) (layer FSilkS) hide
    (effects (font (size 1 1) (thickness 0.25)))
)

The exception parsing this is always this one:

enter image description here

No stack trace :-(.

Enarthrosis answered 25/2, 2017 at 18:11 Comment(2)
OMeta# is a bit weirdo, have you tried using IronMeta instead ?Ebonee
@OndrejSvejdar I tried to use it but following the first tutorial I got stuck with creating the correct 'element' to define IronMeta PEG. I need to give it another try!Enarthrosis

© 2022 - 2024 — McMap. All rights reserved.