Class ScopeParser


  • public class ScopeParser
    extends java.lang.Object
    Parse args, return values, locals

    rule[arg1, arg2, ..., argN] returns [ret1, ..., retN]

    text is target language dependent. Java/C#/C/C++ would use "int i" but ruby/python would use "i". Languages with postfix types like Go, Swift use "x : T" notation or "T x".

    • Constructor Detail

      • ScopeParser

        public ScopeParser()
    • Method Detail

      • parseTypedArgList

        public static AttributeDict parseTypedArgList​(ActionAST action,
                                                      java.lang.String s,
                                                      Grammar g)
        Given an arg or retval scope definition list like

        Map<String, String>, int[] j3, char *foo32[3]

        or

        int i=3, j=a[34]+20

        convert to an attribute scope.

      • parseAttributeDef

        public static Attribute parseAttributeDef​(ActionAST action,
                                                  Pair<java.lang.String,​java.lang.Integer> decl,
                                                  Grammar g)
        For decls like "String foo" or "char *foo32[]" compute the ID and type declarations. Also handle "int x=3" and 'T t = new T("foo")' but if the separator is ',' you cannot use ',' in the initvalue unless you escape use "\," escape.
      • _parsePrefixDecl

        public static Pair<java.lang.Integer,​java.lang.Integer> _parsePrefixDecl​(Attribute attr,
                                                                                       java.lang.String decl,
                                                                                       ActionAST a,
                                                                                       Grammar g)
      • _parsePostfixDecl

        public static Pair<java.lang.Integer,​java.lang.Integer> _parsePostfixDecl​(Attribute attr,
                                                                                        java.lang.String decl,
                                                                                        ActionAST a,
                                                                                        Grammar g)
      • splitDecls

        public static java.util.List<Pair<java.lang.String,​java.lang.Integer>> splitDecls​(java.lang.String s,
                                                                                                int separatorChar)
        Given an argument list like

        x, (*a).foo(21,33), 3.2+1, '\n', "a,oo\nick", {bl, "fdkj"eck}, ["cat\n,", x, 43]

        convert to a list of attributes. Allow nested square brackets etc... Set separatorChar to ';' or ',' or whatever you want.

      • _splitArgumentList

        public static int _splitArgumentList​(java.lang.String actionText,
                                             int start,
                                             int targetChar,
                                             int separatorChar,
                                             java.util.List<Pair<java.lang.String,​java.lang.Integer>> args)