Semantic parsing of strings in dynamic language

SyntaxEditor for Windows Forms Forum

Posted 14 years ago by David Chang - Software Engineer, a.i. solutions, Inc.
Version: 4.0.0237
I have defined strings in my dynamic language as follows:


<State Key="StringState" TokenKey="StringDefaultToken" Style="StringDefaultStyle">

<ExplicitPatternGroup Type="StartScope" TokenKey="StringStartToken" Style="StringDelimiterStyle" PatternValue="&quot;" />
<RegexPatternGroup Type="EndScope" TokenKey="StringEndToken" Style="StringDelimiterStyle" PatternValue="\&quot;" />

<RegexPatternGroup TokenKey="StringEscapedCharacterToken" PatternValue="\\x {HexDigitMacro}{1,4}" />
<RegexPatternGroup TokenKey="StringEscapedCharacterToken" PatternValue="\\u {HexDigitMacro}{4,4}" />
<RegexPatternGroup TokenKey="StringEscapedCharacterToken" PatternValue="\\U {HexDigitMacro}{8,8}" />

<RegexPatternGroup TokenKey="StringWhitespaceToken" PatternValue="{WhitespaceMacro}+" IsWhitespace="True" />
<RegexPatternGroup TokenKey="StringWordToken" PatternValue="\w+" />
<RegexPatternGroup TokenKey="StringDefaultToken" PatternValue="[^\&quot;]" />
<State Key="DefaultState">
<ChildState Key="StringState" />

In my parser I would like to recognize a string in the DefaultState and parse the string sequence into a ASTNode. I assume the way I would do this is by doing the following:

//Slurp in the string content
AstNode node = new StringNode();

Am I on the right track?

[Modified at 01/02/2007 01:09 PM]

Comments (1)

Posted 14 years ago by Actipro Software Support - Cleveland, OH, USA
Yes that is probably the right track although instead of calling Match methods directly you may wish to use our parser generator's token matching syntax (like 'StringStartToken').

Also, it may be easier (and faster) if you just make strings into one token that is expressed by a single regular expression. That way you can just parse the single token as a string literal.

Actipro Software Support

The latest build of this product (v2020.1 build 0402) was released 2 months ago, which was after the last post in this thread.

Add Comment

Please log in to a validated account to post comments.