Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8589015
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T22:56:33+00:00 2026-06-11T22:56:33+00:00

I want to create a Jison (Bison) grammar for a markup language that allows

  • 0

I want to create a Jison (Bison) grammar for a markup language that allows escaping of markup delimiters.

These would be valid:

I like apples
I like [apples, oranges, pears]
I like [apples, oranges, pears] and [peanut butter, jelly]
I like [apples, oranges, pears] \[when they're in season\]
I like emoticons :-\]

The examples would be interpreted perhaps as the following (in JSON representation):

["I like apples"]
["I like ", ["apples", "oranges", "pears"]]
["I like ", ["apples", "oranges", "pears"], " and ", ["peanut butter", "jelly"]]
["I like ", ["apples", "oranges", "pears"], " [when they're in season]"]
["I like emoticons :-]"]

Escaping of []\, is the minimum, but it probably makes sense to allow any printable character be escaped, even if the escaping is unnecessary.

It’d be nice if escaping non-printable characters would be unsupported. That is, a \ at the end of a line would be illegal. That might come free with the regex . as it might not include newlines, but it should also happen for other unprintable characters too.

It is difficult to google for this because it’s mixed up with a lot of results for escaping literal characters in the Bison definition, etc.

What is the most elegant way to support escape characters in a Bison-defined language?

EDIT

Here’s what I have so far and can be tested on Jison, but it isn’t working (just returns 1 if anything) and I don’t expect that the text will arrive unescaped – that would require a second pass. Is that avoidable?

/* description: markup */

/* lexical grammar */
%lex
%%

(\\.|[^\\\[])+            return 'TOPTEXT'
(\\.|[^\\\[\]\,])+        return 'TEXT'
\-?[0-9]+("."[0-9]+)?\b   return 'NUMBER'
".."|"-"                  return '..'
"["                       return '['
"]"                       return ']'
","                       return ','
<<EOF>>                   return 'EOF'

/lex

%start markup

%%

markup
    : template EOF
        { return $template; }
    ;

template
    : template TOPTEXT
        { $$ = $template.push($TOPTEXT); }
    | template dynamic
        { $$ = $template.push($dynamic); }
    | /* empty */
        { $$ = []; }
    ;

dynamic
    : '[' phraselist ']'
        { $$ = $phraselist; }
    ;

phraselist
    : phraselist ',' phrase
        { $$ = $phraselist.push($phrase); }
    | /* empty */
        { $$ = []; }
    ;

phrase
    : TEXT
        { $$ = $phrase.push($TEXT); }
    | phrase dynamic
        { $$ = $phrase.push($dynamic); }
    | /* empty */
        { $$ = []; }
    ;
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T22:56:34+00:00Added an answer on June 11, 2026 at 10:56 pm

    I think there are more than one problem with your code.

    The first (and this explains the 1 output) is that [].push returns the new length of the list, so what you want is probably push, and then define the value:

    template
    : template TOPTEXT
        { $template.push($TOPTEXT); $$ = $template; }
    | template dynamic
        { $template.push($dynamic); $$ = $template; }
    | /* empty */
        { $$ = []; }
    ;
    

    The other thing is, it seems that you are trying to get too much things to work at the same time, without being really sure that you want them or that they are actually working the way they are supposed to.

    Maybe a better strategy would be for you to start small, making it work one rule at the time, starting from the basics.

    For example, you could first make sure that you have the lexer working for every case, testing with a simple grammar that just prints out the tokens:

    %lex
    %%
    
    (\\\\|\\\[|\\\]|\\\,|[^,\\\[\]])+   return 'TEXT'
    \-?[0-9]+("."[0-9]+)?\b             return 'NUMBER'
    ".."|"-"                            return 'RANGE'
    "["                                 return '['
    "]"                                 return ']'
    ","                                 return ','
    
    /lex
    
    %start lexertest
    
    %%
    
    lexertest:
    token lexertest
    | /* empty */
    ;
    
    token:
    TEXT    { console.log("Token TEXT: |" + $TEXT +  "|"); }
    |
    NUMBER  { console.log("Token NUMBER: |" + $NUMBER +  "|"); }
    |
    '['     { console.log("Token ["); }
    |
    ']'     { console.log("Token ]"); }
    |
    ','     { console.log("Token ,"); }
    |
    'RANGE' { console.log("Token RANGE: |" + $1 +  "|"); }
    ;
    

    Note: When running in the browser, the console.log output will be only in the developer tools. You may find using Jison in the command line with a script like this (for Bash) can be easier to test with several inputs.

    Then you refine it, until you are content with it.
    After you are content with the lexer, then you start making the grammar to work, again testing one rule at the time. Keep the rules above for whenever you want to debug the output of the lexer, you can just change the %start rule.

    In the end, you may well discover that you never needed EOF in the first place, and that maybe you won’t need two different rules for matching the free text, after all.

    Hope it helps.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to create simple application that detects language(using Google API) of phrase and
i want create a custom json data from the mssql 2008 results so that
This the model that I want to create using json file Ext.define('Users', { extend:
I want create wordpress website into which I want create user management... That means
I want to create a data structure that will be parse as a JSON
I want to create a content provider that will bring results from a web
I have a json record like blow [{low:null,high:10,type:2,value:0},{low:10,high:60,type:1,value:10},{low:60,high:null,type:2,value:11}] I would like to create array
I have dynamic json result and i want to create an object for that
I want to create JSON string like {search_element: New York} this. I used following
I want to create JSON , format is like "header": { "b":"aaaa", "c":"00", "d":"zzzzz",

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.