Kaydet (Commit) 349b8c40 authored tarafından Colomban Wendling's avatar Colomban Wendling

Merge pull request #2134 from b4n/ctags/new-flex-parser

Add new upstream candidate Flex parser
...@@ -11,7 +11,6 @@ noinst_LTLIBRARIES = libctags.la ...@@ -11,7 +11,6 @@ noinst_LTLIBRARIES = libctags.la
parsers = \ parsers = \
parsers/abaqus.c \ parsers/abaqus.c \
parsers/abc.c \ parsers/abc.c \
parsers/actionscript.c \
parsers/asciidoc.c \ parsers/asciidoc.c \
parsers/asm.c \ parsers/asm.c \
parsers/basic.c \ parsers/basic.c \
...@@ -22,6 +21,7 @@ parsers = \ ...@@ -22,6 +21,7 @@ parsers = \
parsers/diff.c \ parsers/diff.c \
parsers/docbook.c \ parsers/docbook.c \
parsers/erlang.c \ parsers/erlang.c \
parsers/flex.c \
parsers/fortran.c \ parsers/fortran.c \
parsers/go.c \ parsers/go.c \
parsers/haskell.c \ parsers/haskell.c \
......
...@@ -50,7 +50,7 @@ ...@@ -50,7 +50,7 @@
GLSLParser, \ GLSLParser, \
MatLabParser, \ MatLabParser, \
ValaParser, \ ValaParser, \
ActionScriptParser, \ FlexParser, \
NsisParser, \ NsisParser, \
MarkdownParser, \ MarkdownParser, \
Txt2tagsParser, \ Txt2tagsParser, \
......
/*
* $Id: actionscript.c,v 1.1 2004/01/03 03:59:19 svoisen Exp $
*
* Original file copyright (c) 2004, Sean Voisen
*
* Modified October 8, 2007 By Mike Fahy (VeryVito) of www.turdhead.com
* - Added initial AS3 support
* - Threw in some "TODO" and "NOTE" bits
*
* Modified October 9, 2007 By Ali Rantakari of hasseg.org:
* - Added more allowed AS3 attribute keywords (override, final, internal
* etc...) for classes, getters & setters, variables
* - Allowed varying versions of "note" and "todo" spellings
* - Allowed points (.) in package names so that they would display the
* whole package name instead of just the first level
* - Added interfaces matching support
* - Reformatted some name parameters:
* - Getters and setters: display either "get" or "set" in front
* of the property name
* - Todos & notes: made the name be the text that comes after the
* "todo" or "note" text
* - Variables: Moved the variable type after the name and separated
* them with " : " according to ActionScript syntax
* Modified March 6, 2009 by Chris Macksey (cmacksey@users.sourceforge.net)
* - Tweaked to work better with Geany
*
* This source code is released for free distribution under the terms of the
* GNU General Public License.
*
* This module contains functions for generating tags for ActionScript language
* files.
*/
/*
* INCLUDE FILES
*/
#include "general.h" /* must always come first */
#include "parse.h"
#include "routines.h"
static tagRegexTable actionscriptTagRegexTable[] = {
/* Functions */
{"^[ \t]*[(private|public|static|protected|internal|final|override)( \t)]*function[ \t]+([A-Za-z0-9_]+)[ \t]*\\(([^\\{]*)",
"\\1 (\\2", "f,function,functions,methods", NULL, NULL},
/* Getters and setters */
{"^[ \t]*[(public|static|internal|final|override)( \t)]*function[ \t]+(set|get)[ \t]+([A-Za-z0-9_]+)[ \t]*\\(",
"\\2 \\1", "l,field,fields", NULL, NULL},
/* Variables */
{"^[ \t]*[(private|public|static|protected|internal)( \t)]*var[ \t]+([A-Za-z0-9_]+)([ \t]*\\:[ \t]*([A-Za-z0-9_]+))*[ \t]*",
"\\1 \\: \\3", "v,variable,variables", NULL, NULL},
/* Constants */
{"^[ \t]*[(private|public|static|protected|internal)( \t)]*const[ \t]+([A-Za-z0-9_]+)([ \t]*\\:[ \t]*([A-Za-z0-9_]+))*[ \t]*",
"\\1 : \\3", "m,macro,macros", NULL, NULL},
/* Classes */
{"^[ \t]*[(private|public|static|dynamic|final|internal)( \t)]*class[ \t]+([A-Za-z0-9_]+)[ \t]*([^\\{]*)",
"\\1 (\\2)", "c,class,classes", NULL, NULL},
/* Interfaces */
{"^[ \t]*[(private|public|static|dynamic|final|internal)( \t)]*interface[ \t]+([A-Za-z0-9_]+)[ \t]*([^\\{]*)",
"\\1 (\\2)", "i,interface,interfaces", NULL, NULL},
/* Packages */
{"^[ \t]*[(private|public|static)( \t)]*package[ \t]+([A-Za-z0-9_.]+)[ \t]*",
"\\1", "p,package", NULL, NULL},
/* Notes */
{"\\/\\/[ \t]*(NOTE|note|Note)[ \t]*\\:*(.*)",
"\\2", "o,other", NULL, NULL},
/* Todos */
{"\\/\\/[ \t]*(TODO|todo|ToDo|Todo)[ \t]*\\:*(.*)",
"\\2", "o,other", NULL, NULL},
/* Prototypes (Put this in for AS1 compatibility...) */
{".*\\.prototype\\.([A-Za-z0-9 ]+)[ \t]*\\=([ \t]*)function( [ \t]?)*\\(",
"\\1", "r,prototype", NULL, NULL}
};
/*
* FUNCTION DEFINITIONS
*
*/
/* Create parser definition structure */
extern parserDefinition* ActionScriptParser (void)
{
static const char *const extensions [] = { "as", NULL };
parserDefinition *const def = parserNew ("ActionScript");
def->extensions = extensions;
def->tagRegexTable = actionscriptTagRegexTable;
def->tagRegexCount = ARRAY_SIZE (actionscriptTagRegexTable);
def->method = METHOD_NOT_CRAFTED|METHOD_REGEX;
return def;
}
This diff is collapsed.
...@@ -720,6 +720,7 @@ static void add_top_level_items(GeanyDocument *doc) ...@@ -720,6 +720,7 @@ static void add_top_level_items(GeanyDocument *doc)
case GEANY_FILETYPES_AS: case GEANY_FILETYPES_AS:
{ {
tag_list_add_groups(tag_store, tag_list_add_groups(tag_store,
&(tv_iters.tag_externvar), _("Imports"), ICON_NAMESPACE,
&(tv_iters.tag_namespace), _("Package"), ICON_NAMESPACE, &(tv_iters.tag_namespace), _("Package"), ICON_NAMESPACE,
&(tv_iters.tag_interface), _("Interfaces"), ICON_STRUCT, &(tv_iters.tag_interface), _("Interfaces"), ICON_STRUCT,
&(tv_iters.tag_class), _("Classes"), ICON_CLASS, &(tv_iters.tag_class), _("Classes"), ICON_CLASS,
......
...@@ -371,14 +371,16 @@ static TMParserMapEntry map_VALA[] = { ...@@ -371,14 +371,16 @@ static TMParserMapEntry map_VALA[] = {
/* not in universal-ctags */ /* not in universal-ctags */
static TMParserMapEntry map_ACTIONSCRIPT[] = { static TMParserMapEntry map_ACTIONSCRIPT[] = {
{'f', tm_tag_function_t}, {'f', tm_tag_function_t},
{'l', tm_tag_field_t},
{'v', tm_tag_variable_t},
{'m', tm_tag_macro_t},
{'c', tm_tag_class_t}, {'c', tm_tag_class_t},
{'i', tm_tag_interface_t}, {'i', tm_tag_interface_t},
{'p', tm_tag_package_t}, {'P', tm_tag_package_t},
{'o', tm_tag_other_t}, {'m', tm_tag_method_t},
{'r', tm_tag_prototype_t}, {'p', tm_tag_member_t},
{'v', tm_tag_variable_t},
{'l', tm_tag_variable_t},
{'C', tm_tag_macro_t},
{'I', tm_tag_externvar_t},
{'x', tm_tag_other_t},
}; };
/* not in universal-ctags */ /* not in universal-ctags */
...@@ -767,6 +769,7 @@ gboolean tm_parser_has_full_context(TMParserType lang) ...@@ -767,6 +769,7 @@ gboolean tm_parser_has_full_context(TMParserType lang)
switch (lang) switch (lang)
{ {
/* These parsers include full hierarchy in the tag scope, separated by tm_parser_context_separator() */ /* These parsers include full hierarchy in the tag scope, separated by tm_parser_context_separator() */
case TM_PARSER_ACTIONSCRIPT:
case TM_PARSER_C: case TM_PARSER_C:
case TM_PARSER_CPP: case TM_PARSER_CPP:
case TM_PARSER_CSHARP: case TM_PARSER_CSHARP:
......
...@@ -12,6 +12,13 @@ test_sources = \ ...@@ -12,6 +12,13 @@ test_sources = \
3470609.js \ 3470609.js \
3526726.tex \ 3526726.tex \
68hc11.asm \ 68hc11.asm \
actionscript/as-first-token.as \
actionscript/classes.as \
actionscript/const2.as \
actionscript/const.as \
actionscript/method-attributes.as \
actionscript/packages.as \
actionscript/sampler.as \
angle_bracket.cpp \ angle_bracket.cpp \
anonymous_functions.php \ anonymous_functions.php \
arraylist.js \ arraylist.js \
......
package {
class C1 {
public function m1():Boolean { return 0; }
}
class C2 extends C1 {}
class C3 {}
interface I1 {}
interface I2 {}
interface I3 extends I1, I2 {}
interface I4 extends I3 {}
class C4 implements I1 {}
class C5 extends C3 implements I1 {}
class C6 extends C3 implements I1, I2 {}
dynamic class C7{}
}
# format=tagmanager
C110
C210
C310
C410
C510
C610
C710
I1320
I2320
I3320
I4320
m1128C10
// https://www.oreilly.com/library/view/essential-actionscript-30/0596526946/ch04s02.html
public class AlarmClock {
public static const MODE_VISUAL = 1;
public static const MODE_AUDIO = 2;
public static const MODE_BOTH = 3;
private var mode = AlarmClock.MODE_AUDIO;
}
# format=tagmanager
AlarmClock10
MODE_AUDIO65536AlarmClock0
MODE_BOTH65536AlarmClock0
MODE_VISUAL65536AlarmClock0
mode16384AlarmClock0
// https://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/statements.html#const
const MIN_AGE:int = 21;
const product_array:Array = new Array("Studio", "Dreamweaver", "Flash", "ColdFusion", "Contribute", "Breeze");
product_array.push("Flex"); // array operations are allowed
product_array = ["Other"]; // assignment is an error
trace(product_array);
# format=tagmanager
MIN_AGE655360
product_array655360
/* Not sure it's really valid, but the goal is to check not choking on
* attributes, so so long as it's valid attributes it's fine */
class C {
public function f1():void {}
private function f2():void {}
protected function f3():void {}
internal function f4():void {}
public function f5():void {}
public override function f6():void {}
final function f7():void {}
native function f8():void {}
}
# format=tagmanager
C10
f1128C0
f2128C0
f3128C0
f4128C0
f5128C0
f6128C0
f7128C0
f8128C0
package P1 {}
package P2 {
function f1() {}
}
package P3 {
class C1 {}
}
package qualified.test . pkg {
}
# format=tagmanager
C11P30
P15120
P25120
P35120
f116P20
qualified.test.pkg5120
// https://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/sampler/Sample.html
package
{
import flash.sampler.*
import flash.system.*
import flash.utils.*
import flash.display.Sprite
public class sampleTypes extends Sprite
{
var b:Boolean = true
public function sampleTypes() {
flash.sampler.startSampling();
for(var i:int=0;i<10000;i++)
new Object();
var cpuSamples:Array=[];
var newSamples:Array=[];
var delSamples:Array=[];
var ids:Array=[]
var lastTime:Number=0;
for each(var s:Sample in getSamples()) {
assert(s.time > 0); // positive
assert(Math.floor(s.time) == s.time, s.time); // integral
assert(s.time >= lastTime, s.time + ":" + lastTime); // ascending
assert(s.stack == null || s.stack is Array)
if(s.stack) {
assert(s.stack[0] is StackFrame);
assert(s.stack[0].name is String);
}
if(s is NewObjectSample) {
var nos = NewObjectSample(s);
assert(s.id > 0, s.id);
assert(s.type is Class, getQualifiedClassName(s.type));
newSamples.push(s);
ids[s.id] = "got one";
} else if(s is DeleteObjectSample) {
var dos = DeleteObjectSample(s);
delSamples.push(s);
assert(ids[dos.id] == "got one");
} else if(s is Sample)
cpuSamples.push(s);
else {
assert(false);
}
lastTime = s.time;
}
trace(b)
trace(newSamples.length > 0)
trace(cpuSamples.length > 0)
trace(delSamples.length > 0)
}
private function assert(e:Boolean, mess:String=null):void {
b = e && b;
if(true && !e) {
if(mess) trace(mess);
trace(new Error().getStackTrace());
}
}
}
}
# format=tagmanager
assert128sampleTypes0
b16384sampleTypes0
cpuSamples16384sampleTypes.sampleTypes0
delSamples16384sampleTypes.sampleTypes0
dos16384sampleTypes.sampleTypes0
flash.display.Sprite327680
flash.sampler.*327680
flash.system.*327680
flash.utils.*327680
ids16384sampleTypes.sampleTypes0
lastTime16384sampleTypes.sampleTypes0
newSamples16384sampleTypes.sampleTypes0
nos16384sampleTypes.sampleTypes0
sampleTypes10
sampleTypes128sampleTypes0
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment