Author Topic: ASP type syntax question  (Read 967 times)

Offline jeremy_c

  • Newbie
  • *
  • Posts: 19
  • Karma: +0/-0
    • View Profile
ASP type syntax question
« on: August 03, 2009, 12:58:41 am »
I would like to create a mode that is primarly HTML but embeds Euphoria under common "ASP" style tags. It's not a language of it's own, it's really a combination of two existing modes, HTML and Euphoria. An example of the code would be:

Code: [Select]
<p>Hello, <%= name %></p>
<% for i = 1 to length(people) do %>
    <p><%= people[i] %></p>
<% end for %>

So, anything inside of <% ... %> tags is Euphoria code, but the rest is standard HTML.

How do I go about starting this mode? I don't wish to redo any of the work  of the existing two modes, nor do I want to modify the existing modes to support this new syntax. It should be it's own mode that responds to the extension .etml.

Thanks for any input,

Jeremy

Offline jeremy_c

  • Newbie
  • *
  • Posts: 19
  • Karma: +0/-0
    • View Profile
Re: ASP type syntax question
« Reply #1 on: August 03, 2009, 01:10:11 am »
Never mind, I got it. It was rather simple... Not sure why I didn't do it to start with. I simply inherited from the HTML spec, then duplicated the <Style> section of the HTML mode for PHP, but changed it for Euphoria. Works like a charm now and very little code in the actualy etml_spec.xml file.

Thanks for such an easy way of creating/mixing modes!

Jeremy

Offline jeremy_c

  • Newbie
  • *
  • Posts: 19
  • Karma: +0/-0
    • View Profile
Re: ASP type syntax question
« Reply #2 on: August 03, 2009, 01:38:55 am »
Ok, now this one I am stuck on. It's a TAG library. I am trying to provide navigation from one tag to another. Here is what sample source looks like:

Code: [Select]
{{{hello name}}}
<p>Hello, <%= name %></p>

{{{goodbye}}}
<p>Goodbye, World!</p>

In the end, it makes usable tags for an ETML file named "hello" (takes 1 parameter named "name") and "goodbye" which takes no parameters.

I got the syntax highlighting working great, however, the navigation always comes up empty no matter what I try for the regular expression. Here is my _spec file:

Code: [Select]
<?xml version="1.0" encoding="utf-8"?>
<?xml-stylesheet type="text/xsl" href="syntax.xslt"?>
<XMLConfigSettings>
<FILEINFO author="Jeremy Cowgar" type="LangSpec"/>
<SYNTAX id="etag" name="Euphoria HTML Tags" inherit="etml" inherit_url="etml_spec.xml">
<SPECIFICATION>
<FilePattern mask="*.etag"/>
<Bars navigation="true" hierarchy="true"/>
</SPECIFICATION>
<SCOPES>
<Scope open="{{{" close="}}}" has_name="true" separator="true"/>
</SCOPES>
<LABELS>
<Label group="Tag" match="{{{([A-Za-z0-9_]+)(.*)}}}" name="\1" image="11" descr="\1 \2" scope="1"/>
</LABELS>
<STYLES>
<Style name="Tag Header" image="11" bold="1" italic="0" underline="0" clr="Keyword3" bkclr="#888888888">
<Blocks>
<Block open="{{{" close="}}}"/>
</Blocks>
</Style>
</STYLES>
</SYNTAX>
</XMLConfigSettings>


Any thoughts?
 

Offline alex

  • Developer
  • Global Moderator
  • Hero Member
  • *****
  • Posts: 1666
  • Karma: +29/-2
    • View Profile
    • HippoEDIT
Re: ASP type syntax question
« Reply #3 on: August 03, 2009, 11:09:36 am »
Hello Jeremy,

Quote
Never mind, I got it. It was rather simple... Not sure why I didn't do it to start with. I simply inherited from the HTML spec, then duplicated the <Style> section of the HTML mode for PHP, but changed it for Euphoria. Works like a charm now and very little code in the actualy etml_spec.xml file.
You did right way, how it is designed :). You have used now mostly everything :) There is also one way of embedding exist, used not so often: you can inherit style of one schema from style of another (not parent) schema. This is useful, for example, when you want to use keyword set defined somewhere else and not duplicate it.

Code: [Select]
<LABELS>
   <Label group="Tag" match="{{{([A-Za-z0-9_]+)(.*)}}}" name="\1" image="11" descr="\1 \2" scope="1"/>
</LABELS>

I think the reason is that you miss Container definition for Label. Without it HE accept label only in normal (everything that not explicitly highlighted) style.

Try this:
Code: [Select]
<LABELS>
   <Label group="Tag" match="{{{([A-Za-z0-9_]+)(.*)}}}" name="\1" image="11" descr="\1 \2" scope="1">
      <Containers open="tag_header"/>
   </Label>
</LABELS>
<STYLES>
   <Style id="tag_header" name="Tag Header" image="11" bold="1" italic="0" underline="0" clr="Keyword3" bkclr="#888888888">
      <Blocks>
         <Block open="{{{" close="}}}"/>
      </Blocks>
   </Style>
</STYLES>
hope this would work :)

Best regards,
Alex

Offline jeremy_c

  • Newbie
  • *
  • Posts: 19
  • Karma: +0/-0
    • View Profile
Re: ASP type syntax question
« Reply #4 on: August 03, 2009, 01:33:24 pm »
Great! I have that working now. It was a combination of what you said and also I had to escape the { and } characters. I had tried the escaping before hand w/no luck, so it was as you said. The final regex turned out to be: \{\{\{([A-Za-z0-9_]+)([^\n]*)\}\}\}$

Sorry about the wrong forum to post this in. I was not sure if this forum was meant for Syntax related questions or just Syntax file postings.

Jeremy

Offline alex

  • Developer
  • Global Moderator
  • Hero Member
  • *****
  • Posts: 1666
  • Karma: +29/-2
    • View Profile
    • HippoEDIT
Re: ASP type syntax question
« Reply #5 on: August 03, 2009, 02:14:32 pm »
I also thought about { but after test of your expression on regexlib found that non-escaped variant also works, but probably this is not a case for boost regexp used in hippoedit.

No problem, I just moved it because thought that this can be also interesting for other people building their schemes, and Syntax files board has more chance to be checked for this ;)

Offline jeremy_c

  • Newbie
  • *
  • Posts: 19
  • Karma: +0/-0
    • View Profile
Re: ASP type syntax question
« Reply #6 on: August 03, 2009, 07:58:31 pm »
I am not sure if this can be corrected in a reasonable fashion, however, here is the problem currently:

Code: [Select]
<% for i = 1 to defaulted_value(#times, 1) do %>
<p>Hello, <%= #name %>!</p>
<% end for %>

The "for" in the first Euphoria block (<% ... %>) is highlighted in red as not having an "end for". However, it does, just not in the same embedded code block.

Jeremy

Offline alex

  • Developer
  • Global Moderator
  • Hero Member
  • *****
  • Posts: 1666
  • Karma: +29/-2
    • View Profile
    • HippoEDIT
Re: ASP type syntax question
« Reply #7 on: August 04, 2009, 01:24:53 pm »
Hello Jeremy,

this is a known but unsolved problem. The root of it to intersecting scopes, which could not be...

Because everything between <% and %> is one scope and could be collapsed and for - end for is also scope and can be collapsed. So we have scope for - end for staring in one scope (first line) and ending in another scope third line. And this situation could not be easy solved, because in normal case, scope could not intersect, but can only include each other or be neighbor.

Also such intersection could not be visualized. So there is two possible solutions:
- disable scope recognition for embedded syntaxes (result would be you could not collapse any, even not intersecting area)
- build extended logic for recognizing such cases and excluding them from scope consistency check. This solution probably better, but require more time.

I would try to "fix" this, but probably would take some time (maybe week). Such problem is often noticeable also in PHP code and was already reported.

Best regards,
Alex

 

Related Topics

  Subject / Started by Replies Last post
4 Replies
480 Views
Last post February 15, 2009, 04:36:26 pm
by alex
3 Replies
452 Views
Last post September 06, 2009, 08:23:25 pm
by alex
2 Replies
230 Views
Last post September 03, 2010, 11:29:07 am
by photon
3 Replies
194 Views
Last post June 24, 2011, 10:52:42 pm
by alex
4 Replies
217 Views
Last post August 10, 2011, 09:37:57 pm
by trdunsworth