有研究FLEX语言的同好吗,加MSN

allenofchina 2008-08-28
最近在做一个基于ANTLR3的actionscript3语法分析器
对flex还不是很了解
有兴趣的或者有研究flex的可以加我msn:allenofchina@hotmail.com
mreay 2008-08-29
actionscript3语法分析器 ?
找找有没有开源现成的。
allenofchina 2008-08-29
没有,应该说没有很好的
有个metaas,不过不支持unicode的变量名,一个文件只能有一个类等等

ationscript3目前看下来是基于ECMAScript3的语言,加入了ECMAScript4的E4X,语法里主要是加入了for each in结构

我把E4X写好了,等下帖上来
allenofchina 2008-08-29
grammar E4X;
options
{
    backtrack=true;
    memoize=true;
    output=AST;
    ASTLabelType=CommonTree;
}

tokens{
UNDERSCORE  = '_';
/*
    SEMI        = ';' ;
    LCURLY      = '{' ;
    RCURLY      = '}' ;
    LPAREN      = '(' ;
    RPAREN      = ')' ;
    LBRACK      = '[' ;
    RBRACK      = ']' ;
    DOT         = '.' ;
    COMMA       = ',' ;
    LT          = '<' ;
    GT          = '>' ;
    LTE         = '<=' ;
    GTE         = '>=' ;
    EQ          = '==' ;
    NEQ         = '!=' ;
    SAME        = '===' ;
    NSAME       = '!==' ;
    PLUS        = '+' ;
    SUB         = '-' ;
    STAR        = '*' ;
    DIV         = '/' ;
    MOD         = '%' ;
    INC         = '++' ;
    DEC         = '--' ;
    SHL         = '<<' ;
    SHR         = '>>' ;
    SHU         = '>>>' ;
    AND         = '&' ;
    OR          = '|' ;
    XOR         = '^' ;
    NOT         = '!' ;
    INV         = '~' ;
    LAND        = '&&' ;
    LOR         = '||' ;
    QUE         = '?' ;
    COLON       = ':' ;
    ASSIGN      = '=' ;
    MUL_ASSIGN  = '*=' ;
    DIV_ASSIGN  = '/=' ;
    MOD_ASSIGN  = '%=' ;
    ADD_ASSIGN  = '+=' ;
    SUB_ASSIGN  = '-=' ;
    SHL_ASSIGN  = '<<=';
    SHR_ASSIGN  = '>>=';
    SHU_ASSIGN  = '>>>=';
    AND_ASSIGN  = '&=' ;
    XOR_ASSIGN  = '^=' ;
    OR_ASSIGN   = '|=' ;
    ELLIPSIS    = '...';
*/    
}

@header{
package org.allen.antlr.e4x;
}
@lexer::header{
package org.allen.antlr.e4x;
}
@lexer::members{
    private final boolean isUnicodeLetter(int ch){
        return ( ch>='\u0041' && ch<='\u005A')
             || ( ch>='\u0061' && ch<='\u007A')
             || ( ch=='\u00AA')
             || ( ch=='\u00B5')
             || ( ch=='\u00BA')
             || ( ch>='\u00C0' && ch<='\u00D6')
             || ( ch>='\u00D8' && ch<='\u00F6')
             || ( ch>='\u00F8' && ch<='\u02C1')
             || ( ch>='\u02C6' && ch<='\u02D1')
             || ( ch>='\u02E0' && ch<='\u02E4')
             || ( ch=='\u02EC')
             || ( ch=='\u02EE')
             || ( ch>='\u0370' && ch<='\u0374')
             || ( ch>='\u0376' && ch<='\u037D')
             || ( ch=='\u0386')
             || ( ch>='\u0388' && ch<='\u03F5')
             || ( ch>='\u03F7' && ch<='\u0481')
             || ( ch>='\u048A' && ch<='\u0559')
             || ( ch>='\u0561' && ch<='\u0587')
             || ( ch>='\u05D0' && ch<='\u05F2')
             || ( ch>='\u0621' && ch<='\u064A')
             || ( ch>='\u066E' && ch<='\u066F')
             || ( ch>='\u0671' && ch<='\u06D3')
             || ( ch=='\u06D5')
             || ( ch>='\u06E5' && ch<='\u06E6')
             || ( ch>='\u06EE' && ch<='\u06EF')
             || ( ch>='\u06FA' && ch<='\u06FC')
             || ( ch=='\u06FF')
             || ( ch=='\u0710')
             || ( ch>='\u0712' && ch<='\u072F')
             || ( ch>='\u074D' && ch<='\u07A5')
             || ( ch=='\u07B1')
             || ( ch>='\u07CA' && ch<='\u07EA')
             || ( ch>='\u07F4' && ch<='\u07F5')
             || ( ch=='\u07FA')
             || ( ch>='\u0904' && ch<='\u0939')
             || ( ch=='\u093D')
             || ( ch=='\u0950')
             || ( ch>='\u0958' && ch<='\u0961')
             || ( ch>='\u0971' && ch<='\u097F')
             || ( ch>='\u0985' && ch<='\u09B9')
             || ( ch=='\u09BD')
             || ( ch=='\u09CE')
             || ( ch>='\u09DC' && ch<='\u09E1')
             || ( ch>='\u09F0' && ch<='\u09F1')
             || ( ch>='\u0A05' && ch<='\u0A39')
             || ( ch>='\u0A59' && ch<='\u0A5E')
             || ( ch>='\u0A72' && ch<='\u0A74')
             || ( ch>='\u0A85' && ch<='\u0AB9')
             || ( ch=='\u0ABD')
             || ( ch>='\u0AD0' && ch<='\u0AE1')
             || ( ch>='\u0B05' && ch<='\u0B39')
             || ( ch=='\u0B3D')
             || ( ch>='\u0B5C' && ch<='\u0B61')
             || ( ch=='\u0B71')
             || ( ch>='\u0B83' && ch<='\u0BB9')
             || ( ch=='\u0BD0')
             || ( ch>='\u0C05' && ch<='\u0C3D')
             || ( ch>='\u0C58' && ch<='\u0C61')
             || ( ch>='\u0C85' && ch<='\u0CB9')
             || ( ch=='\u0CBD')
             || ( ch>='\u0CDE' && ch<='\u0CE1')
             || ( ch>='\u0D05' && ch<='\u0D3D')
             || ( ch>='\u0D60' && ch<='\u0D61')
             || ( ch>='\u0D7A' && ch<='\u0D7F')
             || ( ch>='\u0D85' && ch<='\u0DC6')
             || ( ch>='\u0E01' && ch<='\u0E30')
             || ( ch>='\u0E32' && ch<='\u0E33')
             || ( ch>='\u0E40' && ch<='\u0E46')
             || ( ch>='\u0E81' && ch<='\u0EB0')
             || ( ch>='\u0EB2' && ch<='\u0EB3')
             || ( ch>='\u0EBD' && ch<='\u0EC6')
             || ( ch>='\u0EDC' && ch<='\u0F00')
             || ( ch>='\u0F40' && ch<='\u0F6C')
             || ( ch>='\u0F88' && ch<='\u0F8B')
             || ( ch>='\u1000' && ch<='\u102A')
             || ( ch=='\u103F')
             || ( ch>='\u1050' && ch<='\u1055')
             || ( ch>='\u105A' && ch<='\u105D')
             || ( ch=='\u1061')
             || ( ch>='\u1065' && ch<='\u1066')
             || ( ch>='\u106E' && ch<='\u1070')
             || ( ch>='\u1075' && ch<='\u1081')
             || ( ch=='\u108E')
             || ( ch>='\u10A0' && ch<='\u10FA')
             || ( ch>='\u10FC' && ch<='\u135A')
             || ( ch>='\u1380' && ch<='\u138F')
             || ( ch>='\u13A0' && ch<='\u166C')
             || ( ch>='\u166F' && ch<='\u1676')
             || ( ch>='\u1681' && ch<='\u169A')
             || ( ch>='\u16A0' && ch<='\u16EA')
             || ( ch>='\u16EE' && ch<='\u1711')
             || ( ch>='\u1720' && ch<='\u1731')
             || ( ch>='\u1740' && ch<='\u1751')
             || ( ch>='\u1760' && ch<='\u1770')
             || ( ch>='\u1780' && ch<='\u17B3')
             || ( ch=='\u17D7')
             || ( ch=='\u17DC')
             || ( ch>='\u1820' && ch<='\u18A8')
             || ( ch>='\u18AA' && ch<='\u191C')
             || ( ch>='\u1950' && ch<='\u19A9')
             || ( ch>='\u19C1' && ch<='\u19C7')
             || ( ch>='\u1A00' && ch<='\u1A16')
             || ( ch>='\u1B05' && ch<='\u1B33')
             || ( ch>='\u1B45' && ch<='\u1B4B')
             || ( ch>='\u1B83' && ch<='\u1BA0')
             || ( ch>='\u1BAE' && ch<='\u1BAF')
             || ( ch>='\u1C00' && ch<='\u1C23')
             || ( ch>='\u1C4D' && ch<='\u1C4F')
             || ( ch>='\u1C5A' && ch<='\u1C7D')
             || ( ch>='\u1D00' && ch<='\u1DBF')
             || ( ch>='\u1E00' && ch<='\u1FBC')
             || ( ch=='\u1FBE')
             || ( ch>='\u1FC2' && ch<='\u1FCC')
             || ( ch>='\u1FD0' && ch<='\u1FDB')
             || ( ch>='\u1FE0' && ch<='\u1FEC')
             || ( ch>='\u1FF2' && ch<='\u1FFC')
             || ( ch=='\u2071')
             || ( ch=='\u207F')
             || ( ch>='\u2090' && ch<='\u2094')
             || ( ch=='\u2102')
             || ( ch=='\u2107')
             || ( ch>='\u210A' && ch<='\u2113')
             || ( ch=='\u2115')
             || ( ch>='\u2119' && ch<='\u211D')
             || ( ch=='\u2124')
             || ( ch=='\u2126')
             || ( ch=='\u2128')
             || ( ch>='\u212A' && ch<='\u212D')
             || ( ch>='\u212F' && ch<='\u2139')
             || ( ch>='\u213C' && ch<='\u213F')
             || ( ch>='\u2145' && ch<='\u2149')
             || ( ch=='\u214E')
             || ( ch>='\u2160' && ch<='\u2188')
             || ( ch>='\u2C00' && ch<='\u2CE4')
             || ( ch>='\u2D00' && ch<='\u2DDE')
             || ( ch=='\u2E2F')
             || ( ch>='\u3005' && ch<='\u3007')
             || ( ch>='\u3021' && ch<='\u3029')
             || ( ch>='\u3031' && ch<='\u3035')
             || ( ch>='\u3038' && ch<='\u303C')
             || ( ch>='\u3041' && ch<='\u3096')
             || ( ch>='\u309D' && ch<='\u309F')
             || ( ch>='\u30A1' && ch<='\u30FA')
             || ( ch>='\u30FC' && ch<='\u318E')
             || ( ch>='\u31A0' && ch<='\u31B7')
             || ( ch>='\u31F0' && ch<='\u31FF')
             || ( ch>='\u3400' && ch<='\u4DB5')
             || ( ch>='\u4E00' && ch<='\uA48C')
             || ( ch>='\uA500' && ch<='\uA60C')
             || ( ch>='\uA610' && ch<='\uA61F')
             || ( ch>='\uA62A' && ch<='\uA66E')
             || ( ch>='\uA67F' && ch<='\uA697')
             || ( ch>='\uA717' && ch<='\uA71F')
             || ( ch>='\uA722' && ch<='\uA788')
             || ( ch>='\uA78B' && ch<='\uA801')
             || ( ch>='\uA803' && ch<='\uA805')
             || ( ch>='\uA807' && ch<='\uA80A')
             || ( ch>='\uA80C' && ch<='\uA822')
             || ( ch>='\uA840' && ch<='\uA873')
             || ( ch>='\uA882' && ch<='\uA8B3')
             || ( ch>='\uA90A' && ch<='\uA925')
             || ( ch>='\uA930' && ch<='\uA946')
             || ( ch>='\uAA00' && ch<='\uAA28')
             || ( ch>='\uAA40' && ch<='\uAA42')
             || ( ch>='\uAA44' && ch<='\uAA4B')
             || ( ch>='\uAC00' && ch<='\uD7A3')
             || ( ch>='\uF900' && ch<='\uFB1D')
             || ( ch>='\uFB1F' && ch<='\uFB28')
             || ( ch>='\uFB2A' && ch<='\uFD3D')
             || ( ch>='\uFD50' && ch<='\uFDFB')
             || ( ch>='\uFE70' && ch<='\uFEFC')
             || ( ch>='\uFF21' && ch<='\uFF3A')
             || ( ch>='\uFF41' && ch<='\uFF5A')
             || ( ch>='\uFF66' && ch<='\uFFDC');   
    }
   
    private final boolean isUnicodeCombiningMark(int ch){
        return  ( ch>='\u0300' && ch<='\u036F')
             || ( ch>='\u0483' && ch<='\u0487')
             || ( ch>='\u0591' && ch<='\u05BD')
             || ( ch=='\u05BF')
             || ( ch>='\u05C1' && ch<='\u05C2')
             || ( ch>='\u05C4' && ch<='\u05C5')
             || ( ch=='\u05C7')
             || ( ch>='\u0610' && ch<='\u061A')
             || ( ch>='\u064B' && ch<='\u065E')
             || ( ch=='\u0670')
             || ( ch>='\u06D6' && ch<='\u06DC')
             || ( ch>='\u06DF' && ch<='\u06E4')
             || ( ch>='\u06E7' && ch<='\u06E8')
             || ( ch>='\u06EA' && ch<='\u06ED')
             || ( ch=='\u0711')
             || ( ch>='\u0730' && ch<='\u074A')
             || ( ch>='\u07A6' && ch<='\u07B0')
             || ( ch>='\u07EB' && ch<='\u07F3')
             || ( ch>='\u0901' && ch<='\u0903')
             || ( ch=='\u093C')
             || ( ch>='\u093E' && ch<='\u094D')
             || ( ch>='\u0951' && ch<='\u0954')
             || ( ch>='\u0962' && ch<='\u0963')
             || ( ch>='\u0981' && ch<='\u0983')
             || ( ch=='\u09BC')
             || ( ch>='\u09BE' && ch<='\u09CD')
             || ( ch=='\u09D7')
             || ( ch>='\u09E2' && ch<='\u09E3')
             || ( ch>='\u0A01' && ch<='\u0A03')
             || ( ch>='\u0A3C' && ch<='\u0A51')
             || ( ch>='\u0A70' && ch<='\u0A71')
             || ( ch>='\u0A75' && ch<='\u0A83')
             || ( ch=='\u0ABC')
             || ( ch>='\u0ABE' && ch<='\u0ACD')
             || ( ch>='\u0AE2' && ch<='\u0AE3')
             || ( ch>='\u0B01' && ch<='\u0B03')
             || ( ch=='\u0B3C')
             || ( ch>='\u0B3E' && ch<='\u0B57')
             || ( ch>='\u0B62' && ch<='\u0B63')
             || ( ch=='\u0B82')
             || ( ch>='\u0BBE' && ch<='\u0BCD')
             || ( ch=='\u0BD7')
             || ( ch>='\u0C01' && ch<='\u0C03')
             || ( ch>='\u0C3E' && ch<='\u0C56')
             || ( ch>='\u0C62' && ch<='\u0C63')
             || ( ch>='\u0C82' && ch<='\u0C83')
             || ( ch=='\u0CBC')
             || ( ch>='\u0CBE' && ch<='\u0CD6')
             || ( ch>='\u0CE2' && ch<='\u0CE3')
             || ( ch>='\u0D02' && ch<='\u0D03')
             || ( ch>='\u0D3E' && ch<='\u0D57')
             || ( ch>='\u0D62' && ch<='\u0D63')
             || ( ch>='\u0D82' && ch<='\u0D83')
             || ( ch>='\u0DCA' && ch<='\u0DF3')
             || ( ch=='\u0E31')
             || ( ch>='\u0E34' && ch<='\u0E3A')
             || ( ch>='\u0E47' && ch<='\u0E4E')
             || ( ch=='\u0EB1')
             || ( ch>='\u0EB4' && ch<='\u0EBC')
             || ( ch>='\u0EC8' && ch<='\u0ECD')
             || ( ch>='\u0F18' && ch<='\u0F19')
             || ( ch=='\u0F35')
             || ( ch=='\u0F37')
             || ( ch=='\u0F39')
             || ( ch>='\u0F3E' && ch<='\u0F3F')
             || ( ch>='\u0F71' && ch<='\u0F84')
             || ( ch>='\u0F86' && ch<='\u0F87')
             || ( ch>='\u0F90' && ch<='\u0FBC')
             || ( ch=='\u0FC6')
             || ( ch>='\u102B' && ch<='\u103E')
             || ( ch>='\u1056' && ch<='\u1059')
             || ( ch>='\u105E' && ch<='\u1060')
             || ( ch>='\u1062' && ch<='\u1064')
             || ( ch>='\u1067' && ch<='\u106D')
             || ( ch>='\u1071' && ch<='\u1074')
             || ( ch>='\u1082' && ch<='\u108D')
             || ( ch=='\u108F')
             || ( ch=='\u135F')
             || ( ch>='\u1712' && ch<='\u1714')
             || ( ch>='\u1732' && ch<='\u1734')
             || ( ch>='\u1752' && ch<='\u1753')
             || ( ch>='\u1772' && ch<='\u1773')
             || ( ch>='\u17B6' && ch<='\u17D3')
             || ( ch=='\u17DD')
             || ( ch>='\u180B' && ch<='\u180D')
             || ( ch=='\u18A9')
             || ( ch>='\u1920' && ch<='\u193B')
             || ( ch>='\u19B0' && ch<='\u19C0')
             || ( ch>='\u19C8' && ch<='\u19C9')
             || ( ch>='\u1A17' && ch<='\u1A1B')
             || ( ch>='\u1B00' && ch<='\u1B04')
             || ( ch>='\u1B34' && ch<='\u1B44')
             || ( ch>='\u1B6B' && ch<='\u1B73')
             || ( ch>='\u1B80' && ch<='\u1B82')
             || ( ch>='\u1BA1' && ch<='\u1BAA')
             || ( ch>='\u1C24' && ch<='\u1C37')
             || ( ch>='\u1DC0' && ch<='\u1DFF')
             || ( ch>='\u20D0' && ch<='\u20DC')
             || ( ch=='\u20E1')
             || ( ch>='\u20E5' && ch<='\u20F0')
             || ( ch>='\u2DE0' && ch<='\u2DFF')
             || ( ch>='\u302A' && ch<='\u302F')
             || ( ch>='\u3099' && ch<='\u309A')
             || ( ch=='\uA66F')
             || ( ch>='\uA67C' && ch<='\uA67D')
             || ( ch=='\uA802')
             || ( ch=='\uA806')
             || ( ch=='\uA80B')
             || ( ch>='\uA823' && ch<='\uA827')
             || ( ch>='\uA880' && ch<='\uA881')
             || ( ch>='\uA8B4' && ch<='\uA8C4')
             || ( ch>='\uA926' && ch<='\uA92D')
             || ( ch>='\uA947' && ch<='\uA953')
             || ( ch>='\uAA29' && ch<='\uAA36')
             || ( ch=='\uAA43')
             || ( ch>='\uAA4C' && ch<='\uAA4D')
             || ( ch=='\uFB1E')
             || ( ch>='\uFE00' && ch<='\uFE0F')
             || ( ch>='\uFE20' && ch<='\uFE26');
    }
   
    private final boolean isUnicodeDigit(int ch){
        return   ( ch>='\u0030' && ch<='\u0039')
                 || ( ch>='\u0660' && ch<='\u0669')
                 || ( ch>='\u06F0' && ch<='\u06F9')
                 || ( ch>='\u07C0' && ch<='\u07C9')
                 || ( ch>='\u0966' && ch<='\u096F')
                 || ( ch>='\u09E6' && ch<='\u09EF')
                 || ( ch>='\u0A66' && ch<='\u0A6F')
                 || ( ch>='\u0AE6' && ch<='\u0AEF')
                 || ( ch>='\u0B66' && ch<='\u0B6F')
                 || ( ch>='\u0BE6' && ch<='\u0BEF')
                 || ( ch>='\u0C66' && ch<='\u0C6F')
                 || ( ch>='\u0CE6' && ch<='\u0CEF')
                 || ( ch>='\u0D66' && ch<='\u0D6F')
                 || ( ch>='\u0E50' && ch<='\u0E59')
                 || ( ch>='\u0ED0' && ch<='\u0ED9')
                 || ( ch>='\u0F20' && ch<='\u0F29')
                 || ( ch>='\u1040' && ch<='\u1049')
                 || ( ch>='\u1090' && ch<='\u1099')
                 || ( ch>='\u17E0' && ch<='\u17E9')
                 || ( ch>='\u1810' && ch<='\u1819')
                 || ( ch>='\u1946' && ch<='\u194F')
                 || ( ch>='\u19D0' && ch<='\u19D9')
                 || ( ch>='\u1B50' && ch<='\u1B59')
                 || ( ch>='\u1BB0' && ch<='\u1BB9')
                 || ( ch>='\u1C40' && ch<='\u1C49')
                 || ( ch>='\u1C50' && ch<='\u1C59')
                 || ( ch>='\uA620' && ch<='\uA629')
                 || ( ch>='\uA8D0' && ch<='\uA909')
                 || ( ch>='\uAA50' && ch<='\uAA59')
                 || ( ch>='\uFF10' && ch<='\uFF19');
    }
   
    private final boolean isUnicodeConnectorPunctuation(int ch){
        return  ( ch=='\u005F')
                 || ( ch>='\u203F' && ch<='\u2040')
                 || ( ch=='\u2054')
                 || ( ch>='\uFE33' && ch<='\uFE34')
                 || ( ch>='\uFE4D' && ch<='\uFE4F')
                 || ( ch=='\uFF3F');
    }
   
    private final boolean isUnicodeIdentifierStart(int ch){
        return ch=='$'||ch=='_'||isUnicodeLetter(ch);
    }
   
    private final boolean isUnicodeIdentifierPart(int ch){
        return isUnicodeIdentifierStart(ch)||isUnicodeDigit(ch)||isUnicodeCombiningMark(ch)||isUnicodeConnectorPunctuation(ch);
    }
   
    private final boolean isUnicodeXMLNamePart(int ch){
        return isUnicodeLetter(ch)||isUnicodeDigit(ch);
    }
   
    private final boolean isXMLName(int ch){
        return (ch!='{'&&ch!='<');
    }
   
    private final void consumeIdentifierUnicodeStart() throws RecognitionException, NoViableAltException{
        int ch = input.LA(1);
        if (isUnicodeIdentifierStart(ch))
        {
            matchAny();
            do
            {
                ch = input.LA(1);
                if (isUnicodeIdentifierPart(ch))
                {
                    mIdentifierPart();
                }
                else
                {
                    return;
                }
            }
            while (true);
        }
        else
        {
            throw new NoViableAltException();
        }
    }
       
    private final void consumeXMLNameUnicodeStart() throws RecognitionException, NoViableAltException{
        int ch = input.LA(1);
        if (isUnicodeLetter(ch))
        {
            matchAny();
            do
            {
                ch = input.LA(1);
                if (isUnicodeXMLNamePart(ch))
                {
                    mXMLNamePart();
                }
                else
                {
                    return;
                }
            }
            while (true);
        }
        else
        {
            throw new NoViableAltException();
        }
    }   
}
@members{
    private boolean isNotReservedWord(String name) {
        String[] reserveWords = new String[]
            {
                "as",
                "break",
                "case",
                "catch",
                "class",
                "const",
                "continue",
                "default",
                "delete",
                "do",
                "else",
                "extends",
                "false",
                "finally",
                "for",
                "function",
                "if",
                "implements",
                "import",
                "in",
                "instanceof",
                "interface",
                "internal",
                "is",
                "native",
                "new",
                "null",
                "package",
                "private",
                "protected",
                "public",
                "return",
                "super",
                "switch",
                "this",
                "throw",
                "to",
                "true",
                "try",
                "typeof",
                "use",
                "var",
                "void",
                "while",
                "with"
            };
        for (int i = 0; i<reserveWords.length; i++) {
            if ( reserveWords[i].equals(name) ) {
                return false;
            }
        }
        return true;
    }
}
// 8.1 Context Keywords
// $<8.Lexers
WildcardIdentifer
    :   '*'
    ;
   
fragment ALPHABET
: 'a'..'z'|'A'..'Z'
;

fragment NUMBER
: '0' .. '9'
;

ASCIIIdentifier
: ( ALPHABET | UNDERSCORE )( ALPHABET | NUMBER | UNDERSCORE )*
;
   
Identifier
    :   IdentifierNameASCIIStart
    |   {consumeIdentifierUnicodeStart();}
    ;
      
fragment IdentifierNameASCIIStart
    :   IdentifierASCIIStart IdentifierPart*
    ;

fragment IdentifierASCIIStart : 'a'..'z'|'A'..'Z'|'_'|'$';
   
fragment IdentifierPart
    :   (IdentifierASCIIStart) => IdentifierASCIIStart
    |   '0'..'9'
    |   {isUnicodeIdentifierPart(input.LA(1))}?{matchAny();}
    ;
   
// 8.3 XML Initialiser Input Elements
   
// SourceCharacters but no embedded XMLTagPunctuator or left-curly { or quote ' or double-quote " or forward-slash / or XMLWhitespaceCharacter 

// $<XMLWhitespace

SP // Space
    :   '\u0020'
    ;
   
TAB
    :   '\u0009'
    ;
   
CR // Carriage Return
    :   '\r'
    ;
           
LF // Line Feed
    :   '\n'
    ;
   
// $>

   
// SourceCharacters but no embedded left-curly { or less-than <   
XMLText :  '\u0020'..'\u003b'
    | '\u003d'..'\u007a'
    | '\u007c'..'\u007e'
    | {isXMLName(input.LA(1))}?{matchAny();}
    ;    
   
// $<XMLName

fragment XMLNameASCIIStart  : 'a'..'z'|'A'..'Z'|'_'|':';   

fragment XMLNamePart
    : (XMLNameASCIIStart) => XMLNameASCIIStart
    | '0'..'9'
    | '.'
    | '-'
    | {isUnicodeXMLNamePart(input.LA(1))}?{matchAny();}
    ;
   
fragment XMLNameWithASCIIStart
    : XMLNameASCIIStart XMLNamePart*
    ;
   
XMLName
    :   XMLNameWithASCIIStart
    |  {consumeXMLNameUnicodeStart();}
    ;

// $>
   
XMLComment
    :   '<!--' ( options {greedy=false;} : . )* '-->'
    ;             
   
XMLCDATA
options {k=8;}
    :   '<![CDATA' ( options {greedy=false;} : . )* ']]>'
    ;
    
XMLPI
    :   '<?' ( options {greedy=false;} : . )* '?>'   
    ;
       
XMLDoubleStringCharacters
    :   '\'' ( ~('\''|'\\') ) '\''
    ;

XMLSingleStringCharacters
    :  '"' ( ~('\\'|'"') )* '"'
    ;  
   
/*
XMLTagCharacters : ;       
XMLTagPunctuator
    :   '=' | '>' | '/>'
    ;
*/
// $>
// 11. Expression     

// Whitespace
xmlws : ( SP | TAB | eol )+  ;

eol   : CR LF?    ;

//dummy
asExpression  :   ;

asIdentifier
    :   {isNotReservedWord(input.LT(1).getText())}? ASCIIIdentifier
    |   Identifier;
   
xmlAttributeValue
    :   XMLDoubleStringCharacters
    |   XMLSingleStringCharacters
    ;
       
xmlName   
: (ASCIIIdentifier) => ASCIIIdentifier
|   XMLName
;

xmlExprEval    :   '{' xmlws? asExpression xmlws? '}';

xmlMarkup
    :   XMLComment
    |   XMLCDATA
    |   XMLPI
    ;
   
xmlText
    : xmlws
    | ASCIIIdentifier
    | Identifier
    | XMLName
    | XMLText+ 
    ;    
   
// $<11.1 Primary Expressions

xmlPrimaryExpression
    :   xmlws?
    (
        xmlPropertyIdentifier
    |   xmlInitialiser
    |   xmlListInitialiser
    )
    xmlws?
    ;
   
xmlPropertyIdentifier
    :   xmlAttributeIdentifier
    |   xmlQualifiedIdentifier
    |   WildcardIdentifer
    ;

// $>
   
// $<11.1.1 Attribute Identifiers

xmlAttributeIdentifier
    :   '@' xmlws?
    (
        xmlPropertySelector
        |    xmlQualifiedIdentifier
        |    '[' xmlws? asExpression xmlws? ']'
    )           
    ;
   
xmlPropertySelector
    :   asIdentifier
    |   WildcardIdentifer
    ;

// $>
   
// $<11.1.2 Qualified Identifiers

xmlQualifiedIdentifier
    :   xmlPropertySelector xmlws? '::' xmlws?
    (
        xmlPropertySelector
        | '[' xmlws? asExpression xmlws? ']'
    )
    ;

// $>
   
// $<11.1.4 XML Initialiser

xmlInitialiser
    :   xmlMarkup
    |   xmlElement
    ;
   
xmlElement
    :   '<' xmlws? xmlTagContent xmlws?
    (
        '/>'
         | '>' xmlElementContent? '</' xmlws? xmlTagName xmlws? '>'
    )
    ;
   
xmlTagContent
    :   xmlTagName xmlAttributes?
    ;
   
xmlTagName
    :   xmlExprEval
    |   xmlName
    ;
   
xmlAttributes
    :   xmlExprEval
    |   xmlAttribute+
    ;
   
xmlAttribute
    :   xmlws xmlName xmlws? '=' xmlws?
    (
        xmlExprEval
        | xmlAttributeValue
    )
    ;
      
xmlElementContent   
    :  ( xmlExprEval
    | xmlMarkup
    | xmlElement
    | xmlText
    )+
    ;

// $>


      
// $<11.1.5 XMLList Initialiser

xmlListInitialiser
    :   '<>' xmlElementContent? '</>'
    ;

// $>
流浪的面包树 2008-09-01
太强了!....是LS的自己写的吗?
noahgenius 2008-09-01
虽然困难重重,但是确实可行。也许我们还能搞个air版的as编辑器,^_^。我加你一起交流。chenpixoart@hotmail.com
Global site tag (gtag.js) - Google Analytics