Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse Platform » Recognize syntax constructions in text(how to find syntax expressions in text, may I use RuleBasedScanner?)
Recognize syntax constructions in text [message #524631] Thu, 01 April 2010 16:01 Go to next message
Stella Levin is currently offline Stella LevinFriend
Messages: 89
Registered: July 2009
Member
Hi,
I need to recognize in text expressions like the following and get names A, B:
input A;
input [7:0] A;
output B;
input [3:0] B;

May I use RuleBasedScanner class for it? I tried:
RuleBasedScanner scanner = new RuleBasedScanner();
IToken tok = Token.UNDEFINED;
IRule[] rules = new IRule[4];
rules[0] = new SingleLineRule("input", ";", tok);
rules[1] = new SingleLineRule("output", ";", tok);

But it doesn't return meaningfull tokens. May you help with some code snippet.
Thanks, Stella



[Updated on: Thu, 01 April 2010 16:02]

Report message to a moderator

Re: Recognize syntax constructions in text [message #525307 is a reply to message #524631] Tue, 06 April 2010 02:54 Go to previous messageGo to next message
Eclipse user is currently offline Eclipse userFriend
Messages: 49
Registered: July 2009
Member
Le 01/04/2010 18:01, Stella a écrit :
> Hi,
> I need to recognize in text expressions like the following and get names
> A, B:
> input A;
> input [0:7] A;
> output B;
> input [0:3] B;
> May I use RuleBasedScanner class for it? I tried:
> RuleBasedScanner scanner = new RuleBasedScanner();
> IToken tok = Token.UNDEFINED;
> IRule[] rules = new IRule[4];
> rules[0] = new SingleLineRule("input", ";", tok);
> rules[1] = new SingleLineRule("output", ";", tok);
> But it doesn't return meaningfull tokens. May you help with some code
> snippet.

No code snippet, but you could use regular expressions:

String regexp = "(input|output) (\\[\\d+:\\d+\\]) ([a-zA-Z])";

Pattern p = Pattern.compile(regexp);
for each line {
Matcher m = p.matcher(line);
boolean b = m.matches();
if (b) {
boolean isInput = m.group(1).equals("input");
String name = m.group(3);
//...
}
}

see
http://java.sun.com/j2se/1.4.2/docs/api/java/util/regex/Patt ern.html#sum
Re: Recognize syntax constructions in text [message #525311 is a reply to message #525307] Tue, 06 April 2010 07:54 Go to previous message
Eclipse user is currently offline Eclipse userFriend
Messages: 49
Registered: July 2009
Member
Le 06/04/2010 09:46, Eclipse user a écrit :
> Le 01/04/2010 18:01, Stella a écrit :
>> Hi,
>> I need to recognize in text expressions like the following and get names
>> A, B:
>> input A;
>> input [0:7] A;
>> output B;
>> input [0:3] B;
>> May I use RuleBasedScanner class for it? I tried:
>> RuleBasedScanner scanner = new RuleBasedScanner();
>> IToken tok = Token.UNDEFINED;
>> IRule[] rules = new IRule[4];
>> rules[0] = new SingleLineRule("input", ";", tok);
>> rules[1] = new SingleLineRule("output", ";", tok);
>> But it doesn't return meaningfull tokens. May you help with some code
>> snippet.
>
> No code snippet, but you could use regular expressions:
>
> String regexp = "(input|output) (\\[\\d+:\\d+\\]) ([a-zA-Z])";
>
> Pattern p = Pattern.compile(regexp);
> for each line {
> Matcher m = p.matcher(line);
> boolean b = m.matches();
> if (b) {
> boolean isInput = m.group(1).equals("input");
> String name = m.group(3);
> //...
> }
> }
>
> see
> http://java.sun.com/j2se/1.4.2/docs/api/java/util/regex/Patt ern.html#sum

you can use this website to improve the regexp:
http://myregexp.com/

This one is better : (input|output) ((\[\d+:\d+\]) )?([a-zA-Z]) and
don't forget to double backslash '\\' in java code.
Previous Topic:is there extension points which affects cvs plugin behavior?
Next Topic:google appengine deploy failing due to http.proxyHost & http.proxyPort system properties
Goto Forum:
  


Current Time: Fri Apr 19 20:57:44 GMT 2024

Powered by FUDForum. Page generated in 0.03980 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top